forked from nouiz/ccw_tutorial_theano
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
103 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from theano import Op, Apply | ||
from theano.tensor import as_tensor_variable | ||
|
||
class DoubleOp(Op): | ||
__props__ = () | ||
|
||
def make_node(self, x): | ||
x = as_tensor_variable(x) | ||
return Apply(self, [x], [x.type()]) | ||
|
||
def perform(self, node, inputs, output_storage): | ||
x = inputs[0] | ||
z = output_storage[0] | ||
z[0] = x * 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from theano import Op, Apply | ||
from theano.tensor import as_tensor_variable | ||
from theano.scalar import as_scalar_variable | ||
|
||
class ScalMulV1(Op): | ||
__props__ = ('scal') | ||
|
||
def __init__(self, scal): | ||
if not isinstance(scal, int): | ||
raise TypeError('expected an int') | ||
self.scal = scal | ||
|
||
def make_node(self, x): | ||
x = as_tensor_variable(x) | ||
return Apply(self, [x], [x.type()]) | ||
|
||
def perform(self, node, inputs, output_storage): | ||
x = inputs[0] | ||
z = output_storage[0] | ||
z[0] = x * self.scal | ||
|
||
|
||
class ScalMulV2(Op): | ||
__props__ = () | ||
|
||
def make_node(self, x, scal): | ||
x = as_tensor_variable(x) | ||
scal = as_scalar_variable(scal) | ||
return Apply(self, [x, scal], [x.type()]) | ||
|
||
def perform(self, node, inputs, output_storage): | ||
x = inputs[0] | ||
scal = inputs[1] | ||
z = output_storage[0] | ||
z[0] = x * scal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters