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

NeuralTensorNet.__getattr__()   A

Complexity

Conditions 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
dl 0
loc 5
rs 9.4285
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A NeuralTensorNet.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