提交 5a41b7fa authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Merged

...@@ -14,8 +14,7 @@ Requirements ...@@ -14,8 +14,7 @@ Requirements
------------ ------------
In order to use Theano, the following libraries and software will need In order to use Theano, the following libraries and software will need
to be installed (MacOS and Windows users should refer to platform-specific to be installed:
instructions below for detailed installation steps):
Linux, Mac OS X or Windows operating system Linux, Mac OS X or Windows operating system
We develop mainly on 64-bit Linux machines. 32-bit architectures are We develop mainly on 64-bit Linux machines. 32-bit architectures are
...@@ -395,7 +394,7 @@ Windows V1 (Installing from Scratch) ...@@ -395,7 +394,7 @@ Windows V1 (Installing from Scratch)
You can keep the default install options (except for the installation directory). You can keep the default install options (except for the installation directory).
- Install Mercurial. You can download it - Install Mercurial. You can download it
`here <http://mercurial.selenic.com/downloads>`_. You may get either the command `here <http://mercurial.selenic.com/downloads>`__. You may get either the command
line Windows version or the TortoiseHG GUI version: it does not matter as line Windows version or the TortoiseHG GUI version: it does not matter as
far as installing Theano is concerned. far as installing Theano is concerned.
...@@ -451,7 +450,7 @@ compile GotoBLAS2 (ATLAS may work too, but was not tested, and is ...@@ -451,7 +450,7 @@ compile GotoBLAS2 (ATLAS may work too, but was not tested, and is
usually reported to be slower and more difficult to compile -- especially usually reported to be slower and more difficult to compile -- especially
on Windows). on Windows).
GotoBLAS2 can be downloaded GotoBLAS2 can be downloaded
`here <http://www.tacc.utexas.edu/tacc-projects/gotoblas2/downloads>`_ `here <http://www.tacc.utexas.edu/tacc-projects/gotoblas2/downloads>`__
after registering on the website (we tested v1.13). after registering on the website (we tested v1.13).
To compile it, you will also need to install MSYS and Perl, To compile it, you will also need to install MSYS and Perl,
as described below. as described below.
...@@ -539,8 +538,7 @@ Windows: Using the GPU ...@@ -539,8 +538,7 @@ Windows: Using the GPU
Please note that these are tentative instructions (we have not yet been able to Please note that these are tentative instructions (we have not yet been able to
get the GPU to work under Windows with Theano). get the GPU to work under Windows with Theano).
Please report your own successes / failures on the Please report your own successes / failures on the `theano-users`_ mailing list.
`theano-users <http://groups.google.com/group/theano-users>`_ mailing list.
Those are instructions for the 32-bit version of Python (the one that comes Those are instructions for the 32-bit version of Python (the one that comes
with Python(x,y) is 32-bit). with Python(x,y) is 32-bit).
...@@ -562,7 +560,7 @@ is the correct Python installation path): ...@@ -562,7 +560,7 @@ is the correct Python installation path):
.. code-block:: cfg .. code-block:: cfg
[cuda] [cuda]
nvccflags=-LC:\Python27\libs nvccflags=-LC:\Python26\libs
Then Then
...@@ -606,25 +604,83 @@ It could probably also run with `Cygwin <http://www.cygwin.com/>`__, ...@@ -606,25 +604,83 @@ It could probably also run with `Cygwin <http://www.cygwin.com/>`__,
but this has not been tested yet. but this has not been tested yet.
- From `the MinGW files <http://sourceforge.net/projects/mingw/files/>`__, - From `the MinGW files <http://sourceforge.net/projects/mingw/files/>`__,
download the latest version of the ``Automated MinGW Installer`` download the latest version of the ``Automated MinGW Installer`` and install
(``mingw-get-inst``) and install it with all optional components (although it (keeping default options).
you probably do not need them all: if you feel like figuring out exactly
which ones are required, let us know!). - From `the MinGW files <http://sourceforge.net/projects/mingw/files/>`__,
download the latest ``MSYS Base System`` executable file and run it
(note that the latest version of MSYS Base System may not contain an
executable file, in which case it is easier to just use an
older version, e.g. MSYS-1.0.11.exe).
This will install MSYS (you can keep the default install options).
It will also run a post-install script where it will ask you about the
location of MinGW (typically ``c:/MinGW``).
- From `the MinGW files <http://sourceforge.net/projects/mingw/files/>`__,
download the current version of ``GCC Version 4`` (full package with
binaries, e.g.
gcc-full-4.4.0-mingw32-bin-2.tar.lzma). Unpack it (you may use
`7-Zip <http://www.7-zip.org>`__ to unpack files with the
.lzma extension), copying the content into the root directory
of your MinGW installation (if you obtain a .tar file, make
sure you expand it as well, either with `7-Zip <http://www.7-zip.org>`__
or through the ``tar`` command on the MSYS command line).
- If you are familiar with vi, you may find useful to download and install
``MSYS vim`` (this is done in a similar way to GCC 4).
This is strictly optional and mostly helpful to edit configuration files
from within MSYS.
- Run MSYS (Start/Programs/MinGW/MSYS/MSYS) and check the installation
by verifying that the proper version of GCC is found:
.. code-block:: bash
gcc --version
You may also decide to change the location of your home directory by
adding a line at the beginning of msys.bat, that would look like
``set HOME=C:\My\Home\For\MinGW`` (you can also set a global ``HOME``
environment variable within Windows, but this could affect more programs).
- If you do not have them already, install the latest versions of - If you do not have them already, install the latest versions of
`Python 2.x <http://www.python.org/download/windows>`__ and `Python 2.x <http://www.python.org/download/windows>`__ and
corresponding `NumPy <http://sourceforge.net/projects/numpy/files/>`__ corresponding `NumPy <http://sourceforge.net/projects/numpy/files/>`__
then `SciPy <http://sourceforge.net/projects/scipy/files/>`__ then `SciPy <http://sourceforge.net/projects/scipy/files/>`__
packages (simply use the executable installers). Note that we experienced packages (simply use the executable installers).
issues with the 64 bit version of Python, and thus recommend using the 32 bit
version instead (if you managed to get Theano to work with 64 bit Python under - Ensure that the Python installation directory and its ``Scripts`` sub-directory
Windows, please let us know!). are in your system path. This may be done by
modifying the global ``PATH`` Windows environment variables, or by creating a ``.profile`` file in
your MinGW home, containing the line
``export PATH=$PATH:/c/Python26:/c/Python26/Scripts``
(for Python 2.6).
- Install a ``BLAS`` library. Note that although the following instructions
will give you a generic way to build your own library, there may exist
better (more optimized) versions of BLAS available for your system, but
these have not been tested for Windows at this time.
To build BLAS, download the latest version of `LAPACK <http://www.netlib.org/lapack/>`__
(typically lapack.tgz), then issue the following commands in MSYS
(for LAPACK 3.2.1):
.. code-block:: bash
tar zxvf lapack.tgz
cd lapack-3.2.1
gfortran -shared -O3 -o libblas.dll BLAS/SRC/*.f
cp libblas.dll /mingw/lib
mv libblas.dll /mingw/bin
- Edit (or create) your ``$HOME/.theanorc`` and add the following section:
.. code-block:: cfg
[blas]
ldflags = -lblas
- Ensure that the Python installation directory and its ``Scripts`` - Install `Mercurial <http://mercurial.selenic.com/downloads/>`__
sub-directory are in your system path. This may be done by (you can use the regular Windows release, you do not need TortoiseHg).
modifying the global ``PATH`` Windows environment variables, or by creating
a ``.profile`` file in your MinGW home, containing a line like
``export PATH=$PATH:/c/Python27:/c/Python27/Scripts``.
- In order to run Theano's test-suite, you will need `nose - In order to run Theano's test-suite, you will need `nose
<http://somethingaboutorange.com/mrl/projects/nose>`__. <http://somethingaboutorange.com/mrl/projects/nose>`__.
...@@ -635,15 +691,17 @@ but this has not been tested yet. ...@@ -635,15 +691,17 @@ but this has not been tested yet.
python setup.py install python setup.py install
- Install Theano using the above :ref:`install_bleeding_edge` installation - Install Theano using the above :ref:`install_bleeding_edge` installation instructions
instructions (using ``easy_install`` will require additional packages and has not been
(using ``easy_install`` and has not been tested yet). tested yet, while the latest official Theano release is also untested at this
time).
In particular, do not forget to make the Theano package accessible from In particular, do not forget to make the Theano package accessible from
Python, e.g. by adding to your ``.profile`` a line like Python, e.g. by adding to your ``.profile`` a line like
``export PYTHONPATH=PYTHONPATH:$HOME/Theano``. ``export PYTHONPATH=PYTHONPATH:$HOME/Theano``.
- Please note that at this time, the test suite may be broken under Windows. - Please note that at this time, some tests (launched using ``nosetests``) are
In particular, many tests may fail while running the test-suite, still failing under Windows: we are working on fixing them.
It may also happen that many tests may fail while running the test-suite,
due to insufficient memory resources (in which case you will probably get an due to insufficient memory resources (in which case you will probably get an
error of the type ``"Not enough storage is available to error of the type ``"Not enough storage is available to
process this command"``): one workaround is to run nosetests process this command"``): one workaround is to run nosetests
......
...@@ -33,6 +33,9 @@ def _info(*msg): ...@@ -33,6 +33,9 @@ def _info(*msg):
def _warn(*msg): def _warn(*msg):
_logger.warn(' '.join(msg)) _logger.warn(' '.join(msg))
#This is needed as we will hide it later
python_complex=complex
def check_equal_numpy(x, y): def check_equal_numpy(x, y):
""" """
Returns True iff x and y are equal (checks the dtype and Returns True iff x and y are equal (checks the dtype and
...@@ -388,6 +391,20 @@ def get_constant_value(v): ...@@ -388,6 +391,20 @@ def get_constant_value(v):
ret = get_constant_value(ret) ret = get_constant_value(ret)
#join can cast implicitly its input in some case. #join can cast implicitly its input in some case.
return theano._asarray(ret, dtype=v.type.dtype) return theano._asarray(ret, dtype=v.type.dtype)
if (v.owner.inputs[0].owner and
isinstance(v.owner.inputs[0].owner.op,
theano.tensor.opt.MakeVector) and
# MakeVector normally accept only scalar as input.
# We put this check in case there is change in the future
all(var.ndim==0 for var in v.owner.inputs[0].owner.inputs)):
# The index list 'idx_list' should have length one
# since joining scalar variables results in a 1D vector.
assert len(v.owner.op.idx_list) == 1
ret = v.owner.inputs[0].owner.inputs[v.owner.op.idx_list[0]]
ret = get_constant_value(ret)
#MakeVector can cast implicitly its input in some case.
return theano._asarray(ret, dtype=v.type.dtype)
raise TypeError(v) raise TypeError(v)
...@@ -1505,7 +1522,7 @@ class SpecifyShape(Op): ...@@ -1505,7 +1522,7 @@ class SpecifyShape(Op):
L{Op} put into the graph the user provided shape L{Op} put into the graph the user provided shape
In the case where this op stay in the final graph, we assert the shape. In the case where this op stay in the final graph, we assert the shape.
For this the output of this op must be used in the graph. This is not For this the output of this op must be used in the graph. This is not
the case most of the time if we only take the shape of the output. the case most of the time if we only take the shape of the output.
Maybe there is other optimization that will mess with this. Maybe there is other optimization that will mess with this.
...@@ -1524,12 +1541,12 @@ class SpecifyShape(Op): ...@@ -1524,12 +1541,12 @@ class SpecifyShape(Op):
x = as_tensor_variable(x) x = as_tensor_variable(x)
shape = as_tensor_variable(shape) shape = as_tensor_variable(shape)
return Apply(self, [x, shape], [x.type()]) return Apply(self, [x, shape], [x.type()])
def perform(self, node, (x,shape ), (out, )): def perform(self, node, (x,shape ), (out, )):
assert numpy.all(x.shape==shape), ("got shape", x.shape, assert numpy.all(x.shape==shape), ("got shape", x.shape,
"expected", shape) "expected", shape)
out[0] = x out[0] = x
def infer_shape(self, node, (xshape, sshape)): def infer_shape(self, node, (xshape, sshape)):
new_shape=[] new_shape=[]
for dim in range(node.inputs[0].ndim): for dim in range(node.inputs[0].ndim):
...@@ -2276,7 +2293,7 @@ def std(input, axis=None): ...@@ -2276,7 +2293,7 @@ def std(input, axis=None):
:type axis: None or int or (list of int) (see `Sum`) :type axis: None or int or (list of int) (see `Sum`)
""" """
return sqrt(var(input=input, axis=axis)) return sqrt(var(input=input, axis=axis))
if 0: if 0:
## COMMENTED OUT FEB 17 2010 ## COMMENTED OUT FEB 17 2010
## TODO (DOCUMENT AND WRITE TESTS) OR DELETE ## TODO (DOCUMENT AND WRITE TESTS) OR DELETE
...@@ -3269,11 +3286,18 @@ def stack(*tensors): ...@@ -3269,11 +3286,18 @@ def stack(*tensors):
raise Exception('theano.tensor.stack(*tensors) must have at least one parameter') raise Exception('theano.tensor.stack(*tensors) must have at least one parameter')
# If all tensors are scalars of the same type, call make_vector. # If all tensors are scalars of the same type, call make_vector.
# It makes the graph simpler, by not adding DimShuffles and Rebroadcasts # It makes the graph simpler, by not adding DimShuffles and Rebroadcasts
if numpy.all([isinstance(t, Variable) and\ if isinstance(tensors[0], (numpy.number, float, int, python_complex)):
isinstance(t.type, TensorType) and\ tensors=list(tensors)
t.ndim==0 and t.type==tensors[0].type\ tensors[0]=as_tensor_variable(tensors[0])
if numpy.all([isinstance(t, (numpy.number, float, int, python_complex))#in case their is direct int
or (isinstance(t, Variable) and
isinstance(t.type, TensorType) and
t.ndim==0 and
t.type.__class__==tensors[0].type.__class__)
for t in tensors]): for t in tensors]):
return theano.tensor.opt.MakeVector(scal.upcast(*[i.dtype for i in tensors]))(*tensors) tensors = map(as_tensor_variable,tensors)#in case their is direct int
dtype = scal.upcast(*[i.dtype for i in tensors])
return theano.tensor.opt.MakeVector(dtype)(*tensors)
return join(0, *[shape_padleft(t, 1) for t in tensors]) return join(0, *[shape_padleft(t, 1) for t in tensors])
@constructor @constructor
......
...@@ -1552,6 +1552,36 @@ class T_Join_and_Split(unittest.TestCase): ...@@ -1552,6 +1552,36 @@ class T_Join_and_Split(unittest.TestCase):
assert len([n for n in e if isinstance(n, Join)]) == 0 assert len([n for n in e if isinstance(n, Join)]) == 0
assert f.maker.env.outputs[0].dtype == config.floatX assert f.maker.env.outputs[0].dtype == config.floatX
def test_stack_scalar_make_vector_dtype(self):
'''Test that calling stack() on scalars instantiates MakeVector,
event when the scalar don't have the same dtype.'''
a = tensor.iscalar('a')
b = tensor.lscalar('b')
s = stack(a, b, a, b)
f = function([a,b], s)
val = f(1,2)
self.failUnless(numpy.all(val == [1,2,1,2]))
e = f.maker.env.toposort()
assert len([n for n in e if isinstance(n.op,opt.MakeVector)]) > 0
assert len([n for n in e if isinstance(n, Join)]) == 0
assert f.maker.env.outputs[0].dtype == 'int64'
def test_stack_scalar_make_vector_constant(self):
'''Test that calling stack() on scalars instantiates MakeVector,
event when the scalar are simple int type.'''
a = tensor.iscalar('a')
b = tensor.lscalar('b')
#test when the constant is the first element.
#The first element is used in a special way
s = stack(10,a,b, numpy.int8(3))
f = function([a,b], s)
val = f(1,2)
self.failUnless(numpy.all(val == [10,1,2,3]))
e = f.maker.env.toposort()
assert len([n for n in e if isinstance(n.op,opt.MakeVector)]) > 0
assert len([n for n in e if isinstance(n, Join)]) == 0
assert f.maker.env.outputs[0].dtype == 'int64'
def test_join_vector(self): def test_join_vector(self):
a = as_tensor_variable(numpy.array([1, 2, 3])) a = as_tensor_variable(numpy.array([1, 2, 3]))
b = as_tensor_variable(numpy.array([7, 8, 9])) b = as_tensor_variable(numpy.array([7, 8, 9]))
...@@ -3440,6 +3470,28 @@ def test_dimshuffle_duplicate(): ...@@ -3440,6 +3470,28 @@ def test_dimshuffle_duplicate():
assert success assert success
class T_get_constant_value(unittest.TestCase):
def test_get_constant_value(self):
a = tensor.stack(1,2,3)
assert get_constant_value(a[0])==1
assert get_constant_value(a[1])==2
assert get_constant_value(a[2])==3
b = tensor.iscalar()
a = tensor.stack(b,2,3)
self.assertRaises(TypeError, get_constant_value, a[0])
assert get_constant_value(a[1])==2
assert get_constant_value(a[2])==3
#For now get_constant_value got throught only MakeVector and Join of scalar.
v = tensor.ivector()
a = tensor.stack(v,2,3)
self.assertRaises(TypeError, get_constant_value, a[0])
self.assertRaises(TypeError, get_constant_value, a[1])
self.assertRaises(TypeError, get_constant_value, a[2])
if __name__ == '__main__': if __name__ == '__main__':
if 1: if 1:
unittest.main() unittest.main()
...@@ -3449,5 +3501,3 @@ if __name__ == '__main__': ...@@ -3449,5 +3501,3 @@ if __name__ == '__main__':
suite = unittest.TestLoader() suite = unittest.TestLoader()
suite = suite.loadTestsFromTestCase(testcase) suite = suite.loadTestsFromTestCase(testcase)
unittest.TextTestRunner(verbosity=2).run(suite) unittest.TextTestRunner(verbosity=2).run(suite)
...@@ -316,20 +316,20 @@ def makeSharedTester(shared_constructor_, ...@@ -316,20 +316,20 @@ def makeSharedTester(shared_constructor_,
#Test that we forward the input #Test that we forward the input
specify_shape_fct = theano.function([],x1_specify_shape) specify_shape_fct = theano.function([],x1_specify_shape)
theano.printing.debugprint(specify_shape_fct) #theano.printing.debugprint(specify_shape_fct)
assert numpy.all(self.ref_fct(specify_shape_fct()) assert numpy.all(self.ref_fct(specify_shape_fct())
==self.ref_fct(x1_2)) ==self.ref_fct(x1_2))
topo_specify = specify_shape_fct.maker.env.toposort() topo_specify = specify_shape_fct.maker.env.toposort()
if theano.config.mode!='FAST_COMPILE': if theano.config.mode!='FAST_COMPILE':
assert len(topo_specify)==6 assert len(topo_specify)==4
#Test that we put the shape info into the graph #Test that we put the shape info into the graph
shape_constant_fct = theano.function([],x1_specify_shape.shape) shape_constant_fct = theano.function([],x1_specify_shape.shape)
theano.printing.debugprint(shape_constant_fct) #theano.printing.debugprint(shape_constant_fct)
assert numpy.all(shape_constant_fct()==shape_op_fct()) assert numpy.all(shape_constant_fct()==shape_op_fct())
topo_cst = shape_constant_fct.maker.env.toposort() topo_cst = shape_constant_fct.maker.env.toposort()
if theano.config.mode!='FAST_COMPILE': if theano.config.mode!='FAST_COMPILE':
assert len(topo_cst)==6 assert len(topo_cst)==2
#Test that we can replace with values of the different shape #Test that we can replace with values of the different shape
# but that will raise an error in some case, but not all # but that will raise an error in some case, but not all
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论