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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Joshua
wendelin.core
Commits
fd647f2b
Commit
fd647f2b
authored
Oct 29, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
2ad300e8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
8 deletions
+85
-8
lib/tests/test_xnumpy.py
lib/tests/test_xnumpy.py
+85
-8
No files found.
lib/tests/test_xnumpy.py
View file @
fd647f2b
...
...
@@ -20,25 +20,102 @@
from
numpy
import
arange
,
dtype
,
int32
from
wendelin.lib.xnumpy
import
restructure
from
pytest
import
raises
# XXX text
def
test_restructure
():
a
=
arange
(
3
*
3
,
dtype
=
int32
).
reshape
((
3
,
3
))
b
=
a
[:
2
,:
2
]
# xbase returns original object from which arr was restructured.
def
xbase
(
arr
):
b
=
arr
.
base
# arr -> typed view
b
=
b
.
base
# -> DummyArray
b
=
b
.
base
# -> origin
return
b
dtxy
=
dtype
([(
'x'
,
int32
),
(
'y'
,
int32
)])
# C order
a
=
arange
(
4
*
3
,
dtype
=
int32
).
reshape
((
4
,
3
))
# 0 1 2
# 3 4 5
# 6 7 8
# 9 10 11
with
raises
(
ValueError
,
match
=
"minor-axis is not C-contiguous: stride
\
(-
4
\
) <
0
"
):
restructure
(
a
[:
3
,:
2
][:,::
-
1
],
dtxy
)
with
raises
(
ValueError
,
match
=
"minor-axis is not C-contiguous: stride
\
(8
\
) != itemsize
\
(
4
\
)
"
):
restructure(a[:,::2], dtxy)
with raises(ValueError, match="
dtype
.
itemsize
\
(
8
\
)
!=
sizeof
\
(
minor
-
axis
\
)
\
(
12
\
)
"):
restructure(a, dtxy)
b = a[:3,:2]
bxy = restructure(b, dtxy)
assert xbase(bxy) is b
assert bxy.dtype == dtxy
assert
bxy
.
shape
==
(
2
,)
assert
(
0
,
1
)
==
(
0
,
1
)
assert bxy.shape == (3,)
assert bxy[0]['x'] == 0
assert bxy[0]['y'] == 1
assert bxy[1]['x'] == 3
assert bxy[1]['y'] == 4
assert bxy[2]['x'] == 6
assert bxy[2]['y'] == 7
bxy['x'][0] = 100
assert bxy[0]['x'] == 100
assert b[0,0] == 100
assert a[0,0] == 100
bxy['y'][2] = 200
assert bxy[2]['y'] == 200
assert b[2,1] == 200
assert a[2,1] == 200
# C contigous in minor; reverse in major
a = arange(4*3, dtype=int32).reshape((4,3))
# 0 1 2
# 3 4 5
# 6 7 8
# 9 10 11
b = a[:3,:2][::-1,:]
bxy = restructure(b, dtxy)
assert xbase(bxy) is b
assert bxy.dtype == dtxy
assert bxy.shape == (3,)
assert bxy[0]['x'] == 6
assert bxy[0]['y'] == 7
assert bxy[1]['x'] == 3
assert bxy[1]['y'] == 4
assert bxy[2]['x'] == 0
assert bxy[2]['y'] == 1
bxy['x'][0] = 100
assert bxy[0]['x'] == 100
assert b[0,0] == 100
assert a[2,0] == 100
bxy['y'][2] = 200
assert bxy[2]['y'] == 200
assert b[2,1] == 200
assert a[0,1] == 200
# F order
a = arange(4*3, dtype=int32).reshape((4,3), order='F')
# 0 4 8
# 1 5 9
# 2 6 10
# 3 7 11
b = a[:2,:3]
bxy = restructure(b, dtxy)
assert xbase(bxy) is b
assert bxy.dtype == dtxy
assert bxy.shape == (3,)
assert bxy[0]['x'] == 0
assert bxy[0]['y'] == 1
assert bxy[1]['x'] == 4
assert bxy[1]['y'] == 5
assert bxy[2]['x'] == 8
assert bxy[2]['y'] == 9
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
bxy['y'][
2
] = 200
assert bxy[
2
]['y'] == 200
assert b[1,
2
] == 200
assert a[1,
2
] == 200
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