提交 fb547b73 authored 作者: Hengjean's avatar Hengjean

Made every int32 int64 and added c_cache_version

上级 165eb70c
......@@ -63,12 +63,12 @@ class GetItem(Op):
index = Constant(SliceType(), index)
return Apply(self, [x, index], [x.type()])
else:
index = T.constant(index, ndim=0, dtype='int32')
index = T.constant(index, ndim=0, dtype='int64')
return Apply(self, [x, index], [x.ttype()])
if isinstance(index.type, SliceType):
return Apply(self, [x, index], [x.type()])
elif isinstance(index, T.TensorVariable) and index.ndim == 0:
assert index.dtype == 'int32'
assert index.dtype == 'int64'
return Apply(self, [x, index], [x.ttype()])
else:
raise TypeError('Expected scalar or slice as index.')
......@@ -86,13 +86,16 @@ class GetItem(Op):
output_name = out[0]
fail = sub['fail']
return """
%(output_name)s = (typeof %(output_name)s) PyList_GetItem( (PyObject*) %(x_name)s, *((int *) PyArray_DATA(%(index)s)));
%(output_name)s = (typeof %(output_name)s) PyList_GetItem( (PyObject*) %(x_name)s, *((npy_int64 *) PyArray_DATA(%(index)s)));
if(%(output_name)s == NULL){
%(fail)s
}
Py_INCREF(%(output_name)s);
""" % locals()
def c_code_cache_version(self):
return (1,)
getitem = GetItem()
......@@ -149,6 +152,9 @@ class Append(Op):
Py_INCREF(%(output_name)s);
""" % locals()
def c_code_cache_version(self):
return (1,)
append = Append()
......@@ -209,6 +215,9 @@ class Extend(Op):
Py_INCREF(%(output_name)s);
""" % locals()
def c_code_cache_version(self):
return (1,)
extend = Extend()
......@@ -229,9 +238,9 @@ class Insert(Op):
assert isinstance(x.type, TypedListType)
assert x.ttype == toInsert.type
if not isinstance(index, Variable):
index = T.constant(index, ndim=0, dtype='int32')
index = T.constant(index, ndim=0, dtype='int64')
else:
assert index.dtype == 'int32'
assert index.dtype == 'int64'
assert isinstance(index, T.TensorVariable) and index.ndim == 0
return Apply(self, [x, index, toInsert], [x.type()])
......@@ -261,12 +270,15 @@ class Insert(Op):
if(%(output_name)s==NULL){
%(fail)s
};
if(PyList_Insert((PyObject*) %(output_name)s, *((int *) PyArray_DATA(%(index)s)), (PyObject*) %(toInsert)s)==-1){
if(PyList_Insert((PyObject*) %(output_name)s, *((npy_int64 *) PyArray_DATA(%(index)s)), (PyObject*) %(toInsert)s)==-1){
%(fail)s
};
Py_INCREF(%(output_name)s);
""" % locals()
def c_code_cache_version(self):
return (1,)
insert = Insert()
......@@ -361,6 +373,9 @@ class Reverse(Op):
Py_INCREF(%(output_name)s);
""" % locals()
def c_code_cache_version(self):
return (1,)
reverse = Reverse()
......
......@@ -68,7 +68,7 @@ class test_get_item(unittest.TestCase):
mySymbolicMatricesList = TypedListType(T.TensorType(
theano.config.floatX, (False, False)))()
mySymbolicScalar = T.scalar(dtype='int32')
mySymbolicScalar = T.scalar(dtype='int64')
z = GetItem()(mySymbolicMatricesList, mySymbolicScalar)
......@@ -79,12 +79,12 @@ class test_get_item(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], numpy.asarray(0,
dtype='int32')), x))
dtype='int64')), x))
def test_interface(self):
mySymbolicMatricesList = TypedListType(T.TensorType(
theano.config.floatX, (False, False)))()
mySymbolicScalar = T.scalar(dtype='int32')
mySymbolicScalar = T.scalar(dtype='int64')
z = mySymbolicMatricesList[mySymbolicScalar]
......@@ -94,7 +94,7 @@ class test_get_item(unittest.TestCase):
x = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], numpy.asarray(0,
dtype='int32')), x))
dtype='int64')), x))
z = mySymbolicMatricesList[0]
......@@ -241,7 +241,7 @@ class test_insert(unittest.TestCase):
mySymbolicMatricesList = TypedListType(T.TensorType(
theano.config.floatX, (False, False)))()
myMatrix = T.matrix()
myScalar = T.scalar(dtype='int32')
myScalar = T.scalar(dtype='int64')
z = Insert(True)(mySymbolicMatricesList, myScalar, myMatrix)
......@@ -253,13 +253,13 @@ class test_insert(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], numpy.asarray(1,
dtype='int32'), y), [x, y]))
dtype='int64'), y), [x, y]))
def test_sanity_check(self):
mySymbolicMatricesList = TypedListType(T.TensorType(
theano.config.floatX, (False, False)))()
myMatrix = T.matrix()
myScalar = T.scalar(dtype='int32')
myScalar = T.scalar(dtype='int64')
z = Insert()(mySymbolicMatricesList, myScalar, myMatrix)
......@@ -270,13 +270,13 @@ class test_insert(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], numpy.asarray(1,
dtype='int32'), y), [x, y]))
dtype='int64'), y), [x, y]))
def test_interface(self):
mySymbolicMatricesList = TypedListType(T.TensorType(
theano.config.floatX, (False, False)))()
myMatrix = T.matrix()
myScalar = T.scalar(dtype='int32')
myScalar = T.scalar(dtype='int64')
z = mySymbolicMatricesList.insert(myScalar, myMatrix)
......@@ -287,7 +287,7 @@ class test_insert(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], numpy.asarray(1,
dtype='int32'), y), [x, y]))
dtype='int64'), y), [x, y]))
class test_remove(unittest.TestCase):
......
......@@ -77,7 +77,7 @@ class test_inplace(unittest.TestCase):
def test_insert_inplace(self):
mySymbolicMatricesList = TypedListType(T.TensorType(
theano.config.floatX, (False, False)))()
mySymbolicIndex = T.scalar(dtype='int32')
mySymbolicIndex = T.scalar(dtype='int64')
mySymbolicMatrix = T.matrix()
z = Insert()(mySymbolicMatricesList, mySymbolicIndex, mySymbolicMatrix)
......@@ -93,7 +93,7 @@ class test_inplace(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], numpy.asarray(1,
dtype='int32'), y), [x, y]))
dtype='int64'), y), [x, y]))
def test_remove_inplace(self):
mySymbolicMatricesList = TypedListType(T.TensorType(
......
......@@ -105,3 +105,6 @@ class TypedListType(gof.Type):
def c_cleanup(self, name, sub):
return ""
def c_code_cache_version(self):
return (1,)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论