提交 61b4d95c authored 作者: Gijs van Tulder's avatar Gijs van Tulder

Add tensor6 and tensor7 (and typed variants).

上级 4747cf44
...@@ -18,17 +18,19 @@ shapes = [ ...@@ -18,17 +18,19 @@ 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' %( print('%s%-10s %-10s %-4s %-15s %-20s' %(
letter[0], shape[0], letter[1], len(shape[1]), s, shape[1] letter[0], shape[0], letter[1], len(shape[1]), s, shape[1]
)) ))
print(hdr) print(hdr)
...@@ -89,6 +89,14 @@ floating-point precision. ...@@ -89,6 +89,14 @@ floating-point precision.
Return a Variable for a 5-dimensional ndarray Return a Variable for a 5-dimensional ndarray
.. function:: tensor6(name=None, dtype=config.floatX)
Return a Variable for a 6-dimensional ndarray
.. function:: tensor7(name=None, dtype=config.floatX)
Return a Variable for a 7-dimensional ndarray
.. #COMMENT .. #COMMENT
Each of the types described above can be constructed by two methods: Each of the types described above can be constructed by two methods:
a singular version (e.g., :ref:`dmatrix <libdoc_tensor_creation>`) a singular version (e.g., :ref:`dmatrix <libdoc_tensor_creation>`)
...@@ -116,74 +124,90 @@ They are all callable, and accept an optional ``name`` argument. So for example ...@@ -116,74 +124,90 @@ They are all callable, and accept an optional ``name`` argument. So for example
table generated by table generated by
$ python Theano/doc/generate_dtype_tensor_table.py $ python Theano/doc/generate_dtype_tensor_table.py
============ =========== ==== ============ =================================== ============ =========== ==== ================ =================================================
Constructor dtype ndim shape broadcastable Constructor dtype ndim shape broadcastable
============ =========== ==== ============ =================================== ============ =========== ==== ================ =================================================
bscalar int8 0 () () bscalar int8 0 () ()
bvector int8 1 (?,) (False,) bvector int8 1 (?,) (False,)
brow int8 2 (1,?) (True, False) brow int8 2 (1,?) (True, False)
bcol int8 2 (?,1) (False, True) bcol int8 2 (?,1) (False, True)
bmatrix int8 2 (?,?) (False, False) bmatrix int8 2 (?,?) (False, False)
btensor3 int8 3 (?,?,?) (False, False, False) btensor3 int8 3 (?,?,?) (False, False, False)
btensor4 int8 4 (?,?,?,?) (False, False, False, False) btensor4 int8 4 (?,?,?,?) (False, False, False, False)
btensor5 int8 5 (?,?,?,?,?) (False, False, False, False, False) btensor5 int8 5 (?,?,?,?,?) (False, False, False, False, False)
wscalar int16 0 () () btensor6 int8 6 (?,?,?,?,?,?) (False, False, False, False, False, False)
wvector int16 1 (?,) (False,) btensor7 int8 7 (?,?,?,?,?,?,?) (False, False, False, False, False, False, False)
wrow int16 2 (1,?) (True, False) wscalar int16 0 () ()
wcol int16 2 (?,1) (False, True) wvector int16 1 (?,) (False,)
wmatrix int16 2 (?,?) (False, False) wrow int16 2 (1,?) (True, False)
wtensor3 int16 3 (?,?,?) (False, False, False) wcol int16 2 (?,1) (False, True)
wtensor4 int16 4 (?,?,?,?) (False, False, False, False) wmatrix int16 2 (?,?) (False, False)
wtensor5 int16 5 (?,?,?,?,?) (False, False, False, False, False) wtensor3 int16 3 (?,?,?) (False, False, False)
iscalar int32 0 () () wtensor4 int16 4 (?,?,?,?) (False, False, False, False)
ivector int32 1 (?,) (False,) wtensor5 int16 5 (?,?,?,?,?) (False, False, False, False, False)
irow int32 2 (1,?) (True, False) wtensor6 int16 6 (?,?,?,?,?,?) (False, False, False, False, False, False)
icol int32 2 (?,1) (False, True) wtensor7 int16 7 (?,?,?,?,?,?,?) (False, False, False, False, False, False, False)
imatrix int32 2 (?,?) (False, False) iscalar int32 0 () ()
itensor3 int32 3 (?,?,?) (False, False, False) ivector int32 1 (?,) (False,)
itensor4 int32 4 (?,?,?,?) (False, False, False, False) irow int32 2 (1,?) (True, False)
itensor5 int32 5 (?,?,?,?,?) (False, False, False, False, False) icol int32 2 (?,1) (False, True)
lscalar int64 0 () () imatrix int32 2 (?,?) (False, False)
lvector int64 1 (?,) (False,) itensor3 int32 3 (?,?,?) (False, False, False)
lrow int64 2 (1,?) (True, False) itensor4 int32 4 (?,?,?,?) (False, False, False, False)
lcol int64 2 (?,1) (False, True) itensor5 int32 5 (?,?,?,?,?) (False, False, False, False, False)
lmatrix int64 2 (?,?) (False, False) itensor6 int32 6 (?,?,?,?,?,?) (False, False, False, False, False, False)
ltensor3 int64 3 (?,?,?) (False, False, False) itensor7 int32 7 (?,?,?,?,?,?,?) (False, False, False, False, False, False, False)
ltensor4 int64 4 (?,?,?,?) (False, False, False, False) lscalar int64 0 () ()
ltensor5 int64 5 (?,?,?,?,?) (False, False, False, False, False) lvector int64 1 (?,) (False,)
dscalar float64 0 () () lrow int64 2 (1,?) (True, False)
dvector float64 1 (?,) (False,) lcol int64 2 (?,1) (False, True)
drow float64 2 (1,?) (True, False) lmatrix int64 2 (?,?) (False, False)
dcol float64 2 (?,1) (False, True) ltensor3 int64 3 (?,?,?) (False, False, False)
dmatrix float64 2 (?,?) (False, False) ltensor4 int64 4 (?,?,?,?) (False, False, False, False)
dtensor3 float64 3 (?,?,?) (False, False, False) ltensor5 int64 5 (?,?,?,?,?) (False, False, False, False, False)
dtensor4 float64 4 (?,?,?,?) (False, False, False, False) ltensor6 int64 6 (?,?,?,?,?,?) (False, False, False, False, False, False)
dtensor5 float64 5 (?,?,?,?,?) (False, False, False, False, False) ltensor7 int64 7 (?,?,?,?,?,?,?) (False, False, False, False, False, False, False)
fscalar float32 0 () () dscalar float64 0 () ()
fvector float32 1 (?,) (False,) dvector float64 1 (?,) (False,)
frow float32 2 (1,?) (True, False) drow float64 2 (1,?) (True, False)
fcol float32 2 (?,1) (False, True) dcol float64 2 (?,1) (False, True)
fmatrix float32 2 (?,?) (False, False) dmatrix float64 2 (?,?) (False, False)
ftensor3 float32 3 (?,?,?) (False, False, False) dtensor3 float64 3 (?,?,?) (False, False, False)
ftensor4 float32 4 (?,?,?,?) (False, False, False, False) dtensor4 float64 4 (?,?,?,?) (False, False, False, False)
ftensor5 float32 5 (?,?,?,?,?) (False, False, False, False, False) dtensor5 float64 5 (?,?,?,?,?) (False, False, False, False, False)
cscalar complex64 0 () () dtensor6 float64 6 (?,?,?,?,?,?) (False, False, False, False, False, False)
cvector complex64 1 (?,) (False,) dtensor7 float64 7 (?,?,?,?,?,?,?) (False, False, False, False, False, False, False)
crow complex64 2 (1,?) (True, False) fscalar float32 0 () ()
ccol complex64 2 (?,1) (False, True) fvector float32 1 (?,) (False,)
cmatrix complex64 2 (?,?) (False, False) frow float32 2 (1,?) (True, False)
ctensor3 complex64 3 (?,?,?) (False, False, False) fcol float32 2 (?,1) (False, True)
ctensor4 complex64 4 (?,?,?,?) (False, False, False, False) fmatrix float32 2 (?,?) (False, False)
ctensor5 complex64 5 (?,?,?,?,?) (False, False, False, False, False) ftensor3 float32 3 (?,?,?) (False, False, False)
zscalar complex128 0 () () ftensor4 float32 4 (?,?,?,?) (False, False, False, False)
zvector complex128 1 (?,) (False,) ftensor5 float32 5 (?,?,?,?,?) (False, False, False, False, False)
zrow complex128 2 (1,?) (True, False) ftensor6 float32 6 (?,?,?,?,?,?) (False, False, False, False, False, False)
zcol complex128 2 (?,1) (False, True) ftensor7 float32 7 (?,?,?,?,?,?,?) (False, False, False, False, False, False, False)
zmatrix complex128 2 (?,?) (False, False) cscalar complex64 0 () ()
ztensor3 complex128 3 (?,?,?) (False, False, False) cvector complex64 1 (?,) (False,)
ztensor4 complex128 4 (?,?,?,?) (False, False, False, False) crow complex64 2 (1,?) (True, False)
ztensor5 complex128 5 (?,?,?,?,?) (False, False, False, False, False) ccol complex64 2 (?,1) (False, True)
============ =========== ==== ============ =================================== cmatrix complex64 2 (?,?) (False, False)
ctensor3 complex64 3 (?,?,?) (False, False, False)
ctensor4 complex64 4 (?,?,?,?) (False, False, False, False)
ctensor5 complex64 5 (?,?,?,?,?) (False, False, False, False, False)
ctensor6 complex64 6 (?,?,?,?,?,?) (False, False, False, False, False, False)
ctensor7 complex64 7 (?,?,?,?,?,?,?) (False, False, False, False, False, False, False)
zscalar complex128 0 () ()
zvector complex128 1 (?,) (False,)
zrow complex128 2 (1,?) (True, False)
zcol complex128 2 (?,1) (False, True)
zmatrix complex128 2 (?,?) (False, False)
ztensor3 complex128 3 (?,?,?) (False, False, False)
ztensor4 complex128 4 (?,?,?,?) (False, False, False, False)
ztensor5 complex128 5 (?,?,?,?,?) (False, False, False, False, False)
ztensor6 complex128 6 (?,?,?,?,?,?) (False, False, False, False, False, False)
ztensor7 complex128 7 (?,?,?,?,?,?,?) (False, False, False, False, False, False, False)
============ =========== ==== ================ =================================================
Plural Constructors Plural Constructors
-------------------------- --------------------------
...@@ -232,11 +256,11 @@ If you would like to construct a tensor variable with a non-standard ...@@ -232,11 +256,11 @@ If you would like to construct a tensor variable with a non-standard
broadcasting pattern, or a larger number of dimensions you'll need to create broadcasting pattern, or a larger number of dimensions you'll need to create
your own :class:`TensorType` instance. You create such an instance by passing your own :class:`TensorType` instance. You create such an instance by passing
the dtype and broadcasting pattern to the constructor. For example, you the dtype and broadcasting pattern to the constructor. For example, you
can create your own 6-dimensional tensor type can create your own 8-dimensional tensor type
>>> dtensor6 = TensorType('float64', (False,)*6) >>> dtensor8 = TensorType('float64', (False,)*8)
>>> x = dtensor6() >>> x = dtensor8()
>>> z = dtensor6('z') >>> z = dtensor8('z')
You can also redefine some of the provided types and they will interact You can also redefine some of the provided types and they will interact
correctly: correctly:
......
...@@ -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>`.
......
...@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论