提交 67091013 authored 作者: Olivier Breuleux's avatar Olivier Breuleux

moved Tensor -> NDArrayType, TensorResult -> NDArrayResult, as_tensor ->…

moved Tensor -> NDArrayType, TensorResult -> NDArrayResult, as_tensor -> as_tensor_result, Sparse -> SparseType, as_sparse -> as_sparse_result, closes #243
上级 55c5d0b3
......@@ -22,7 +22,7 @@ class BROKEN_ON_PURPOSE_StructuredDotCSC(gof.Op):
def __hash__(self):
return 29834 ^ hash(type(self)) ^ hash(self.py_offset)
def make_node(self, a_val, a_ind, a_ptr, a_nrows, b):
a_nrows = theano.tensor.as_tensor(a_nrows)
a_nrows = theano.tensor.as_ndarray_result(a_nrows)
assert a_val.type.dtype == b.type.dtype
r = gof.Apply(self, [a_val, a_ind, a_ptr, a_nrows, b],
[theano.tensor.tensor(a_val.type.dtype, (False, False))])
......
......@@ -18,7 +18,7 @@ class StochasticGradientDescent(module.FancyModule):
def __init__(self, args, cost, params, gradients=None, stepsize=None, WEIRD_STUFF=True):
"""
:param stepsize: the step to take in (negative) gradient direction
:type stepsize: None, scalar value, or scalar TensorResult
:type stepsize: None, scalar value, or scalar NDArrayResult
"""
super(StochasticGradientDescent, self).__init__()
self.WEIRD_STUFF = WEIRD_STUFF
......@@ -26,7 +26,7 @@ class StochasticGradientDescent(module.FancyModule):
if stepsize is None:
self.stepsize = (T.dscalar())
elif isinstance(stepsize, T.TensorResult):
elif isinstance(stepsize, T.NDArrayResult):
self.stepsize = stepsize
else:
if self.WEIRD_STUFF:
......@@ -89,9 +89,9 @@ class TanhRnn(Op):
:type A: matrix (M by M)
"""
x = T.as_tensor(x)
z0 = T.as_tensor(z0)
A = T.as_tensor(A)
x = T.as_ndarray_result(x)
z0 = T.as_ndarray_result(z0)
A = T.as_ndarray_result(A)
z = x.type() #make a new symbolic result with the same type as x
return Apply(self, [x, z0, A], [z])
......
......@@ -289,9 +289,9 @@ class Type(object2, PureType, CLinkerType):
- `Generic`: for any python type
- `Tensor`: for numpy.ndarray
- `NDArrayType`: for numpy.ndarray
- `Sparse`: for scipy.sparse
- `SparseType`: for scipy.sparse
But you are encouraged to write your own, as described in WRITEME.
......
差异被折叠。
......@@ -66,8 +66,8 @@ def true_dot(x, y, grad_preserves_dense=True):
@todo: Maybe the triple-transposition formulation (when x is dense)
is slow. See if there is a direct way to do this.
"""
if hasattr(x, 'getnnz'): x = as_sparse(x)
if hasattr(y, 'getnnz'): y = as_sparse(y)
if hasattr(x, 'getnnz'): x = as_sparse_result(x)
if hasattr(y, 'getnnz'): y = as_sparse_result(y)
x_is_sparse_result = _is_sparse_result(x)
y_is_sparse_result = _is_sparse_result(y)
......@@ -86,7 +86,7 @@ class test_true_dot(unittest.TestCase):
def test_basicSS(self):
for mtype in _mtypes:
x = as_sparse(mtype((500,3)))
x = as_sparse_result(mtype((500,3)))
x.data[(10, 1)] = 1
x.data[(20, 2)] = 2
self.failUnless(_is_sparse_result(x))
......@@ -117,12 +117,12 @@ class test_true_dot(unittest.TestCase):
def test_basicSD(self):
for mtype in _mtypes:
x = as_sparse(mtype((500,3)))
x = as_sparse_result(mtype((500,3)))
x.data[(10, 1)] = 1
x.data[(20, 2)] = 2
self.failUnless(_is_sparse_result(x))
y = tensor.as_tensor([[1., 2], [3, 4], [2, 1]])
y = tensor.as_ndarray_result([[1., 2], [3, 4], [2, 1]])
self.failUnless(_is_dense_result(y))
zop = true_dot(x,y)
......@@ -150,12 +150,12 @@ class test_true_dot(unittest.TestCase):
def test_basicDS(self):
for mtype in _mtypes:
x = as_sparse(mtype((500,3)))
x = as_sparse_result(mtype((500,3)))
x.data[(10, 1)] = 1
x.data[(20, 2)] = 2
self.failUnless(_is_sparse_result(x))
y = tensor.as_tensor([[1., 2], [3, 4], [2, 1]])
y = tensor.as_ndarray_result([[1., 2], [3, 4], [2, 1]])
self.failUnless(_is_dense_result(y))
x.data = x.data.T
......@@ -189,7 +189,7 @@ class test_true_dot(unittest.TestCase):
def test_graph_bprop0(self):
for mtype in _mtypes:
x = tensor.matrix('x') #Tensor('float64', broadcastable=[False,False], name='x')
x = tensor.matrix('x') #NDArrayType('float64', broadcastable=[False,False], name='x')
w = Sparse(dtype = 'float64', format = _mtype_to_str[mtype]).make_result()
xw = dense_from_sparse(true_dot(w, x))
y = dense_from_sparse(true_dot(w.T, xw))
......
......@@ -22,7 +22,7 @@ class T_transpose(unittest.TestCase):
def test_transpose_csc(self):
sp = sparse.csc_matrix(sparse.eye(5,3))
a = as_sparse(sp)
a = as_sparse_result(sp)
self.failUnless(a.data is sp)
self.failUnless(a.data.shape == (5,3))
self.failUnless(a.type.dtype == 'float64', a.type.dtype)
......@@ -34,7 +34,7 @@ class T_transpose(unittest.TestCase):
vta = eval_outputs([ta])
self.failUnless(vta.shape == (3,5))
def test_transpose_csr(self):
a = as_sparse(sparse.csr_matrix(sparse.eye(5,3)))
a = as_sparse_result(sparse.csr_matrix(sparse.eye(5,3)))
self.failUnless(a.data.shape == (5,3))
self.failUnless(a.type.dtype == 'float64')
self.failUnless(a.type.format == 'csr')
......@@ -49,13 +49,13 @@ class T_Add(unittest.TestCase):
def testSS(self):
for mtype in _mtypes:
a = mtype(numpy.array([[1., 0], [3, 0], [0, 6]]))
aR = as_sparse(a)
aR = as_sparse_result(a)
self.failUnless(aR.data is a)
self.failUnless(_is_sparse(a))
self.failUnless(_is_sparse_result(aR))
b = mtype(numpy.asarray([[0, 2.], [0, 4], [5, 0]]))
bR = as_sparse(b)
bR = as_sparse_result(b)
self.failUnless(bR.data is b)
self.failUnless(_is_sparse(b))
self.failUnless(_is_sparse_result(bR))
......@@ -76,13 +76,13 @@ class T_Add(unittest.TestCase):
def testSD(self):
for mtype in _mtypes:
a = numpy.array([[1., 0], [3, 0], [0, 6]])
aR = tensor.as_tensor(a)
aR = tensor.as_ndarray_result(a)
self.failUnless(aR.data is a)
self.failUnless(_is_dense(a))
self.failUnless(_is_dense_result(aR))
b = mtype(numpy.asarray([[0, 2.], [0, 4], [5, 0]]))
bR = as_sparse(b)
bR = as_sparse_result(b)
self.failUnless(bR.data is b)
self.failUnless(_is_sparse(b))
self.failUnless(_is_sparse_result(bR))
......@@ -101,13 +101,13 @@ class T_Add(unittest.TestCase):
def testDS(self):
for mtype in _mtypes:
a = mtype(numpy.array([[1., 0], [3, 0], [0, 6]]))
aR = as_sparse(a)
aR = as_sparse_result(a)
self.failUnless(aR.data is a)
self.failUnless(_is_sparse(a))
self.failUnless(_is_sparse_result(aR))
b = numpy.asarray([[0, 2.], [0, 4], [5, 0]])
bR = tensor.as_tensor(b)
bR = tensor.as_ndarray_result(b)
self.failUnless(bR.data is b)
self.failUnless(_is_dense(b))
self.failUnless(_is_dense_result(bR))
......@@ -128,14 +128,14 @@ class T_conversion(unittest.TestCase):
unittest_tools.seed_rng()
def test0(self):
a = tensor.as_tensor(numpy.random.rand(5))
a = tensor.as_ndarray_result(numpy.random.rand(5))
s = csc_from_dense(a)
val = eval_outputs([s])
self.failUnless(str(val.dtype)=='float64')
self.failUnless(val.format == 'csc')
def test1(self):
a = tensor.as_tensor(numpy.random.rand(5))
a = tensor.as_ndarray_result(numpy.random.rand(5))
s = csr_from_dense(a)
val = eval_outputs([s])
self.failUnless(str(val.dtype)=='float64')
......
差异被折叠。
......@@ -275,7 +275,7 @@ class Gemm(GemmRelated):
E_z_uniq = 'argument z aliased to x or y'
destroy_map = {0: [0]}
def make_node(self, *inputs):
inputs = map(T.as_tensor, inputs)
inputs = map(T.as_ndarray_result, inputs)
if len(inputs) != 5:
raise TypeError("Wrong number of inputs for %s (expected 5, got %s)" % (self, len(inputs)))
z, a, x, y, b = inputs
......@@ -475,7 +475,7 @@ class GemmLocalOptimizer(LocalOptimizer):
@staticmethod
def _as_scalar(res):
"""Return None or a TensorResult whose type is in T.float_scalar_types"""
"""Return None or a NDArrayResult whose type is in T.float_scalar_types"""
if res.owner and isinstance(res.owner.op, T.DimShuffle):
return GemmLocalOptimizer._as_scalar(res.owner.inputs[0])
elif res.type in T.float_scalar_types:
......
......@@ -13,18 +13,18 @@ from copy import copy, deepcopy
# tensor depends on elemwise to provide definitions for several ops
# but elemwise needs to make Tensor instances, so we have these as
# but elemwise needs to make NDArrayType instances, so we have these as
# placeholders and the tensor module fills them
def as_tensor(data):
def as_ndarray_result(data):
raise Exception("Circular dependencies prevent using this here. import tensor before elemwise")
def Tensor(*inputs, **kwargs):
def NDArrayType(*inputs, **kwargs):
raise Exception("Circular dependencies prevent using this here. import tensor before elemwise")
def TensorResult(*inputs, **kwargs):
def NDArrayResult(*inputs, **kwargs):
raise Exception("Circular dependencies prevent using this here. import tensor before elemwise")
def TensorConstant(*inputs, **kwargs):
def NDArrayConstant(*inputs, **kwargs):
raise Exception("Circular dependencies prevent using this here. import tensor before elemwise")
......@@ -137,7 +137,7 @@ class DimShuffle(Op):
else:
ob.append(ib[value])
output = Tensor(dtype = input.type.dtype,
output = NDArrayType(dtype = input.type.dtype,
broadcastable = ob).make_result()
return Apply(self, [input], [output])
......@@ -256,7 +256,7 @@ class DimShuffle(Op):
return full_code % dict(locals(), **sub)
def grad(self, (x, ), (gz, )):
gz = as_tensor(gz)
gz = as_ndarray_result(gz)
grad_order = ['x'] * len(x.type.broadcastable)
for i, v in enumerate(self.new_order):
if v != 'x':
......@@ -365,7 +365,7 @@ class Elemwise(Op):
using DimShuffle.
"""
inputs = map(as_tensor, inputs)
inputs = map(as_ndarray_result, inputs)
shadow = self.scalar_op.make_node(*[Scalar(dtype = t.type.dtype)() for t in inputs])
target_length = max([input.type.ndim for input in inputs])
......@@ -403,7 +403,7 @@ class Elemwise(Op):
if any(inputs[i].type.dtype != out_dtypes[o] for o, i in inplace_pattern.items()):
raise TypeError("Cannot do an inplace operation on incompatible data types.",
([i.type.dtype for i in inputs], out_dtypes, inplace_pattern))
outputs = [Tensor(dtype = dtype, broadcastable = broadcastable)() for dtype, broadcastable in zip(out_dtypes, out_broadcastables)]
outputs = [NDArrayType(dtype = dtype, broadcastable = broadcastable)() for dtype, broadcastable in zip(out_dtypes, out_broadcastables)]
return Apply(self, inputs, outputs)
def __eq__(self, other):
......@@ -431,7 +431,7 @@ class Elemwise(Op):
return self.name
def grad(self, inputs, ograds):
ograds = map(as_tensor, ograds) # this shouldn't be necessary...
ograds = map(as_ndarray_result, ograds) # this shouldn't be necessary...
scalar_inputs = [Scalar(dtype = t.type.dtype)() for t in inputs]
scalar_ograds = [Scalar(dtype = ograd.type.dtype)() for ograd in ograds]
scalar_igrads = self.scalar_op.grad(scalar_inputs, scalar_ograds)
......@@ -445,8 +445,8 @@ class Elemwise(Op):
node = r.owner
if node is None:
# the gradient contains a constant, translate it as
# an equivalent Tensor of size 1 and proper number of dimensions
res = TensorConstant(Tensor(dtype = r.type.dtype,
# an equivalent NDArrayType of size 1 and proper number of dimensions
res = NDArrayConstant(NDArrayType(dtype = r.type.dtype,
broadcastable = ()),
numpy.asarray(r.data)) # .reshape(b)
return DimShuffle((), ['x']*nd, inplace = True)(res)
......@@ -678,11 +678,11 @@ class CAReduce(Op):
self.ufunc = numpy.frompyfunc(scalar_op.impl, 2, 1)
def make_node(self, input):
input = as_tensor(input)
input = as_ndarray_result(input)
axis = self.axis
if axis is None:
axis = range(len(input.type.broadcastable))
output = Tensor(dtype = input.type.dtype,
output = NDArrayType(dtype = input.type.dtype,
broadcastable = [x for i, x in enumerate(input.type.broadcastable) if i not in axis])()
return Apply(self, [input], [output])
......@@ -809,7 +809,7 @@ class Sum(CAReduce):
CAReduce.__init__(self, scalar.add, axis)
def grad(self, (x, ), (gz, )):
gz = as_tensor(gz)
gz = as_ndarray_result(gz)
axis = self.axis
if axis is None:
axis = range(x.type.ndim)
......
......@@ -94,8 +94,8 @@ class SoftmaxWithBias(gof.Op):
gof.Op.__init__(self, **kwargs)
def make_node(self, x, b):
x = tensor.as_tensor(x)
b = tensor.as_tensor(b)
x = tensor.as_ndarray_result(x)
b = tensor.as_ndarray_result(b)
if x.type.ndim != 2 \
or x.type.dtype not in ['float32', 'float64']:
raise ValueError('x must be 2-d tensor of floats')
......@@ -263,8 +263,8 @@ class SoftmaxWithBiasDx(gof.Op):
gof.Op.__init__(self, **kwargs)
def make_node(self, dy, sm, **kwargs):
dy = tensor.as_tensor(dy)
sm = tensor.as_tensor(sm)
dy = tensor.as_ndarray_result(dy)
sm = tensor.as_ndarray_result(sm)
return gof.Apply(self, [dy, sm], [sm.type.make_result()])
def perform(self, node, input_storage, output_storage):
......@@ -368,9 +368,9 @@ class CrossentropySoftmaxArgmax1HotWithBias(gof.Op):
gof.Op.__init__(self, **kwargs)
def make_node(self, x, b, y_idx):
x = tensor.as_tensor(x)
b = tensor.as_tensor(b)
y_idx = tensor.as_tensor(y_idx)
x = tensor.as_ndarray_result(x)
b = tensor.as_ndarray_result(b)
y_idx = tensor.as_ndarray_result(y_idx)
if x.type.ndim != 2 \
or x.type.dtype not in ['float32', 'float64']:
raise ValueError('x must be 2-d tensor of floats')
......@@ -382,9 +382,9 @@ class CrossentropySoftmaxArgmax1HotWithBias(gof.Op):
raise ValueError('y_idx must be 1-d tensor of ints')
# TODO: Is this correct? It used to be y, not y_idx
nll = tensor.Tensor(x.type.dtype,
nll = tensor.NDArrayType(x.type.dtype,
y_idx.type.broadcastable).make_result()
# nll = Tensor(x.dtype, y.broadcastable)
# nll = NDArrayType(x.dtype, y.broadcastable)
sm = x.type.make_result()
am = y_idx.type.make_result()
return gof.Apply(self, [x, b, y_idx], [nll, sm, am])
......@@ -532,9 +532,9 @@ class CrossentropySoftmax1HotWithBiasDx (gof.Op):
def __init__(self, **kwargs):
gof.Op.__init__(self,**kwargs)
def make_node(self, dy, sm, y_idx,**kwargs):
dy = tensor.as_tensor(dy)
sm = tensor.as_tensor(sm)
y_idx = tensor.as_tensor(y_idx)
dy = tensor.as_ndarray_result(dy)
sm = tensor.as_ndarray_result(sm)
y_idx = tensor.as_ndarray_result(y_idx)
return gof.Apply(self, [dy, sm, y_idx],[sm.type.make_result()])
def perform(self, node, input_storage, output_storage):
dy,sm,y_idx = input_storage
......@@ -672,8 +672,8 @@ class Prepend_scalar_constant_to_each_row(gof.Op):
#check type of input
if not isinstance(mat,gof.Result) or not mat.type==tensor.matrix().type:
raise TypeError("Expected a matrix as input")
x = tensor.as_tensor(mat)
y = tensor.as_tensor(self.val)
x = tensor.as_ndarray_result(mat)
y = tensor.as_ndarray_result(self.val)
if x.type.dtype != y.type.dtype:
TypeError("the value to prepend don't have the same type as the matrix")
......@@ -706,8 +706,8 @@ class Prepend_scalar_to_each_row(gof.Op):
val = scalar.constant(val)
if not isinstance(mat,gof.Result) or not mat.type==tensor.matrix().type:
raise TypeError("Expected a matrix as input")
x = tensor.as_tensor(mat)
y = tensor.as_tensor(val)
x = tensor.as_ndarray_result(mat)
y = tensor.as_ndarray_result(val)
if x.type.dtype != y.type.dtype:
TypeError("the value to prepend don't have the same type as the matrix")
......
......@@ -534,7 +534,7 @@ class Canonizer(gof.LocalOptimizer):
ln, ld = len(num), len(denum)
if not ln and not ld:
return T.as_tensor(self.calculate([], []))
return T.as_ndarray_result(self.calculate([], []))
if not ln:
if self.use_reciprocal:
return self.reciprocal(self.merge_num_denum(denum, []))
......@@ -545,7 +545,7 @@ class Canonizer(gof.LocalOptimizer):
if isinstance(num[0], gof.Result):
return num[0]
else:
return T.as_tensor(num[0])
return T.as_ndarray_result(num[0])
else:
return self.main(*num)
return self.inverse(self.merge_num_denum(num, []),
......@@ -844,7 +844,7 @@ def local_mul_specialize(node):
if len(new_inputs) < len(node.inputs):
if len(new_inputs) == 0:
newval = -y.flatten()[0] if neg else y.flatten()[0]
return [T.TensorConstant(T.Tensor(dtype=node.outputs[0].type.dtype,
return [T.NDArrayConstant(T.NDArrayType(dtype=node.outputs[0].type.dtype,
broadcastable = [True] * node.outputs[0].ndim), N.asarray(newval))]
if len(new_inputs) == 1:
......
......@@ -131,7 +131,7 @@ class RandomStreams(Component):
:returns: The symbolic random draw part of op()'s return value. This function stores
the updated RandomStateType Result for use at `build` time.
:rtype: TensorResult
:rtype: NDArrayResult
"""
random_state_result = raw_random.random_state_type()
new_r, out = op(random_state_result, *args, **kwargs)
......
......@@ -87,7 +87,7 @@ class RandomFunction(gof.Op):
fn, outtype, args, kwargs = state
self.fn = getattr(numpy.random.RandomState, fn) if isinstance(fn, str) else fn
self.outtype = outtype
self.args = tuple(tensor.as_tensor(arg) for arg in args)
self.args = tuple(tensor.as_ndarray_result(arg) for arg in args)
self.inplace = kwargs.pop('inplace', False)
if self.inplace:
self.destroy_map = {0: [0]}
......@@ -103,7 +103,7 @@ class RandomFunction(gof.Op):
:param args: the values associated with these results will be passed to the RandomState
function during perform as extra "*args"-style arguments. These should be castable to
results of Type Tensor.
results of Type NDArrayType.
:rtype: Apply
......@@ -115,7 +115,7 @@ class RandomFunction(gof.Op):
if shape == () or shape == []:
shape = tensor.lvector()
else:
shape = tensor.as_tensor(shape, ndim=1)
shape = tensor.as_ndarray_result(shape, ndim=1)
#print 'SHAPE TYPE', shape.type, tensor.lvector
assert shape.type.ndim == 1
assert (shape.type.dtype == 'int64') or (shape.type.dtype == 'int32')
......@@ -127,9 +127,9 @@ class RandomFunction(gof.Op):
# shape.type
# assert shape.type == tensor.lvector
# convert args to Tensor instances
# convert args to NDArrayType instances
# and append enough None's to match the length of self.args
args = map(tensor.as_tensor, args)
args = map(tensor.as_ndarray_result, args)
if len(args) > len(self.args):
raise TypeError('Too many args for this kind of random generator')
args += (None,) * (len(self.args) - len(args))
......@@ -202,14 +202,14 @@ def random_function(fn, dtype, *rfargs, **rfkwargs):
else:
r, shape, args = ndim, args[0], args[1:]
if shape == () or shape == []:
shape = tensor.TensorConstant(type = tensor.lvector, data = shape)
shape = tensor.NDArrayConstant(type = tensor.lvector, data = shape)
else:
shape = tensor.as_tensor(shape)
shape = tensor.as_ndarray_result(shape)
ndim = tensor.get_vector_length(shape)
if ndim is None:
raise ValueError('Cannot infer the number of dimensions from the shape argument.')
# note: rf could be cached for future use
rf = RandomFunction(fn, tensor.Tensor(dtype = dtype, broadcastable = (False,)*ndim), *rfargs, **rfkwargs)
rf = RandomFunction(fn, tensor.NDArrayType(dtype = dtype, broadcastable = (False,)*ndim), *rfargs, **rfkwargs)
return rf(r, shape, *args, **kwargs)
return f
......
......@@ -12,7 +12,7 @@ _as_scalar = GemmLocalOptimizer._as_scalar
_is_real_matrix = GemmLocalOptimizer._is_real_matrix
from theano import In, Out
from .test_basic import (_approx_eq, as_tensor, inplace_func,
from .test_basic import (_approx_eq, as_ndarray_result, inplace_func,
compile, value, constant, inplace, eval_outputs)
class t_gemm(TestCase):
......@@ -35,7 +35,7 @@ class t_gemm(TestCase):
def cmp_linker(z, a, x, y, b, l):
z,a,x,y,b = [numpy.asarray(p) for p in z,a,x,y,b]
z_orig = z.copy()
tz,ta,tx,ty,tb = [as_tensor(p).type() for p in z,a,x,y,b]
tz,ta,tx,ty,tb = [as_ndarray_result(p).type() for p in z,a,x,y,b]
f = inplace_func([tz,ta,tx,ty,tb], gemm(tz,ta,tx,ty,tb), mode=compile.Mode(optimizer = None, linker = l))
new_z = f(z,a,x,y,b)
......@@ -100,7 +100,7 @@ class t_gemm(TestCase):
def test_destroy_map0(self):
"""test that only first input can be overwritten"""
Z = as_tensor(self.rand(2,2))
Z = as_ndarray_result(self.rand(2,2))
try:
gemm(Z, 1.0, Z, Z, 1.0)
except ValueError, e:
......@@ -109,8 +109,8 @@ class t_gemm(TestCase):
self.fail()
def test_destroy_map1(self):
"""test that only first input can be overwritten"""
Z = as_tensor(self.rand(2,2))
A = as_tensor(self.rand(2,2))
Z = as_ndarray_result(self.rand(2,2))
A = as_ndarray_result(self.rand(2,2))
try:
gemm(Z, 1.0, A, inplace.transpose_inplace(Z), 1.0)
except ValueError, e:
......@@ -119,8 +119,8 @@ class t_gemm(TestCase):
self.fail()
def test_destroy_map2(self):
"""test that only first input can be overwritten"""
Z = as_tensor(self.rand(2,2))
A = as_tensor(self.rand(2,2))
Z = as_ndarray_result(self.rand(2,2))
A = as_ndarray_result(self.rand(2,2))
try:
gemm(Z, 1.0, inplace.transpose_inplace(Z), A, 1.0)
except ValueError, e:
......@@ -129,8 +129,8 @@ class t_gemm(TestCase):
self.fail()
def test_destroy_map3(self):
"""test that only first input can be overwritten"""
Z = as_tensor(self.rand(2,2))
A = as_tensor(self.rand(2,2))
Z = as_ndarray_result(self.rand(2,2))
A = as_ndarray_result(self.rand(2,2))
try:
gemm(Z, 1.0, Z, A, 1.0)
except ValueError, e:
......
......@@ -27,7 +27,7 @@ class test_DimShuffle(unittest.TestCase):
((1, 4, 3, 2, 1), (3, 2, 1), (2, 3, 4)),
((1, 1, 4), (1, 2), (1, 4))]:
ib = [(entry == 1) for entry in xsh]
x = Tensor('float64', ib)('x')
x = NDArrayType('float64', ib)('x')
e = DimShuffle(ib, shuffle)(x)
f = copy(linker).accept(Env([x], [e])).make_function()
assert f(numpy.ones(xsh)).shape == zsh
......@@ -50,8 +50,8 @@ class test_Broadcast(unittest.TestCase):
((2, 3, 4, 5), (1, 3, 1, 5)),
((2, 3, 4, 5), (1, 1, 1, 1)),
((), ())]:
x = Tensor('float64', [(entry == 1) for entry in xsh])('x')
y = Tensor('float64', [(entry == 1) for entry in ysh])('y')
x = NDArrayType('float64', [(entry == 1) for entry in xsh])('x')
y = NDArrayType('float64', [(entry == 1) for entry in ysh])('y')
e = Elemwise(add)(x, y)
f = copy(linker).accept(Env([x, y], [e])).make_function()
xv = numpy.asarray(numpy.random.rand(*xsh))
......@@ -69,8 +69,8 @@ class test_Broadcast(unittest.TestCase):
((2, 3, 4, 5), (1, 3, 1, 5)),
((2, 3, 4, 5), (1, 1, 1, 1)),
((), ())]:
x = Tensor('float64', [(entry == 1) for entry in xsh])('x')
y = Tensor('float64', [(entry == 1) for entry in ysh])('y')
x = NDArrayType('float64', [(entry == 1) for entry in xsh])('x')
y = NDArrayType('float64', [(entry == 1) for entry in ysh])('y')
e = Elemwise(Add(transfer_type(0)), {0:0})(x, y)
f = copy(linker).accept(Env([x, y], [e])).make_function()
xv = numpy.asarray(numpy.random.rand(*xsh))
......@@ -94,8 +94,8 @@ class test_Broadcast(unittest.TestCase):
self.with_linker_inplace(gof.CLinker())
def test_fill(self):
x = Tensor('float64', [0, 0])('x')
y = Tensor('float64', [1, 1])('y')
x = NDArrayType('float64', [0, 0])('x')
y = NDArrayType('float64', [1, 1])('y')
e = Elemwise(Second(transfer_type(0)), {0:0})(x, y)
f = gof.CLinker().accept(Env([x, y], [e])).make_function()
xv = numpy.ones((5, 5))
......@@ -104,8 +104,8 @@ class test_Broadcast(unittest.TestCase):
assert (xv == yv).all()
def test_weird_strides(self):
x = Tensor('float64', [0, 0, 0, 0, 0])('x')
y = Tensor('float64', [0, 0, 0, 0, 0])('y')
x = NDArrayType('float64', [0, 0, 0, 0, 0])('x')
y = NDArrayType('float64', [0, 0, 0, 0, 0])('y')
e = Elemwise(add)(x, y)
f = gof.CLinker().accept(Env([x, y], [e])).make_function()
xv = numpy.random.rand(2, 2, 2, 2, 2)
......@@ -114,7 +114,7 @@ class test_Broadcast(unittest.TestCase):
assert (f(xv, yv) == zv).all()
def test_same_inputs(self):
x = Tensor('float64', [0, 0])('x')
x = NDArrayType('float64', [0, 0])('x')
e = Elemwise(add)(x, x)
f = gof.CLinker().accept(Env([x], [e])).make_function()
xv = numpy.random.rand(2, 2)
......@@ -134,7 +134,7 @@ class test_CAReduce(unittest.TestCase):
((5, 6), ()),
((2, 3, 4, 5), (0, 1, 3)),
((), ())]:
x = Tensor('float64', [(entry == 1) for entry in xsh])('x')
x = NDArrayType('float64', [(entry == 1) for entry in xsh])('x')
e = CAReduce(add, axis = tosum)(x)
if tosum is None: tosum = range(len(xsh))
f = copy(linker).accept(Env([x], [e])).make_function()
......
......@@ -63,7 +63,7 @@ def test_merge_with_weird_eq():
assert node.inputs[0] is node.inputs[1]
#NONSCALAR CASE
# This was created to test TensorConstantSignature
# This was created to test NDArrayConstantSignature
x = T.constant(numpy.ones(5), name='x')
y = T.constant(numpy.ones(5), name='y')
g = Env([x, y], [x+y])
......
......@@ -6,7 +6,7 @@ import unittest
from theano import gof
from theano.tensor.opt import *
from theano import tensor
from theano.tensor import Tensor
from theano.tensor import NDArrayType
from theano.gof import Env
from theano.tensor.elemwise import DimShuffle
from theano import pprint
......@@ -18,9 +18,9 @@ from theano import function
def inputs(xbc = (0, 0), ybc = (0, 0), zbc = (0, 0)):
x = Tensor(broadcastable = xbc, dtype = 'float64')('x')
y = Tensor(broadcastable = ybc, dtype = 'float64')('y')
z = Tensor(broadcastable = zbc, dtype = 'float64')('z')
x = NDArrayType(broadcastable = xbc, dtype = 'float64')('x')
y = NDArrayType(broadcastable = ybc, dtype = 'float64')('y')
z = NDArrayType(broadcastable = zbc, dtype = 'float64')('z')
return x, y, z
......
......@@ -3,7 +3,7 @@ from theano.tensor.xlogx import xlogx
import unittest
import theano
from theano.tensor import as_tensor
from theano.tensor import as_ndarray_result
import test_basic as TT
import random
......@@ -15,7 +15,7 @@ class T_XlogX(unittest.TestCase):
unittest_tools.seed_rng()
def test0(self):
x = as_tensor([1, 0])
x = as_ndarray_result([1, 0])
y = xlogx(x)
f = theano.function([], [y])
self.failUnless(numpy.all(f() == numpy.asarray([0, 0.])))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论