Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.io.base
Commits
d0708ec3
Commit
d0708ec3
authored
Sep 17, 2016
by
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
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
bob/io/base/__init__.py
View file @
d0708ec3
# 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
):
...
...
bob/io/base/test_file.py
View file @
d0708ec3
...
...
@@ -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
=
[]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment