Completed
Push — master ( c8682f...5bbe2a )
by Raphael
01:33
created

deepy.utils.create_var()   A

Complexity

Conditions 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 11
rs 9.4286
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
import numpy as np
5
from functions import FLOATX
6
7
def create_var(theano_tensor, dim=0, test_shape=None, test_dtype=FLOATX):
8
    """
9
    Wrap a Theano tensor into the variable for defining neural network.
10
    :param dim: last dimension of tensor, 0 indicates that the last dimension is flexible
11
    :rtype: TensorVar
12
    """
13
    from deepy.layers.variable import NeuralVar
14
    var = NeuralVar(dim, theano_tensor)
15
    if test_shape:
16
        var.set_test_value(np.random.rand(*test_shape).astype(test_dtype))
17
    return var