Completed
Push — master ( 5937d6...900a69 )
by Raphael
01:44
created

NeuralTensorNet   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __getattr__() 0 5 2
A wrapper() 0 3 1
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
from theano import tensor as theano_tensor
5
from decorations import neural_computation
6
7
class NeuralTensorNet(object):
8
9
    def __getattr__(self, func_name):
10
        @neural_computation
11
        def wrapper(*args, **kwargs):
12
            return getattr(theano_tensor.nnet, func_name)(*args, **kwargs)
13
        return wrapper
14
15
neural_tensor_net = NeuralTensorNet()
16
17
class NeuralTensor(object):
18
    """
19
    A class for exporting Theano tensor operations to neural variables.
20
    """
21
22
    def __getattr__(self, func_name):
23
        global neural_tensor_net
24
        @neural_computation
25
        def wrapper(*args, **kwargs):
26
            return getattr(theano_tensor, func_name)(*args, **kwargs)
27
        if func_name == 'nnet':
28
            return neural_tensor_net
29
        else:
30
            return wrapper
31
32
33
neural_tensor = NeuralTensor()
34
NT = neural_tensor
35
tensor = neural_tensor