提交 1a18f3db authored 作者: nouiz's avatar nouiz

Merge pull request #1136 from delallea/minor

Minor fixes
......@@ -3,6 +3,25 @@ from theano.gof.python25 import any, defaultdict
## {{{ http://code.activestate.com/recipes/578231/ (r1)
# Copyright (c) Oren Tirosh 2012
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
def memodict(f):
""" Memoization decorator for a function taking a single argument """
class memodict(defaultdict):
......@@ -12,6 +31,7 @@ def memodict(f):
return memodict().__getitem__
## end of http://code.activestate.com/recipes/578231/ }}}
def make_depends():
@memodict
def depends((a, b)):
......
......@@ -375,11 +375,11 @@ def use(device,
import theano.sandbox.cuda.tests.test_driver
theano.sandbox.cuda.tests.test_driver.test_nvidia_driver1()
if device_properties(use.device_number)["warpSize"] != 32:
raise ValueError("Your GPU have a warpSize of 32. Currently"
" we have code that depend on this. Email"
" Theano mailing list to tell us about"
raise ValueError("Your GPU has a warpSize != 32. Currently"
" we have code that depends on this. Email"
" the Theano mailing list to tell us about"
" this new GPU as we don't know any with"
" this properties")
" this property")
if move_shared_float32_to_gpu:
handle_shared_float32(True)
......
......@@ -1443,7 +1443,7 @@ class _tensor_py_operators:
def __sub__(self, other):
# See explanation in __add__ for the error catched
# adn the return value in that case
# and the return value in that case
try:
return sub(self, other)
except (NotImplementedError, TypeError):
......@@ -1451,7 +1451,7 @@ class _tensor_py_operators:
def __mul__(self, other):
# See explanation in __add__ for the error catched
# adn the return value in that case
# and the return value in that case
try:
return mul(self, other)
except (NotImplementedError, TypeError):
......@@ -1459,7 +1459,7 @@ class _tensor_py_operators:
def __div__(self, other):
# See explanation in __add__ for the error catched
# adn the return value in that case
# and the return value in that case
try:
return div_proxy(self, other)
except IntegerDivisionError:
......@@ -6833,7 +6833,7 @@ def take(a, indices, axis=None, mode='raise'):
# Reuse advanced_subtensor1 if indices is a vector
if indices.ndim == 1:
if mode == 'clip':
indices = clip(indices, 0, a.shape[axis]-1)
indices = clip(indices, 0, a.shape[axis] - 1)
elif mode == 'wrap':
indices = indices % a.shape[axis]
if axis is None:
......@@ -6853,10 +6853,12 @@ def take(a, indices, axis=None, mode='raise'):
shape = indices.shape
ndim = indices.ndim
else:
shape = concatenate([a.shape[:axis], indices.shape, a.shape[axis+1:]])
shape = concatenate(
[a.shape[:axis], indices.shape, a.shape[axis + 1:]])
ndim = a.ndim + indices.ndim - 1
return take(a, indices.flatten(), axis, mode).reshape(shape, ndim)
#########################
# Linalg : Dot
#########################
......@@ -7283,6 +7285,7 @@ def all(x, axis=None, keepdims=False):
out = makeKeepDims(x, out, axis)
return out
class Diagonal(Op):
"""Return specified diagonals.
......@@ -7310,7 +7313,7 @@ class Diagonal(Op):
x = as_tensor_variable(x)
assert x.ndim >= 2
return Apply(self, [x], [tensor(dtype=x.dtype,
broadcastable=[False] * (x.ndim -1))])
broadcastable=[False] * (x.ndim - 1))])
def perform(self, node, (x,), (z,)):
z[0] = x.diagonal(self.offset, self.axis1, self.axis2)
......@@ -7322,7 +7325,7 @@ class Diagonal(Op):
in_shape, = shapes
dim1 = in_shape[self.axis1]
dim2 = in_shape[self.axis2]
out_shape = [d for i,d in enumerate(in_shape)
out_shape = [d for i, d in enumerate(in_shape)
if i not in (self.axis1, self.axis2)]
# The following logic is inspired by C code of PyArray_Diagonal().
offset = self.offset
......@@ -7338,12 +7341,14 @@ class Diagonal(Op):
def __str__(self):
return self.__class__.__name__
def diagonal(a, offset=0, axis1=0, axis2=1):
if (offset, axis1, axis2) == (0, 0, 1):
from theano.sandbox.linalg import extract_diag
return extract_diag(a)
return Diagonal(offset, axis1, axis2)(a)
class Diag(Op):
def __eq__(self, other):
......@@ -7371,6 +7376,7 @@ class Diag(Op):
def __str__(self):
return self.__class__.__name__
def diag(v, k=0):
if v.ndim == 1:
assert k == 0, "diagonals other than main are not implemented"
......
......@@ -109,7 +109,7 @@ class SoftmaxWithBias(gof.Op):
if (PyArray_NDIM(%(x)s) != 2)
{
PyErr_SetString(PyExc_ValueError, "a not 2d tensor");
PyErr_SetString(PyExc_ValueError, "not a 2d tensor");
%(fail)s;
}
if (PyArray_NDIM(%(b)s) != 1)
......@@ -120,7 +120,7 @@ class SoftmaxWithBias(gof.Op):
if ((PyArray_DESCR(%(x)s)->type_num != NPY_DOUBLE) &&
(PyArray_DESCR(%(x)s)->type_num != NPY_FLOAT))
{
PyErr_SetString(PyExc_TypeError, "a not float");
PyErr_SetString(PyExc_TypeError, "not a float");
%(fail)s;
}
if ((PyArray_DESCR(%(b)s)->type_num != NPY_DOUBLE) &&
......@@ -401,13 +401,13 @@ class Softmax(gof.Op):
if (%(x)s->nd != 2)
{
PyErr_SetString(PyExc_ValueError, "a not 2d tensor");
PyErr_SetString(PyExc_ValueError, "not a 2d tensor");
%(fail)s;
}
if ((%(x)s->descr->type_num != PyArray_DOUBLE) &&
(%(x)s->descr->type_num != PyArray_FLOAT))
{
PyErr_SetString(PyExc_TypeError, "a not float");
PyErr_SetString(PyExc_TypeError, "not a float");
%(fail)s;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论