Completed
Push — master ( 48255b...bf2b0c )
by Raphael
01:13
created

NeuralTensor.constant()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
import theano.tensor as T
5
from theano import tensor as theano_tensor
6
from decorations import neural_computation
7
from deepy.layers.neural_var import NeuralVariable
8
9
class NeuralTensorNet(object):
10
11
    def __getattr__(self, func_name):
12
        @neural_computation
13
        def wrapper(*args, **kwargs):
14
            return getattr(theano_tensor.nnet, func_name)(*args, **kwargs)
15
        return wrapper
16
17
deepy_nnet = NeuralTensorNet()
18
19
class NeuralTensor(object):
20
    """
21
    A class for exporting Theano tensor operations to neural variables.
22
23
    """
24
25
    def constant(self, value, dtype="float32", dim=None):
26
        return NeuralVariable(T.constant(value, dtype=dtype), dim=dim)
27
28
    def __getattr__(self, func_name):
29
        global deepy_nnet
30
        @neural_computation
31
        def wrapper(*args, **kwargs):
32
            return getattr(theano_tensor, func_name)(*args, **kwargs)
33
        if func_name == 'nnet':
34
            return deepy_nnet
35
        else:
36
            return wrapper
37
38
39
deepy_tensor = NeuralTensor()
40
tensor = NT = deepy_tensor
41
42