提交 e5e60a01 authored 作者: Ian Goodfellow's avatar Ian Goodfellow 提交者: Olivier Delalleau

fixed up imports, changed comment

上级 965afb68
...@@ -9,10 +9,24 @@ import numpy ...@@ -9,10 +9,24 @@ import numpy
from numpy.testing import dec from numpy.testing import dec
from numpy.testing.noseclasses import KnownFailureTest from numpy.testing.noseclasses import KnownFailureTest
from theano.tensor import *
from theano.tensor import _shared from theano.tensor import _shared
from theano.tensor import basic as tensor # for hidden symbols import theano.tensor as T
from theano.tensor import inplace from theano.tensor import (wvector, bvector, autocast_float_as, argmin,
max_and_argmax, cscalar, Subtensor, ctensor3, join,
horizontal_stack, vertical_stack, argmax, get_vector_length,
fscalar, zeros_like, sum, tensor3, vector, izip, add, addbroadcast,
alloc, as_tensor_variable, tensor_from_scalar, ARange, autocast_float,
basic, clip, constant, default, dot, inc_subtensor, set_subtensor,
dmatrix, dscalar, dvector, eq, eye, fill, flatten, inverse_permutation,
tensor4, permute_row_elements, Flatten, fmatrix, fscalars, grad,
inplace, iscalar, matrix, minimum, matrices, maximum, mul, neq, Reshape,
row, scalar, scalars, second, smallest, stack, sub, Tensor,
tensor_copy, tensordot, tensordot_grad, TensorType, unbroadcast,
var, value, Join, shape, MaxAndArgmax, lscalar, zvector, exp,
get_constant_value, ivector, reshape, scalar_from_tensor, scal,
iscalars, arange, dscalars, fvector, imatrix, numeric_grad,
opt, ComplexError, TensorDot, lvector, true_div, max, min)
import warnings
from copy import copy from copy import copy
from theano import compile, config from theano import compile, config
...@@ -22,8 +36,9 @@ from theano.gof.python25 import any, all, combinations ...@@ -22,8 +36,9 @@ from theano.gof.python25 import any, all, combinations
from theano.compile.mode import get_default_mode from theano.compile.mode import get_default_mode
from theano import function from theano import function
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
import theano.tensor as T
import theano
import logging
imported_scipy_special = False imported_scipy_special = False
mode_no_scipy = get_default_mode() mode_no_scipy = get_default_mode()
...@@ -498,7 +513,7 @@ _good_broadcast_div_mod_normal_float = dict(empty2 = (numpy.asarray([0]), numpy. ...@@ -498,7 +513,7 @@ _good_broadcast_div_mod_normal_float = dict(empty2 = (numpy.asarray([0]), numpy.
def no_complex(d): def no_complex(d):
"""Remove pairs from dictionary d when the value contains complex data.""" """Remove pairs from dictionary d when the value contains complex data."""
return dict((k, v) for k, v in d.iteritems() return dict((k, v) for k, v in d.iteritems()
if all(str(x.dtype) not in tensor.complex_dtypes for x in v)) if all(str(x.dtype) not in basic.complex_dtypes for x in v))
# 'No-complex' versions. # 'No-complex' versions.
...@@ -526,7 +541,7 @@ if config.floatX=='float32': ...@@ -526,7 +541,7 @@ if config.floatX=='float32':
# float32. # float32.
# This is probably caused by our way of computing the gradient error. # This is probably caused by our way of computing the gradient error.
div_grad_rtol=0.025 div_grad_rtol=0.025
TrueDivTester = makeBroadcastTester(op = true_div, TrueDivTester = makeBroadcastTester(op = T.true_div,
expected = lambda x, y: check_floatX((x, y), x / y), expected = lambda x, y: check_floatX((x, y), x / y),
good = _good_broadcast_div_mod_normal_float, good = _good_broadcast_div_mod_normal_float,
# integers = (randint(2, 3), randint_nonzero(2, 3)), # integers = (randint(2, 3), randint_nonzero(2, 3)),
...@@ -542,7 +557,7 @@ TrueDivInplaceTester = makeBroadcastTester(op = inplace.true_div_inplace, ...@@ -542,7 +557,7 @@ TrueDivInplaceTester = makeBroadcastTester(op = inplace.true_div_inplace,
grad_rtol=div_grad_rtol, grad_rtol=div_grad_rtol,
inplace = True) inplace = True)
ModTester = makeBroadcastTester(op = mod, ModTester = makeBroadcastTester(op = T.mod,
expected = lambda x, y: numpy.asarray(x % y, dtype=theano.scalar.basic.upcast(x.dtype, y.dtype)), expected = lambda x, y: numpy.asarray(x % y, dtype=theano.scalar.basic.upcast(x.dtype, y.dtype)),
good = _good_broadcast_div_mod_normal_float_no_complex, good = _good_broadcast_div_mod_normal_float_no_complex,
# integers = (randint(2, 3), randint_nonzero(2, 3)), # integers = (randint(2, 3), randint_nonzero(2, 3)),
...@@ -625,7 +640,7 @@ _grad_broadcast_unary_normal = dict(normal = (numpy.asarray(rand_ranged(-5, 5, ( ...@@ -625,7 +640,7 @@ _grad_broadcast_unary_normal = dict(normal = (numpy.asarray(rand_ranged(-5, 5, (
AbsTester = makeBroadcastTester(op = tensor.abs_, AbsTester = makeBroadcastTester(op = basic.abs_,
expected = lambda x: abs(x), expected = lambda x: abs(x),
good = _good_broadcast_unary_normal, good = _good_broadcast_unary_normal,
grad = _grad_broadcast_unary_normal) grad = _grad_broadcast_unary_normal)
...@@ -638,7 +653,7 @@ AbsInplaceTester = makeBroadcastTester(op = inplace.abs__inplace, ...@@ -638,7 +653,7 @@ AbsInplaceTester = makeBroadcastTester(op = inplace.abs__inplace,
grad = _grad_broadcast_unary_normal, grad = _grad_broadcast_unary_normal,
inplace = True) inplace = True)
NegTester = makeBroadcastTester(op = neg, NegTester = makeBroadcastTester(op = T.neg,
expected = lambda x: -x, expected = lambda x: -x,
good = _good_broadcast_unary_normal, good = _good_broadcast_unary_normal,
grad = _grad_broadcast_unary_normal) grad = _grad_broadcast_unary_normal)
...@@ -648,7 +663,7 @@ NegInplaceTester = makeBroadcastTester(op = inplace.neg_inplace, ...@@ -648,7 +663,7 @@ NegInplaceTester = makeBroadcastTester(op = inplace.neg_inplace,
grad = _grad_broadcast_unary_normal, grad = _grad_broadcast_unary_normal,
inplace = True) inplace = True)
SgnTester = makeBroadcastTester(op = sgn, SgnTester = makeBroadcastTester(op = T.sgn,
expected = numpy.sign, expected = numpy.sign,
good = _good_broadcast_unary_normal_no_complex, good = _good_broadcast_unary_normal_no_complex,
grad = _grad_broadcast_unary_normal,) grad = _grad_broadcast_unary_normal,)
...@@ -657,7 +672,7 @@ SgnInplaceTester = makeBroadcastTester(op = inplace.sgn_inplace, ...@@ -657,7 +672,7 @@ SgnInplaceTester = makeBroadcastTester(op = inplace.sgn_inplace,
good = _good_broadcast_unary_normal_no_complex, good = _good_broadcast_unary_normal_no_complex,
grad = _grad_broadcast_unary_normal, grad = _grad_broadcast_unary_normal,
inplace = True) inplace = True)
CeilTester = makeBroadcastTester(op = ceil, CeilTester = makeBroadcastTester(op = T.ceil,
expected = lambda a: numpy.asarray(numpy.ceil(a),a.dtype), expected = lambda a: numpy.asarray(numpy.ceil(a),a.dtype),
good = _good_broadcast_unary_normal_no_complex, good = _good_broadcast_unary_normal_no_complex,
grad = _grad_broadcast_unary_normal) grad = _grad_broadcast_unary_normal)
...@@ -667,7 +682,7 @@ CeilInplaceTester = makeBroadcastTester(op = inplace.ceil_inplace, ...@@ -667,7 +682,7 @@ CeilInplaceTester = makeBroadcastTester(op = inplace.ceil_inplace,
grad = _grad_broadcast_unary_normal, grad = _grad_broadcast_unary_normal,
inplace = True) inplace = True)
FloorTester = makeBroadcastTester(op = floor, FloorTester = makeBroadcastTester(op = T.floor,
expected = lambda a: numpy.asarray(numpy.floor(a),a.dtype), expected = lambda a: numpy.asarray(numpy.floor(a),a.dtype),
good = _good_broadcast_unary_normal_no_complex, good = _good_broadcast_unary_normal_no_complex,
grad = _grad_broadcast_unary_normal) grad = _grad_broadcast_unary_normal)
...@@ -677,7 +692,7 @@ FloorInplaceTester = makeBroadcastTester(op = inplace.floor_inplace, ...@@ -677,7 +692,7 @@ FloorInplaceTester = makeBroadcastTester(op = inplace.floor_inplace,
grad = _grad_broadcast_unary_normal, grad = _grad_broadcast_unary_normal,
inplace = True) inplace = True)
RoundHalfToEvenTester = makeBroadcastTester(op = round_half_to_even, RoundHalfToEvenTester = makeBroadcastTester(op = T.round_half_to_even,
expected = numpy.round, expected = numpy.round,
good = _good_broadcast_unary_normal_float_no_complex) good = _good_broadcast_unary_normal_float_no_complex)
# TODO: Why complex are accepted in the next one? # TODO: Why complex are accepted in the next one?
...@@ -689,7 +704,7 @@ RoundHalfToEvenInplaceTester = makeBroadcastTester(op = inplace.round_half_to_ev ...@@ -689,7 +704,7 @@ RoundHalfToEvenInplaceTester = makeBroadcastTester(op = inplace.round_half_to_ev
#numpy.vectorize don't handle correctly empty ndarray. #numpy.vectorize don't handle correctly empty ndarray.
#see in their file numpy/lib/function_base.py in class vectorize.__call__ #see in their file numpy/lib/function_base.py in class vectorize.__call__
#This happen in float32 mode. #This happen in float32 mode.
RoundHalfAwayFromZeroTester = makeBroadcastTester(op = round_half_away_from_zero, RoundHalfAwayFromZeroTester = makeBroadcastTester(op = T.round_half_away_from_zero,
expected = theano.scalar.basic.round_half_away_from_zero_vec, expected = theano.scalar.basic.round_half_away_from_zero_vec,
good = _good_broadcast_unary_normal_float_no_empty_no_complex)#_good_broadcast_unary_normal_float) good = _good_broadcast_unary_normal_float_no_empty_no_complex)#_good_broadcast_unary_normal_float)
RoundHalfAwayFromZeroInplaceTester = makeBroadcastTester(op = inplace.round_half_away_from_zero_inplace, RoundHalfAwayFromZeroInplaceTester = makeBroadcastTester(op = inplace.round_half_away_from_zero_inplace,
...@@ -697,7 +712,7 @@ RoundHalfAwayFromZeroInplaceTester = makeBroadcastTester(op = inplace.round_half ...@@ -697,7 +712,7 @@ RoundHalfAwayFromZeroInplaceTester = makeBroadcastTester(op = inplace.round_half
good = _good_broadcast_unary_normal_float_no_empty_no_complex, good = _good_broadcast_unary_normal_float_no_empty_no_complex,
inplace = True) inplace = True)
SqrTester = makeBroadcastTester(op = sqr, SqrTester = makeBroadcastTester(op = T.sqr,
expected = numpy.square, expected = numpy.square,
good = _good_broadcast_unary_normal, good = _good_broadcast_unary_normal,
grad = _grad_broadcast_unary_normal) grad = _grad_broadcast_unary_normal)
...@@ -707,7 +722,7 @@ SqrInplaceTester = makeBroadcastTester(op = inplace.sqr_inplace, ...@@ -707,7 +722,7 @@ SqrInplaceTester = makeBroadcastTester(op = inplace.sqr_inplace,
grad = _grad_broadcast_unary_normal, grad = _grad_broadcast_unary_normal,
inplace = True) inplace = True)
ExpTester = makeBroadcastTester(op = exp, ExpTester = makeBroadcastTester(op = T.exp,
expected = numpy.exp, expected = numpy.exp,
good = _good_broadcast_unary_normal, good = _good_broadcast_unary_normal,
grad = _grad_broadcast_unary_normal) grad = _grad_broadcast_unary_normal)
...@@ -729,7 +744,7 @@ _grad_broadcast_unary_positive = dict(normal = (rand_ranged(0.001, 5, (2, 3)),), ...@@ -729,7 +744,7 @@ _grad_broadcast_unary_positive = dict(normal = (rand_ranged(0.001, 5, (2, 3)),),
#empty = (numpy.asarray([]),), #empty = (numpy.asarray([]),),
) )
LogTester = makeBroadcastTester(op = log, LogTester = makeBroadcastTester(op = T.log,
expected = numpy.log, expected = numpy.log,
good = _good_broadcast_unary_positive, good = _good_broadcast_unary_positive,
grad = _grad_broadcast_unary_positive) grad = _grad_broadcast_unary_positive)
...@@ -739,7 +754,7 @@ LogInplaceTester = makeBroadcastTester(op = inplace.log_inplace, ...@@ -739,7 +754,7 @@ LogInplaceTester = makeBroadcastTester(op = inplace.log_inplace,
grad = _grad_broadcast_unary_positive, grad = _grad_broadcast_unary_positive,
inplace = True) inplace = True)
Log2Tester = makeBroadcastTester(op = log2, Log2Tester = makeBroadcastTester(op = T.log2,
expected = numpy.log2, expected = numpy.log2,
good = _good_broadcast_unary_positive, good = _good_broadcast_unary_positive,
grad = _grad_broadcast_unary_positive) grad = _grad_broadcast_unary_positive)
...@@ -749,7 +764,7 @@ Log2InplaceTester = makeBroadcastTester(op = inplace.log2_inplace, ...@@ -749,7 +764,7 @@ Log2InplaceTester = makeBroadcastTester(op = inplace.log2_inplace,
grad = _grad_broadcast_unary_positive, grad = _grad_broadcast_unary_positive,
inplace = True) inplace = True)
Log10Tester = makeBroadcastTester(op = log10, Log10Tester = makeBroadcastTester(op = T.log10,
expected = numpy.log10, expected = numpy.log10,
good = _good_broadcast_unary_positive, good = _good_broadcast_unary_positive,
grad = _grad_broadcast_unary_positive) grad = _grad_broadcast_unary_positive)
...@@ -759,7 +774,7 @@ Log10InplaceTester = makeBroadcastTester(op = inplace.log10_inplace, ...@@ -759,7 +774,7 @@ Log10InplaceTester = makeBroadcastTester(op = inplace.log10_inplace,
grad = _grad_broadcast_unary_positive, grad = _grad_broadcast_unary_positive,
inplace = True) inplace = True)
Log1pTester = makeBroadcastTester(op = log1p, Log1pTester = makeBroadcastTester(op = T.log1p,
expected = numpy.log1p, expected = numpy.log1p,
good = _good_broadcast_unary_positive, good = _good_broadcast_unary_positive,
grad = _grad_broadcast_unary_positive) grad = _grad_broadcast_unary_positive)
...@@ -770,7 +785,7 @@ Log1pInplaceTester = makeBroadcastTester(op = inplace.log1p_inplace, ...@@ -770,7 +785,7 @@ Log1pInplaceTester = makeBroadcastTester(op = inplace.log1p_inplace,
inplace = True) inplace = True)
SqrtTester = makeBroadcastTester(op = sqrt, SqrtTester = makeBroadcastTester(op = T.sqrt,
expected = numpy.sqrt, expected = numpy.sqrt,
good = _good_broadcast_unary_positive, good = _good_broadcast_unary_positive,
grad = _grad_broadcast_unary_positive) grad = _grad_broadcast_unary_positive)
...@@ -803,7 +818,7 @@ _grad_broadcast_unary_arccos = dict(normal = (rand_ranged(-1.+1e-7, 1-1e-7, (2, ...@@ -803,7 +818,7 @@ _grad_broadcast_unary_arccos = dict(normal = (rand_ranged(-1.+1e-7, 1-1e-7, (2,
) )
SinTester = makeBroadcastTester(op = sin, SinTester = makeBroadcastTester(op = T.sin,
expected = numpy.sin, expected = numpy.sin,
good = _good_broadcast_unary_wide, good = _good_broadcast_unary_wide,
grad = _grad_broadcast_unary_wide) grad = _grad_broadcast_unary_wide)
...@@ -813,7 +828,7 @@ SinInplaceTester = makeBroadcastTester(op = inplace.sin_inplace, ...@@ -813,7 +828,7 @@ SinInplaceTester = makeBroadcastTester(op = inplace.sin_inplace,
grad = _grad_broadcast_unary_wide, grad = _grad_broadcast_unary_wide,
inplace = True) inplace = True)
CosTester = makeBroadcastTester(op = cos, CosTester = makeBroadcastTester(op = T.cos,
expected = numpy.cos, expected = numpy.cos,
good = _good_broadcast_unary_wide, good = _good_broadcast_unary_wide,
grad = _grad_broadcast_unary_wide) grad = _grad_broadcast_unary_wide)
...@@ -822,7 +837,7 @@ CosInplaceTester = makeBroadcastTester(op = inplace.cos_inplace, ...@@ -822,7 +837,7 @@ CosInplaceTester = makeBroadcastTester(op = inplace.cos_inplace,
good = _good_broadcast_unary_wide, good = _good_broadcast_unary_wide,
grad = _grad_broadcast_unary_wide, grad = _grad_broadcast_unary_wide,
inplace = True) inplace = True)
ArccosTester = makeBroadcastTester(op = arccos, ArccosTester = makeBroadcastTester(op = T.arccos,
expected = numpy.arccos, expected = numpy.arccos,
good = _good_broadcast_unary_arccos, good = _good_broadcast_unary_arccos,
grad = _grad_broadcast_unary_arccos) grad = _grad_broadcast_unary_arccos)
...@@ -837,7 +852,7 @@ if config.floatX=='float32': ...@@ -837,7 +852,7 @@ if config.floatX=='float32':
#We raise the relative tolerence for the grad as their is error in float32 #We raise the relative tolerence for the grad as their is error in float32
#This is probably caused by our way of computing the gradient error. #This is probably caused by our way of computing the gradient error.
tan_grad_rtol = 0.052 tan_grad_rtol = 0.052
TanTester = makeBroadcastTester(op = tan, TanTester = makeBroadcastTester(op = T.tan,
expected = numpy.tan, expected = numpy.tan,
good = dict(normal = (rand_ranged(-3.14, 3.14, (2, 3)),), good = dict(normal = (rand_ranged(-3.14, 3.14, (2, 3)),),
shifted = (rand_ranged(3.15, 6.28, (2, 3)),)), shifted = (rand_ranged(3.15, 6.28, (2, 3)),)),
...@@ -854,7 +869,7 @@ TanInplaceTester = makeBroadcastTester(op = inplace.tan_inplace, ...@@ -854,7 +869,7 @@ TanInplaceTester = makeBroadcastTester(op = inplace.tan_inplace,
inplace = True) inplace = True)
CoshTester = makeBroadcastTester(op = cosh, CoshTester = makeBroadcastTester(op = T.cosh,
expected = numpy.cosh, expected = numpy.cosh,
good = _good_broadcast_unary_normal, good = _good_broadcast_unary_normal,
grad = _grad_broadcast_unary_normal) grad = _grad_broadcast_unary_normal)
...@@ -864,7 +879,7 @@ CoshInplaceTester = makeBroadcastTester(op = inplace.cosh_inplace, ...@@ -864,7 +879,7 @@ CoshInplaceTester = makeBroadcastTester(op = inplace.cosh_inplace,
grad = _grad_broadcast_unary_normal, grad = _grad_broadcast_unary_normal,
inplace = True) inplace = True)
SinhTester = makeBroadcastTester(op = sinh, SinhTester = makeBroadcastTester(op = T.sinh,
expected = numpy.sinh, expected = numpy.sinh,
good = _good_broadcast_unary_normal, good = _good_broadcast_unary_normal,
grad = _grad_broadcast_unary_normal) grad = _grad_broadcast_unary_normal)
...@@ -874,7 +889,7 @@ SinhInplaceTester = makeBroadcastTester(op = inplace.sinh_inplace, ...@@ -874,7 +889,7 @@ SinhInplaceTester = makeBroadcastTester(op = inplace.sinh_inplace,
grad = _grad_broadcast_unary_normal, grad = _grad_broadcast_unary_normal,
inplace = True) inplace = True)
TanhTester = makeBroadcastTester(op = tanh, TanhTester = makeBroadcastTester(op = T.tanh,
expected = numpy.tanh, expected = numpy.tanh,
good = _good_broadcast_unary_normal, good = _good_broadcast_unary_normal,
grad = _grad_broadcast_unary_normal) grad = _grad_broadcast_unary_normal)
...@@ -904,7 +919,7 @@ else: ...@@ -904,7 +919,7 @@ else:
expected_erfc = [] expected_erfc = []
skip_scipy = "scipy is not present" skip_scipy = "scipy is not present"
ErfTester = makeBroadcastTester(op = erf, ErfTester = makeBroadcastTester(op = T.erf,
expected = expected_erf, expected = expected_erf,
good = _good_broadcast_unary_normal, good = _good_broadcast_unary_normal,
grad = _grad_broadcast_unary_normal, grad = _grad_broadcast_unary_normal,
...@@ -920,7 +935,7 @@ ErfInplaceTester = makeBroadcastTester(op = inplace.erf_inplace, ...@@ -920,7 +935,7 @@ ErfInplaceTester = makeBroadcastTester(op = inplace.erf_inplace,
inplace = True, inplace = True,
skip = skip_scipy) skip = skip_scipy)
ErfcTester = makeBroadcastTester(op = erfc, ErfcTester = makeBroadcastTester(op = T.erfc,
expected = expected_erfc, expected = expected_erfc,
good = _good_broadcast_unary_normal_no_int_no_complex, good = _good_broadcast_unary_normal_no_int_no_complex,
grad = _grad_broadcast_unary_normal, grad = _grad_broadcast_unary_normal,
...@@ -936,12 +951,12 @@ ErfcInplaceTester = makeBroadcastTester(op = inplace.erfc_inplace, ...@@ -936,12 +951,12 @@ ErfcInplaceTester = makeBroadcastTester(op = inplace.erfc_inplace,
inplace = True, inplace = True,
skip = skip_scipy) skip = skip_scipy)
ZerosLikeTester = makeBroadcastTester(op = zeros_like, ZerosLikeTester = makeBroadcastTester(op = T.zeros_like,
expected = numpy.zeros_like, expected = numpy.zeros_like,
good = _good_broadcast_unary_normal, good = _good_broadcast_unary_normal,
grad = _grad_broadcast_unary_normal) grad = _grad_broadcast_unary_normal)
OnesLikeTester = makeBroadcastTester(op = ones_like, OnesLikeTester = makeBroadcastTester(op = T.ones_like,
expected = numpy.ones_like, expected = numpy.ones_like,
good = _good_broadcast_unary_normal, good = _good_broadcast_unary_normal,
grad = _grad_broadcast_unary_normal) grad = _grad_broadcast_unary_normal)
...@@ -1082,16 +1097,16 @@ Alloc13GradTester = makeBroadcastTester( ...@@ -1082,16 +1097,16 @@ Alloc13GradTester = makeBroadcastTester(
def test_eye(): def test_eye():
def check(dtype, N, M_=None, k=0): def check(dtype, N, M_=None, k=0):
# Theano does not accept None as a tensor. # Theano does not accept None as a basic.
# So we must use a real value. # So we must use a real value.
M = M_ M = M_
# Currently DebugMode does not support None as inputs even if this is # Currently DebugMode does not support None as inputs even if this is
# allowed. # allowed.
if M is None and theano.config.mode in ['DebugMode', 'DEBUG_MODE']: if M is None and theano.config.mode in ['DebugMode', 'DEBUG_MODE']:
M = N M = N
N_symb = tensor.iscalar() N_symb = basic.iscalar()
M_symb = tensor.iscalar() M_symb = basic.iscalar()
k_symb = tensor.iscalar() k_symb = basic.iscalar()
f = function([N_symb, M_symb, k_symb], f = function([N_symb, M_symb, k_symb],
eye(N_symb, M_symb, k_symb, dtype=dtype)) eye(N_symb, M_symb, k_symb, dtype=dtype))
result = f(N, M, k) result = f(N, M, k)
...@@ -1115,7 +1130,7 @@ def test_eye(): ...@@ -1115,7 +1130,7 @@ def test_eye():
def test_identity(): def test_identity():
def check(dtype): def check(dtype):
obj = rand_of_dtype((2,), dtype) obj = rand_of_dtype((2,), dtype)
sym = tensor.vector(dtype=dtype) sym = basic.vector(dtype=dtype)
f = function([sym], tensor_copy(sym)) f = function([sym], tensor_copy(sym))
assert numpy.all(obj == f(obj)) assert numpy.all(obj == f(obj))
assert obj.dtype == f(obj).dtype assert obj.dtype == f(obj).dtype
...@@ -1137,16 +1152,16 @@ class CastTester(unittest.TestCase): ...@@ -1137,16 +1152,16 @@ class CastTester(unittest.TestCase):
(rand_of_dtype((2,), dtype), dtype)) (rand_of_dtype((2,), dtype), dtype))
for dtype in ALL_DTYPES]) for dtype in ALL_DTYPES])
for testname, (obj, dtype) in good: for testname, (obj, dtype) in good:
inp = tensor.vector(dtype=obj.dtype) inp = basic.vector(dtype=obj.dtype)
out = tensor.cast(inp, dtype=dtype) out = basic.cast(inp, dtype=dtype)
f = function([inp], out) f = function([inp], out)
assert f(obj).dtype == numpy.dtype(dtype) assert f(obj).dtype == numpy.dtype(dtype)
def test_cast_from_real_to_complex(self): def test_cast_from_real_to_complex(self):
for real_dtype in REAL_DTYPES: for real_dtype in REAL_DTYPES:
for complex_dtype in COMPLEX_DTYPES: for complex_dtype in COMPLEX_DTYPES:
inp = tensor.vector(dtype=real_dtype) inp = basic.vector(dtype=real_dtype)
out = tensor.cast(inp, dtype=complex_dtype) out = basic.cast(inp, dtype=complex_dtype)
f = function([inp], out) f = function([inp], out)
obj = rand_of_dtype((2, ), real_dtype) obj = rand_of_dtype((2, ), real_dtype)
assert f(obj).dtype == numpy.dtype(complex_dtype) assert f(obj).dtype == numpy.dtype(complex_dtype)
...@@ -1154,8 +1169,8 @@ class CastTester(unittest.TestCase): ...@@ -1154,8 +1169,8 @@ class CastTester(unittest.TestCase):
def test_cast_from_complex_to_real_raises_error(self): def test_cast_from_complex_to_real_raises_error(self):
for real_dtype in REAL_DTYPES: for real_dtype in REAL_DTYPES:
for complex_dtype in COMPLEX_DTYPES: for complex_dtype in COMPLEX_DTYPES:
inp = tensor.vector(dtype=real_dtype) inp = basic.vector(dtype=real_dtype)
self.assertRaises(TypeError, tensor.cast(inp, dtype=complex_dtype)) self.assertRaises(TypeError, basic.cast(inp, dtype=complex_dtype))
ClipTester = makeTester(name='ClipTester', ClipTester = makeTester(name='ClipTester',
op=clip, op=clip,
...@@ -1189,9 +1204,9 @@ ClipTester = makeTester(name='ClipTester', ...@@ -1189,9 +1204,9 @@ ClipTester = makeTester(name='ClipTester',
class T_Clip(unittest.TestCase): class T_Clip(unittest.TestCase):
def test_complex_value(self): def test_complex_value(self):
for dtype in ['complex64', 'complex128']: for dtype in ['complex64', 'complex128']:
a = tensor.vector(dtype=dtype) a = basic.vector(dtype=dtype)
b = tensor.scalar() b = basic.scalar()
c = tensor.scalar() c = basic.scalar()
self.assertRaises(TypeError, clip, a, b, c) self.assertRaises(TypeError, clip, a, b, c)
#TODO: consider moving this function / functionality to gradient.py #TODO: consider moving this function / functionality to gradient.py
...@@ -1289,7 +1304,7 @@ def test_nan_inf_constant_signature(): ...@@ -1289,7 +1304,7 @@ def test_nan_inf_constant_signature():
assert (x.signature() == y.signature()) == (i == j) assert (x.signature() == y.signature()) == (i == j)
# Also test that nan !=0 and nan != nan. # Also test that nan !=0 and nan != nan.
x = tensor.scalar() x = basic.scalar()
mode = get_default_mode() mode = get_default_mode()
if isinstance(mode, theano.compile.debugmode.DebugMode): if isinstance(mode, theano.compile.debugmode.DebugMode):
# Disable the check preventing usage of NaN / Inf values. # Disable the check preventing usage of NaN / Inf values.
...@@ -1818,10 +1833,10 @@ class T_subtensor(unittest.TestCase): ...@@ -1818,10 +1833,10 @@ class T_subtensor(unittest.TestCase):
This is build in a way that allow to reuse it to test the equivalent gpu op. This is build in a way that allow to reuse it to test the equivalent gpu op.
""" """
def __init__(self, name, shared=_shared, def __init__(self, name, shared=_shared,
sub=theano.tensor.basic.Subtensor, sub=basic.Subtensor,
inc_sub=theano.tensor.basic.IncSubtensor, inc_sub=basic.IncSubtensor,
adv_sub1=theano.tensor.basic.AdvancedSubtensor1, adv_sub1=basic.AdvancedSubtensor1,
adv_incsub1=theano.tensor.basic.AdvancedIncSubtensor1, adv_incsub1=basic.AdvancedIncSubtensor1,
mode=None, mode=None,
dtype=theano.config.floatX, dtype=theano.config.floatX,
ignore_topo=(theano.compile.function_module.DeepCopyOp)): ignore_topo=(theano.compile.function_module.DeepCopyOp)):
...@@ -2125,7 +2140,7 @@ class T_subtensor(unittest.TestCase): ...@@ -2125,7 +2140,7 @@ class T_subtensor(unittest.TestCase):
self.assertTrue(numpy.allclose(val, good), (val, good)) self.assertTrue(numpy.allclose(val, good), (val, good))
# Test reuse of output memory # Test reuse of output memory
if isinstance(self.adv_sub1,tensor.AdvancedSubtensor1): if isinstance(self.adv_sub1,basic.AdvancedSubtensor1):
op = self.adv_sub1() op = self.adv_sub1()
# When idx is a TensorConstant. # When idx is a TensorConstant.
if hasattr(idx, "data"): if hasattr(idx, "data"):
...@@ -2164,7 +2179,7 @@ class T_subtensor(unittest.TestCase): ...@@ -2164,7 +2179,7 @@ class T_subtensor(unittest.TestCase):
def test_adv_sub1_broadcast(self): def test_adv_sub1_broadcast(self):
ones = numpy.ones((1,3), dtype=self.dtype) ones = numpy.ones((1,3), dtype=self.dtype)
n = self.shared(ones*5, broadcastable=(True, False)) n = self.shared(ones*5, broadcastable=(True, False))
idx = tensor.lvector() idx = basic.lvector()
t = n[idx] t = n[idx]
self.assertTrue(isinstance(t.owner.op, theano.tensor.basic.AdvancedSubtensor1)) self.assertTrue(isinstance(t.owner.op, theano.tensor.basic.AdvancedSubtensor1))
...@@ -2566,8 +2581,8 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2566,8 +2581,8 @@ class T_Join_and_Split(unittest.TestCase):
def test_stack_scalar_make_vector(self): def test_stack_scalar_make_vector(self):
'''Test that calling stack() on scalars instantiates MakeVector, '''Test that calling stack() on scalars instantiates MakeVector,
not Join. Test that the floatX dtype stay floatX, not downcasted to int64''' not Join. Test that the floatX dtype stay floatX, not downcasted to int64'''
a = tensor.scalar('a') a = basic.scalar('a')
b = tensor.scalar('b') b = basic.scalar('b')
s = stack(a, b, a, b) s = stack(a, b, a, b)
f = function([a,b], s) f = function([a,b], s)
val = f(1,2) val = f(1,2)
...@@ -2581,8 +2596,8 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2581,8 +2596,8 @@ class T_Join_and_Split(unittest.TestCase):
def test_stack_scalar_make_vector_dtype(self): def test_stack_scalar_make_vector_dtype(self):
'''Test that calling stack() on scalars instantiates MakeVector, '''Test that calling stack() on scalars instantiates MakeVector,
event when the scalar don't have the same dtype.''' event when the scalar don't have the same dtype.'''
a = tensor.iscalar('a') a = basic.iscalar('a')
b = tensor.lscalar('b') b = basic.lscalar('b')
s = stack(a, b, a, b) s = stack(a, b, a, b)
f = function([a,b], s) f = function([a,b], s)
val = f(1,2) val = f(1,2)
...@@ -2595,8 +2610,8 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2595,8 +2610,8 @@ class T_Join_and_Split(unittest.TestCase):
def test_stack_scalar_make_vector_constant(self): def test_stack_scalar_make_vector_constant(self):
'''Test that calling stack() on scalars instantiates MakeVector, '''Test that calling stack() on scalars instantiates MakeVector,
event when the scalar are simple int type.''' event when the scalar are simple int type.'''
a = tensor.iscalar('a') a = basic.iscalar('a')
b = tensor.lscalar('b') b = basic.lscalar('b')
#test when the constant is the first element. #test when the constant is the first element.
#The first element is used in a special way #The first element is used in a special way
s = stack(10,a,b, numpy.int8(3)) s = stack(10,a,b, numpy.int8(3))
...@@ -2860,7 +2875,7 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2860,7 +2875,7 @@ class T_Join_and_Split(unittest.TestCase):
if theano.config.mode != 'FAST_COMPILE': if theano.config.mode != 'FAST_COMPILE':
for node in f.maker.env.toposort(): for node in f.maker.env.toposort():
assert not isinstance(node.op, tensor.Join) assert not isinstance(node.op, basic.Join)
# Test dim 1 # Test dim 1
z = join(1,x1,x2,x3) z = join(1,x1,x2,x3)
...@@ -2870,7 +2885,7 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -2870,7 +2885,7 @@ class T_Join_and_Split(unittest.TestCase):
if theano.config.mode != 'FAST_COMPILE': if theano.config.mode != 'FAST_COMPILE':
for node in f.maker.env.toposort(): for node in f.maker.env.toposort():
assert not isinstance(node.op, tensor.Join) assert not isinstance(node.op, basic.Join)
# Test hide error # Test hide error
if theano.config.mode in ['DebugMode', 'DEBUG_MODE', 'FAST_COMPILE']: if theano.config.mode in ['DebugMode', 'DEBUG_MODE', 'FAST_COMPILE']:
...@@ -3020,7 +3035,7 @@ class T_add(unittest.TestCase): ...@@ -3020,7 +3035,7 @@ class T_add(unittest.TestCase):
class T_ceil(unittest.TestCase): class T_ceil(unittest.TestCase):
def test_complex(self): def test_complex(self):
self.assertRaises(TypeError, ceil, zvector()) self.assertRaises(TypeError, T.ceil, T.zvector())
class T_exp(unittest.TestCase): class T_exp(unittest.TestCase):
def test_grad_0(self): def test_grad_0(self):
...@@ -3653,7 +3668,7 @@ class test_grad(unittest.TestCase): ...@@ -3653,7 +3668,7 @@ class test_grad(unittest.TestCase):
"""grad: Test passing a single variable param""" """grad: Test passing a single variable param"""
o = test_grad.O() o = test_grad.O()
a1 = o.make_node() a1 = o.make_node()
self.assertTrue(o.gval0 is grad(a1.outputs[0], a1.inputs[0])) self.assertTrue(o.gval0 is T.grad(a1.outputs[0], a1.inputs[0]))
def test_Nparam(self): def test_Nparam(self):
"""grad: Test passing multiple variable params""" """grad: Test passing multiple variable params"""
...@@ -3667,8 +3682,10 @@ class test_grad(unittest.TestCase): ...@@ -3667,8 +3682,10 @@ class test_grad(unittest.TestCase):
def test_grad_keep_type(self): def test_grad_keep_type(self):
"""Tests that the theano grad method returns a list if it is passed a list """Tests that the theano grad method returns a list if it is passed a list
and a single variable if it is passed a single variable. and a single variable if it is passed a single variable.
pylearn2 depends on theano behaving this way but theano developers have pylearn2 depends on theano behaving this way. This functionality has been
repeatedly changed it """ added three times and erroneously removed twice. If you do anything that
requires changing this test or making it fail you are almost certainly
making a common mistake, NOT fixing something. """
X = T.matrix() X = T.matrix()
y = X.sum() y = X.sum()
...@@ -3838,7 +3855,7 @@ class T_reshape(unittest.TestCase): ...@@ -3838,7 +3855,7 @@ class T_reshape(unittest.TestCase):
def test_make_column_matrix_broadcastable(): def test_make_column_matrix_broadcastable():
# The goal of the operation made by `b` is to ensure the second dimension # The goal of the operation made by `b` is to ensure the second dimension
# of the column matrix is broadcastable. # of the column matrix is broadcastable.
a = dmatrix() a = T.dmatrix()
b = a.reshape((a.shape[0], )).dimshuffle(0, 'x') b = a.reshape((a.shape[0], )).dimshuffle(0, 'x')
f = function([a], b) f = function([a], b)
assert (f(numpy.zeros((3, 1))) + numpy.ones(2) == numpy.ones((3, 2))).all() assert (f(numpy.zeros((3, 1))) + numpy.ones(2) == numpy.ones((3, 2))).all()
...@@ -4774,7 +4791,7 @@ def _test_autocast_numpy(): ...@@ -4774,7 +4791,7 @@ def _test_autocast_numpy():
assert config.cast_policy == 'numpy' assert config.cast_policy == 'numpy'
# Go through some typical scalar values. # Go through some typical scalar values.
def ok(z): def ok(z):
assert tensor.constant(z).dtype == numpy.asarray(z).dtype assert basic.constant(z).dtype == numpy.asarray(z).dtype
for x in ([2**i for i in xrange(63)] + for x in ([2**i for i in xrange(63)] +
[0] + [0] +
[0., 1., 1.1, 1.5]): [0., 1., 1.1, 1.5]):
...@@ -4796,9 +4813,9 @@ def _test_autocast_numpy_floatX(): ...@@ -4796,9 +4813,9 @@ def _test_autocast_numpy_floatX():
floatX == 'float32' and floatX == 'float32' and
not hasattr(z, 'dtype')): not hasattr(z, 'dtype')):
# Special case where we use 'float32' instead of 'float64'. # Special case where we use 'float32' instead of 'float64'.
assert tensor.constant(z).dtype == 'float32' assert basic.constant(z).dtype == 'float32'
else: else:
assert tensor.constant(z).dtype == numpy.asarray(z).dtype assert basic.constant(z).dtype == numpy.asarray(z).dtype
try: try:
# Test with various values of `config.floatX`. # Test with various values of `config.floatX`.
for floatX in ('float32', 'float64'): for floatX in ('float32', 'float64'):
...@@ -4837,9 +4854,9 @@ class test_arithmetic_cast(unittest.TestCase): ...@@ -4837,9 +4854,9 @@ class test_arithmetic_cast(unittest.TestCase):
# scalar == scalar stored as a 0d array # scalar == scalar stored as a 0d array
# array == 1d array # array == 1d array
# i_scalar == scalar type used internally by Theano # i_scalar == scalar type used internally by Theano
theano_scalar = lambda dtype: tensor.scalar(dtype=str(dtype)) theano_scalar = lambda dtype: basic.scalar(dtype=str(dtype))
numpy_scalar = lambda dtype: numpy.array(1, dtype=dtype) numpy_scalar = lambda dtype: numpy.array(1, dtype=dtype)
theano_array = lambda dtype: tensor.vector(dtype=str(dtype)) theano_array = lambda dtype: basic.vector(dtype=str(dtype))
numpy_array = lambda dtype: numpy.array([1], dtype=dtype) numpy_array = lambda dtype: numpy.array([1], dtype=dtype)
theano_i_scalar = lambda dtype: theano.scalar.Scalar(str(dtype))() theano_i_scalar = lambda dtype: theano.scalar.Scalar(str(dtype))()
numpy_i_scalar = numpy_scalar numpy_i_scalar = numpy_scalar
...@@ -4860,8 +4877,8 @@ class test_arithmetic_cast(unittest.TestCase): ...@@ -4860,8 +4877,8 @@ class test_arithmetic_cast(unittest.TestCase):
# special way (depending on `config.int_division`). # special way (depending on `config.int_division`).
is_int_division = ( is_int_division = (
op is operator.div and op is operator.div and
a_type in tensor.discrete_dtypes and a_type in basic.discrete_dtypes and
b_type in tensor.discrete_dtypes) b_type in basic.discrete_dtypes)
# We will test all meaningful combinations of # We will test all meaningful combinations of
# scalar and array operations. # scalar and array operations.
for combo in ( for combo in (
...@@ -5076,10 +5093,10 @@ def test_mod_compile(): ...@@ -5076,10 +5093,10 @@ def test_mod_compile():
The c_code generated is not compiling as of 30 June 2010. I fix the compilation in the same commit. The c_code generated is not compiling as of 30 June 2010. I fix the compilation in the same commit.
""" """
x = tensor.vector() x = basic.vector()
y = tensor.vector() y = basic.vector()
shape = x.shape shape = x.shape
out = tensor.switch(tensor.eq(3%x.shape[0],0),y,y[:-1]) out = basic.switch(basic.eq(3%x.shape[0],0),y,y[:-1])
f = theano.function([x,y],out) f = theano.function([x,y],out)
...@@ -5097,7 +5114,7 @@ def test_unalign(): ...@@ -5097,7 +5114,7 @@ def test_unalign():
b[:] = numpy.random.rand(len(b)) b[:] = numpy.random.rand(len(b))
out_numpy = 2*a + 3*b out_numpy = 2*a + 3*b
av,bv = tensor.vectors('ab') av,bv = basic.vectors('ab')
f = theano.function([av,bv],2*av+3*bv) f = theano.function([av,bv],2*av+3*bv)
f.maker.env.toposort() f.maker.env.toposort()
# FAST_COMPILE use the python code that support unaligned data # FAST_COMPILE use the python code that support unaligned data
...@@ -5130,28 +5147,28 @@ def test_dimshuffle_duplicate(): ...@@ -5130,28 +5147,28 @@ def test_dimshuffle_duplicate():
class T_get_constant_value(unittest.TestCase): class T_get_constant_value(unittest.TestCase):
def test_get_constant_value(self): def test_get_constant_value(self):
a = tensor.stack(1,2,3) a = basic.stack(1,2,3)
assert get_constant_value(a[0])==1 assert get_constant_value(a[0])==1
assert get_constant_value(a[1])==2 assert get_constant_value(a[1])==2
assert get_constant_value(a[2])==3 assert get_constant_value(a[2])==3
b = tensor.iscalar() b = basic.iscalar()
a = tensor.stack(b,2,3) a = basic.stack(b,2,3)
self.assertRaises(TypeError, get_constant_value, a[0]) self.assertRaises(TypeError, get_constant_value, a[0])
assert get_constant_value(a[1])==2 assert get_constant_value(a[1])==2
assert get_constant_value(a[2])==3 assert get_constant_value(a[2])==3
# For now get_constant_value goes through only MakeVector and Join of # For now get_constant_value goes through only MakeVector and Join of
# scalars. # scalars.
v = tensor.ivector() v = basic.ivector()
a = tensor.stack(v,2,3) a = basic.stack(v,2,3)
self.assertRaises(TypeError, get_constant_value, a[0]) self.assertRaises(TypeError, get_constant_value, a[0])
self.assertRaises(TypeError, get_constant_value, a[1]) self.assertRaises(TypeError, get_constant_value, a[1])
self.assertRaises(TypeError, get_constant_value, a[2]) self.assertRaises(TypeError, get_constant_value, a[2])
# Test the case SubTensor(Shape(v)) when the dimensions # Test the case SubTensor(Shape(v)) when the dimensions
# is broadcastable. # is broadcastable.
v = tensor.row() v = basic.row()
assert get_constant_value(v.shape[0])==1 assert get_constant_value(v.shape[0])==1
def test_subtensor_of_constant(self): def test_subtensor_of_constant(self):
...@@ -5198,17 +5215,17 @@ class test_size(unittest.TestCase): ...@@ -5198,17 +5215,17 @@ class test_size(unittest.TestCase):
""" """
def test_matrix(self): def test_matrix(self):
x = tensor.matrix() x = basic.matrix()
y = numpy.zeros((5, 7), dtype=config.floatX) y = numpy.zeros((5, 7), dtype=config.floatX)
assert y.size == function([x], x.size)(y) assert y.size == function([x], x.size)(y)
def test_vector(self): def test_vector(self):
x = tensor.vector() x = basic.vector()
y = numpy.zeros(7, dtype=config.floatX) y = numpy.zeros(7, dtype=config.floatX)
assert y.size == function([x], x.size)(y) assert y.size == function([x], x.size)(y)
def test_scalar(self): def test_scalar(self):
x = tensor.scalar() x = basic.scalar()
y = numpy.array(7, dtype=config.floatX) y = numpy.array(7, dtype=config.floatX)
assert y.size == function([x], x.size)(y) assert y.size == function([x], x.size)(y)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论