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
2ad300e8
Commit
2ad300e8
authored
Oct 29, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
009b9fb9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
9 deletions
+54
-9
lib/tests/test_xnumpy.py
lib/tests/test_xnumpy.py
+44
-0
lib/xnumpy.py
lib/xnumpy.py
+10
-9
No files found.
lib/tests/test_xnumpy.py
0 → 100644
View file @
2ad300e8
# -*- coding: utf-8 -*-
# Copyright (C) 2018 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
from
numpy
import
arange
,
dtype
,
int32
from
wendelin.lib.xnumpy
import
restructure
# XXX text
def
test_restructure
():
a
=
arange
(
3
*
3
,
dtype
=
int32
).
reshape
((
3
,
3
))
b
=
a
[:
2
,:
2
]
dtxy
=
dtype
([(
'x'
,
int32
),
(
'y'
,
int32
)])
bxy
=
restructure
(
b
,
dtxy
)
assert
bxy
.
dtype
==
dtxy
assert
bxy
.
shape
==
(
2
,)
assert
(
0
,
1
)
==
(
0
,
1
)
assert
bxy
[
0
][
'x'
]
==
0
assert
bxy
[
0
][
'y'
]
==
1
assert
bxy
[
1
][
'x'
]
==
3
assert
bxy
[
1
][
'y'
]
==
4
bxy
[
'x'
][
0
]
=
100
assert
bxy
[
0
][
'x'
]
==
100
assert
b
[
0
,
0
]
==
100
assert
a
[
0
,
0
]
==
100
bxy
[
'y'
][
1
]
=
200
assert
bxy
[
1
][
'y'
]
==
200
assert
b
[
1
,
1
]
==
200
assert
a
[
1
,
1
]
==
200
lib/xnumpy.py
View file @
2ad300e8
...
...
@@ -21,6 +21,7 @@
import
numpy
as
np
from
numpy.lib
import
stride_tricks
as
npst
# XXX move ArrayRef here.
# restructure creates view of the array interpreting its minor axis as fully covered by dtype.
#
...
...
@@ -44,23 +45,23 @@ from numpy.lib import stride_tricks as npst
# array([[0, 1],
# [3, 4]], dtype=int32)
#
# In [5]: b.view(np.int64)
# In [5]: dtxy = np.dtype([('x', np.int32), ('y', np.int32)])
#
# In [6]: dtxy
# Out[6]: dtype([('x', '<i4'), ('y', '<i4')])
# In [7]: b.view(dtxy)
# ---------------------------------------------------------------------------
# ValueError Traceback (most recent call last)
# <ipython-input-66-af98529aa150> in <module>()
# ----> 1 b.view(
np.int64
)
# ----> 1 b.view(
dtxy
)
#
# ValueError: To change to a dtype of a different size, the array must be C-contiguous
#
# In [6]: restructure(b, np.int64)
# 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')])
# In [8]: restructure(b, dtxy)
# Out[8]: array([(0, 1), (3, 4)], dtype=[('x', '<i4'), ('y', '<i4')])
#
# restructure always creates view and never copies data.
#
# TODO tests
def
restructure
(
arr
,
dtype
):
dtype
=
np
.
dtype
(
dtype
)
# convenience
...
...
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