Commit d0708ec3 authored by André Anjos's avatar André Anjos 💬
Browse files

Require C-contiguous/aligned array for writing (fixes #6)

parent fd7511d4
Pipeline #3758 passed with stages
in 65 minutes and 25 seconds
# import Libraries of other lib packages
import numpy
import bob.core
# import our own Library
......@@ -176,6 +177,9 @@ def save(array, filename, create_directories = False):
if create_directories:
create_directories_safe(os.path.dirname(filename))
# requires data is c-contiguous and aligned, will create a copy otherwise
array = numpy.require(array, requirements=('C_CONTIGUOUS', 'ALIGNED'))
return File(filename, 'w').write(array)
# Just to make it homogenous with the C++ API
......@@ -204,6 +208,10 @@ def append(array, filename):
``position`` : int
See :py:meth:`File.append`
"""
# requires data is c-contiguous and aligned, will create a copy otherwise
array = numpy.require(array, requirements=('C_CONTIGUOUS', 'ALIGNED'))
return File(filename, 'a').append(array)
def peek(filename):
......
......@@ -208,6 +208,7 @@ def test_hdf5():
array_readwrite(".h5", a2)
array_readwrite('.h5', a3)
array_readwrite(".h5", a4)
array_readwrite('.h5', a3[:,::2,::2,::2]) #test non-contiguous
# arrayset writing tests
a1 = []
......@@ -274,6 +275,7 @@ def test_tensorfile():
array_readwrite('.tensor', a1)
array_readwrite(".tensor", a2)
array_readwrite(".tensor", a3)
array_readwrite('.tensor', a3[::2,::2]) #test non-contiguous
# arrayset writing tests
a1 = []
......@@ -302,6 +304,7 @@ def test_csv():
array_readwrite('.csv', a1, close=True)
array_readwrite(".csv", a2, close=True)
array_readwrite('.csv', a3, close=True)
array_readwrite('.csv', a3[::2,::2], close=True) #test non-contiguous
# arrayset writing tests
a1 = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment