Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
fbebef94
Commit
fbebef94
authored
Oct 29, 2018
by
Kirill Smelkov
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X `expected a single-segment buffer object` problem gone
parent
2569b175
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
2 deletions
+28
-2
lib/xnumpy.py
lib/xnumpy.py
+28
-2
No files found.
lib/xnumpy.py
View file @
fbebef94
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
# See COPYING file for full licensing terms.
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
# See https://www.nexedi.com/licensing for rationale and options.
import
numpy
as
np
import
numpy
as
np
from
numpy.lib
import
stride_tricks
as
npst
# restructure creates view of the array interpreting its minor axis as fully covered by dtype.
# restructure creates view of the array interpreting its minor axis as fully covered by dtype.
...
@@ -52,7 +53,10 @@ import numpy as np
...
@@ -52,7 +53,10 @@ import numpy as np
# ValueError: To change to a dtype of a different size, the array must be C-contiguous
# ValueError: To change to a dtype of a different size, the array must be C-contiguous
#
#
# In [6]: restructure(b, np.int64)
# In [6]: restructure(b, np.int64)
# TODO
# Out[6]: array([ 4294967296, 17179869187])
#
# In [7]: restructure(b, [('x', np.int32), ('y', np.int32)])
# Out[7]: array([(0, 1), (3, 4)], dtype=[('x', '<i4'), ('y', '<i4')])
#
#
# restructure always creates view and never copies data.
# restructure always creates view and never copies data.
#
#
...
@@ -78,4 +82,26 @@ def restructure(arr, dtype):
...
@@ -78,4 +82,26 @@ def restructure(arr, dtype):
# ok to go
# ok to go
shape
=
arr
.
shape
[:
maxis
]
+
arr
.
shape
[
maxis
+
1
:]
shape
=
arr
.
shape
[:
maxis
]
+
arr
.
shape
[
maxis
+
1
:]
stridev
=
arr
.
strides
[:
maxis
]
+
arr
.
strides
[
maxis
+
1
:]
stridev
=
arr
.
strides
[:
maxis
]
+
arr
.
strides
[
maxis
+
1
:]
return
np
.
ndarray
.
__new__
(
type
(
arr
),
shape
,
dtype
,
buffer
(
arr
),
0
,
stridev
)
# NOTE cannot use just np.ndarray because if arr is a slice it can give:
# TypeError: expected a single-segment buffer object
#return np.ndarray.__new__(type(arr), shape, dtype, buffer(arr), 0, stridev)
# XXX dup from ArrayRef
aiface
=
dict
(
arr
.
__array_interface__
)
aiface
[
'shape'
]
=
shape
aiface
[
'strides'
]
=
stridev
# type: for now we only care that itemsize is the same
aiface
[
'typestr'
]
=
'|V%d'
%
dtype
.
itemsize
aiface
[
'descr'
]
=
[(
''
,
aiface
[
'typestr'
])]
a
=
np
.
asarray
(
npst
.
DummyArray
(
aiface
,
base
=
arr
))
# restore full dtype - it should not raise here, since itemsize is the same
a
.
dtype
=
dtype
# restore full array type
a
=
a
.
view
(
type
=
type
(
arr
))
# we are done
return
a
Kirill Smelkov
@kirr
mentioned in commit
klaus/wendelin@cbe4938b
·
Oct 29, 2018
mentioned in commit
klaus/wendelin@cbe4938b
mentioned in commit klaus/wendelin@cbe4938b5957424adb35a8fcd6ad1bcf9f8d99f1
Toggle commit list
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