diff --git a/bob/io/base/__init__.py b/bob/io/base/__init__.py index 4423e68f9f86b2d0792a871f3612d5a7219859aa..e52764b4696ea1852b658be27293c8c463ed69b1 100644 --- a/bob/io/base/__init__.py +++ b/bob/io/base/__init__.py @@ -1,4 +1,5 @@ # 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): diff --git a/bob/io/base/test_file.py b/bob/io/base/test_file.py index 372fab6aef2e2af8a84bff291e48ad0975956a06..f58ca5d319df7822f3815c8d75ea2c8d4e3d5014 100644 --- a/bob/io/base/test_file.py +++ b/bob/io/base/test_file.py @@ -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 = []