提交 7fabbc7e authored 作者: Frédéric Bastien's avatar Frédéric Bastien 提交者: GitHub

Merge pull request #6315 from gvtulder/f-tensor6-tensor7

Adding tensor6 and tensor7 constructors
...@@ -18,17 +18,23 @@ shapes = [ ...@@ -18,17 +18,23 @@ shapes = [
('matrix', (False,False)), ('matrix', (False,False)),
('tensor3', (False,False,False)), ('tensor3', (False,False,False)),
('tensor4', (False,False,False,False)), ('tensor4', (False,False,False,False)),
('tensor5', (False,False,False,False,False)),] ('tensor5', (False,False,False,False,False)),
('tensor6', (False,) * 6),
('tensor7', (False,) * 7),]
hdr = '============ =========== ==== ============ ===================================' hdr = '============ =========== ==== ================ ==================================='
print(hdr) print(hdr)
print('Constructor dtype ndim shape broadcastable') print('Constructor dtype ndim shape broadcastable')
print(hdr) print(hdr)
for letter in letters: for letter in letters:
for shape in shapes: for shape in shapes:
suff = ',)' if len(shape[1])==1 else ')' suff = ',)' if len(shape[1])==1 else ')'
s = '(' + ','.join('1' if b else '?' for b in shape[1]) + suff s = '(' + ','.join('1' if b else '?' for b in shape[1]) + suff
print('%s%-10s %-10s %-4s %-11s %-20s' %( if len(shape[1]) < 6 or len(set(shape[1])) > 1:
letter[0], shape[0], letter[1], len(shape[1]), s, shape[1] broadcastable_str = str(shape[1])
else:
broadcastable_str = '(%s,) * %d' % (str(shape[1][0]), len(shape[1]))
print('%s%-10s %-10s %-4s %-15s %-20s' %(
letter[0], shape[0], letter[1], len(shape[1]), s, broadcastable_str
)) ))
print(hdr) print(hdr)
...@@ -175,13 +175,13 @@ by :ref:`broadcasting <libdoc_tensor_broadcastable>`. ...@@ -175,13 +175,13 @@ by :ref:`broadcasting <libdoc_tensor_broadcastable>`.
The following types are available: The following types are available:
* **byte**: ``bscalar, bvector, bmatrix, brow, bcol, btensor3, btensor4, btensor5`` * **byte**: ``bscalar, bvector, bmatrix, brow, bcol, btensor3, btensor4, btensor5, btensor6, btensor7``
* **16-bit integers**: ``wscalar, wvector, wmatrix, wrow, wcol, wtensor3, wtensor4, wtensor5`` * **16-bit integers**: ``wscalar, wvector, wmatrix, wrow, wcol, wtensor3, wtensor4, wtensor5, wtensor6, wtensor7``
* **32-bit integers**: ``iscalar, ivector, imatrix, irow, icol, itensor3, itensor4, itensor5`` * **32-bit integers**: ``iscalar, ivector, imatrix, irow, icol, itensor3, itensor4, itensor5, itensor6, itensor7``
* **64-bit integers**: ``lscalar, lvector, lmatrix, lrow, lcol, ltensor3, ltensor4, ltensor5`` * **64-bit integers**: ``lscalar, lvector, lmatrix, lrow, lcol, ltensor3, ltensor4, ltensor5, ltensor6, ltensor7``
* **float**: ``fscalar, fvector, fmatrix, frow, fcol, ftensor3, ftensor4, ftensor5`` * **float**: ``fscalar, fvector, fmatrix, frow, fcol, ftensor3, ftensor4, ftensor5, ftensor6, ftensor7``
* **double**: ``dscalar, dvector, dmatrix, drow, dcol, dtensor3, dtensor4, dtensor5`` * **double**: ``dscalar, dvector, dmatrix, drow, dcol, dtensor3, dtensor4, dtensor5, dtensor6, dtensor7``
* **complex**: ``cscalar, cvector, cmatrix, crow, ccol, ctensor3, ctensor4, ctensor5`` * **complex**: ``cscalar, cvector, cmatrix, crow, ccol, ctensor3, ctensor4, ctensor5, ctensor6, ctensor7``
The previous list is not exhaustive and a guide to all types compatible The previous list is not exhaustive and a guide to all types compatible
with NumPy arrays may be found here: :ref:`tensor creation<libdoc_tensor_creation>`. with NumPy arrays may be found here: :ref:`tensor creation<libdoc_tensor_creation>`.
......
...@@ -1566,10 +1566,8 @@ def test_dnn_batchnorm_train(): ...@@ -1566,10 +1566,8 @@ def test_dnn_batchnorm_train():
raise SkipTest(dnn.dnn_available.msg) raise SkipTest(dnn.dnn_available.msg)
utt.seed_rng() utt.seed_rng()
tensor6 = T.TensorType(theano.config.floatX, (False,) * 6)
for mode in ('per-activation', 'spatial'): for mode in ('per-activation', 'spatial'):
for vartype in (tensor6, T.tensor5, T.tensor4, T.tensor3, T.matrix, T.vector): for vartype in (T.tensor6, T.tensor5, T.tensor4, T.tensor3, T.matrix, T.vector):
x, scale, bias, running_mean, running_var = (vartype(n) x, scale, bias, running_mean, running_var = (vartype(n)
for n in ('x', 'scale', 'bias', for n in ('x', 'scale', 'bias',
'running_mean', 'running_mean',
...@@ -1804,10 +1802,8 @@ def test_batchnorm_inference(): ...@@ -1804,10 +1802,8 @@ def test_batchnorm_inference():
raise SkipTest(dnn.dnn_available.msg) raise SkipTest(dnn.dnn_available.msg)
utt.seed_rng() utt.seed_rng()
tensor6 = T.TensorType(theano.config.floatX, (False,) * 6)
for mode in ('per-activation', 'spatial'): for mode in ('per-activation', 'spatial'):
for vartype in (tensor6, T.tensor5, T.tensor4, T.tensor3, T.matrix, T.vector): for vartype in (T.tensor6, T.tensor5, T.tensor4, T.tensor3, T.matrix, T.vector):
x, scale, bias, mean, var = (vartype(n) x, scale, bias, mean, var = (vartype(n)
for n in ('x', 'scale', 'bias', 'mean', 'var')) for n in ('x', 'scale', 'bias', 'mean', 'var'))
ndim = x.ndim ndim = x.ndim
......
...@@ -901,6 +901,62 @@ def tensor5(name=None, dtype=None): ...@@ -901,6 +901,62 @@ def tensor5(name=None, dtype=None):
tensor5s, ftensor5s, dtensor5s, itensor5s, ltensor5s = _multi( tensor5s, ftensor5s, dtensor5s, itensor5s, ltensor5s = _multi(
tensor5, ftensor5, dtensor5, itensor5, ltensor5) tensor5, ftensor5, dtensor5, itensor5, ltensor5)
ctensor6 = TensorType('complex64', ((False,) * 6))
ztensor6 = TensorType('complex128', ((False,) * 6))
ftensor6 = TensorType('float32', ((False,) * 6))
dtensor6 = TensorType('float64', ((False,) * 6))
btensor6 = TensorType('int8', ((False,) * 6))
wtensor6 = TensorType('int16', ((False,) * 6))
itensor6 = TensorType('int32', ((False,) * 6))
ltensor6 = TensorType('int64', ((False,) * 6))
def tensor6(name=None, dtype=None):
"""Return a symbolic 6-D variable.
Parameters
----------
dtype: numeric type
None means to use theano.config.floatX.
name
A name to attach to this variable.
"""
if dtype is None:
dtype = config.floatX
type = TensorType(dtype, (False,) * 6)
return type(name)
tensor6s, ftensor6s, dtensor6s, itensor6s, ltensor6s = _multi(
tensor6, ftensor6, dtensor6, itensor6, ltensor6)
ctensor7 = TensorType('complex64', ((False,) * 7))
ztensor7 = TensorType('complex128', ((False,) * 7))
ftensor7 = TensorType('float32', ((False,) * 7))
dtensor7 = TensorType('float64', ((False,) * 7))
btensor7 = TensorType('int8', ((False,) * 7))
wtensor7 = TensorType('int16', ((False,) * 7))
itensor7 = TensorType('int32', ((False,) * 7))
ltensor7 = TensorType('int64', ((False,) * 7))
def tensor7(name=None, dtype=None):
"""Return a symbolic 7-D variable.
Parameters
----------
dtype: numeric type
None means to use theano.config.floatX.
name
A name to attach to this variable.
"""
if dtype is None:
dtype = config.floatX
type = TensorType(dtype, (False,) * 7)
return type(name)
tensor7s, ftensor7s, dtensor7s, itensor7s, ltensor7s = _multi(
tensor7, ftensor7, dtensor7, itensor7, ltensor7)
Tensor = TensorType Tensor = TensorType
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论