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

Made every int32 int64 and added c_cache_version

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