Skip to content

Commit

Permalink
Removed functional code form assert statements, since they are remove…
Browse files Browse the repository at this point in the history
…d while running in optimized mode (python -OO) causing the network not being trained
  • Loading branch information
viktor-ferenczi committed May 28, 2015
1 parent 6802688 commit aac1dfd
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions wrapper/cxxnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def ctypes2numpy(cptr, length, dtype=numpy.float32):
"""convert a ctypes pointer array to numpy array """
#assert isinstance(cptr, ctypes.POINTER(ctypes.c_float))
res = numpy.zeros(length, dtype=dtype)
assert ctypes.memmove(res.ctypes.data, cptr, length * res.strides[0])
if not ctypes.memmove(res.ctypes.data, cptr, length * res.strides[0]):
raise AssertionError('ctypes.memmove failed')
return res

def ctypes2numpyT(cptr, shape, dtype=numpy.float32, stride = None):
Expand All @@ -45,11 +46,13 @@ def ctypes2numpyT(cptr, shape, dtype=numpy.float32, stride = None):
size *= x
if stride is None:
res = numpy.zeros(size, dtype=dtype)
assert ctypes.memmove(res.ctypes.data, cptr, size * res.strides[0])
if not ctypes.memmove(res.ctypes.data, cptr, size * res.strides[0]):
raise AssertionError('ctypes.memmove failed')
else:
dsize = size / shape[-1] * stride
res = numpy.zeros(dsize, dtype=dtype)
assert ctypes.memmove(res.ctypes.data, cptr, dsize * res.strides[0])
if not ctypes.memmove(res.ctypes.data, cptr, dsize * res.strides[0]):
raise AssertionError('ctypes.memmove failed')
res = res.reshape((dsize / shape[-1], shape[-1]))
res = res[:, 0 :shape[-1]]
return res.reshape(shape)
Expand Down

0 comments on commit aac1dfd

Please sign in to comment.