提交 7b50faa0 authored 作者: James Bergstra's avatar James Bergstra

disabling floatX.py. using config.floatX to adjust the dtype default in tensor.matrix,vector,etc.

上级 ac95733a
......@@ -65,8 +65,6 @@ import scalar
import sparse
import gradient
import gof
import floatX
floatX.set_floatX()
if config.device.startswith('gpu'):
import theano.sandbox.cuda
......
"""Provide xscalar, xvector, xmatrix, etc. pseudo-types
"""
from .configparser import config
from theano.scalar import float64, float32
from theano.tensor import (fscalar, fvector, fmatrix, frow, fcol, ftensor3, ftensor4, dscalar,
dvector, dmatrix, drow, dcol, dtensor3, dtensor4)
#
# !!! set_floatX adds symbols directly to the module's symbol table !!!
#
def set_floatX(dtype = config.floatX):
""" add the xmatrix, xvector, xscalar etc. aliases to theano.tensor
"""
config.floatX = dtype
if dtype == 'float32': prefix = 'f'
elif dtype == 'float64' : prefix = 'd'
else: raise Exception("Bad param in set_floatX(%s). Only float32 and float64 are supported"%config.floatX)
#tensor.scalar stuff
globals()['floatX'] = globals()[dtype]
# convert_to_floatX = Cast(floatX, name='convert_to_floatX')
#tensor.tensor stuff
for symbol in ('scalar', 'vector', 'matrix', 'row', 'col','tensor3','tensor4'):
globals()['x'+symbol] = globals()[prefix+symbol]
#_convert_to_floatX = _conversion(elemwise.Elemwise(scal.convert_to_floatX), 'floatX')
if 0:
from .configparser import config
from theano.scalar import float64, float32
from theano.tensor import (fscalar, fvector, fmatrix, frow, fcol, ftensor3, ftensor4, dscalar,
dvector, dmatrix, drow, dcol, dtensor3, dtensor4)
#
# !!! set_floatX adds symbols directly to the module's symbol table !!!
#
def set_floatX(dtype = config.floatX):
""" add the xmatrix, xvector, xscalar etc. aliases to theano.tensor
"""
config.floatX = dtype
if dtype == 'float32': prefix = 'f'
elif dtype == 'float64' : prefix = 'd'
else: raise Exception("Bad param in set_floatX(%s). Only float32 and float64 are supported"%config.floatX)
#tensor.scalar stuff
globals()['floatX'] = globals()[dtype]
# convert_to_floatX = Cast(floatX, name='convert_to_floatX')
#tensor.tensor stuff
for symbol in ('scalar', 'vector', 'matrix', 'row', 'col','tensor3','tensor4'):
globals()['x'+symbol] = globals()[prefix+symbol]
#_convert_to_floatX = _conversion(elemwise.Elemwise(scal.convert_to_floatX), 'floatX')
......
......@@ -657,7 +657,13 @@ bscalar = TensorType('int8', ())
wscalar = TensorType('int16', ())
iscalar = TensorType('int32', ())
lscalar = TensorType('int64', ())
def scalar(name = None, dtype = 'float64'):
def scalar(name = None, dtype = None):
"""Return a symbolic scalar variable.
:param dtype: numeric type (None means to use theano.config.floatX)
:param name: a name to attach to this variable
"""
if dtype is None:
dtype = config.floatX
type = TensorType(dtype, ())
return type(name)
scalars, fscalars, dscalars, iscalars, lscalars = _multi(scalar, fscalar, dscalar, iscalar, lscalar)
......@@ -677,7 +683,13 @@ bvector = TensorType('int8', (False,))
wvector = TensorType('int16', (False,))
ivector = TensorType('int32', (False, ))
lvector = TensorType('int64', (False, ))
def vector(name = None, dtype = 'float64'):
def vector(name = None, dtype = None):
"""Return a symbolic vector variable.
:param dtype: numeric type (None means to use theano.config.floatX)
:param name: a name to attach to this variable
"""
if dtype is None:
dtype = config.floatX
type = TensorType(dtype, (False, ))
return type(name)
vectors, fvectors, dvectors, ivectors, lvectors = _multi(vector, fvector, dvector, ivector, lvector)
......@@ -694,7 +706,13 @@ bmatrix = TensorType('int8', (False, False))
wmatrix = TensorType('int16', (False, False))
imatrix = TensorType('int32', (False, False))
lmatrix = TensorType('int64', (False, False))
def matrix(name = None, dtype = 'float64'):
def matrix(name = None, dtype = None):
"""Return a symbolic matrix variable.
:param dtype: numeric type (None means to use theano.config.floatX)
:param name: a name to attach to this variable
"""
if dtype is None:
dtype = config.floatX
type = TensorType(dtype, (False, False))
return type(name)
matrices, fmatrices, dmatrices, imatrices, lmatrices = _multi(matrix, fmatrix, dmatrix, imatrix, lmatrix)
......@@ -711,7 +729,13 @@ brow = TensorType('int8', (True, False))
wrow = TensorType('int16', (True, False))
irow = TensorType('int32', (True, False))
lrow = TensorType('int64', (True, False))
def row(name = None, dtype = 'float64'):
def row(name = None, dtype = None):
"""Return a symbolic row variable (ndim=2, broadcastable=[True,False]).
:param dtype: numeric type (None means to use theano.config.floatX)
:param name: a name to attach to this variable
"""
if dtype is None:
dtype = config.floatX
type = TensorType(dtype, (True, False))
return type(name)
rows, frows, drows, irows, lrows = _multi(row, frow, drow, irow, lrow)
......@@ -724,7 +748,13 @@ bcol = TensorType('int8', (False, True))
wcol = TensorType('int16', (False, True))
icol = TensorType('int32', (False, True))
lcol = TensorType('int64', (False, True))
def col(name = None, dtype = 'float64'):
def col(name = None, dtype = None):
"""Return a symbolic column variable (ndim=2, broadcastable=[False,True]).
:param dtype: numeric type (None means to use theano.config.floatX)
:param name: a name to attach to this variable
"""
if dtype is None:
dtype = config.floatX
type = TensorType(dtype, (False, True))
return type(name)
cols, fcols, dcols, icols, lcols = _multi(col, fcol, dcol, icol, lcol)
......@@ -737,7 +767,13 @@ btensor3 = TensorType('int8', (False,)*3)
wtensor3 = TensorType('int16', (False,)*3)
itensor3 = TensorType('int32', (False,)*3)
ltensor3 = TensorType('int64', (False,)*3)
def tensor3(name=None, dtype='float64'):
def tensor3(name=None, dtype=None):
"""Return a symbolic 3-D variable.
:param dtype: numeric type (None means to use theano.config.floatX)
:param name: a name to attach to this variable
"""
if dtype is None:
dtype = config.floatX
type = TensorType(dtype, (False, False, False))
return type(name)
tensor3s, ftensor3s, dtensor3s, itensor3s, ltensor3s = _multi(tensor3, ftensor3, dtensor3,
......@@ -751,7 +787,13 @@ btensor4 = TensorType('int8', (False,)*4)
wtensor4 = TensorType('int16', (False,)*4)
itensor4 = TensorType('int32', (False,)*4)
ltensor4 = TensorType('int64', (False,)*4)
def tensor4(name=None, dtype='float64'):
def tensor4(name=None, dtype=None):
"""Return a symbolic 4-D variable.
:param dtype: numeric type (None means to use theano.config.floatX)
:param name: a name to attach to this variable
"""
if dtype is None:
dtype = config.floatX
type = TensorType(dtype, (False, False, False, False))
return type(name)
tensor4s, ftensor4s, dtensor4s, itensor4s, ltensor4s = _multi(tensor4, ftensor4, dtensor4,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论