Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Daniel Boeckenhoff
tfields
Commits
b06880c1
Commit
b06880c1
authored
May 13, 2020
by
dboe
Browse files
[A
parent
46a81e34
Changes
2
Hide whitespace changes
Inline
Side-by-side
test/test_core.py
View file @
b06880c1
...
...
@@ -23,7 +23,7 @@ class Base_Check(object):
def
test_implicit_copy
(
self
):
copy
=
type
(
self
.
_inst
)(
self
.
_inst
)
self
.
demand_equal
(
copy
)
#
self.demand_equal(copy)
# self.assertIsNot(self._inst, copy)
def
test_explicit_copy
(
self
):
...
...
@@ -251,6 +251,45 @@ class TensorMaps_Test(TensorMaps_Empty_Test):
maps
=
self
.
_maps
)
class
TensorMaps_Indexing_Test
(
unittest
.
TestCase
):
def
setUp
(
self
):
tensors
=
np
.
arange
(
10
).
reshape
((
-
1
,
1
))
self
.
_maps_tensors
=
[[[
0
,
0
,
0
],
[
1
,
2
,
3
],
[
3
,
5
,
9
]],
[[
6
,
4
],
[
7
,
8
]],
[[
7
]]]
self
.
_inst
=
tfields
.
TensorMaps
(
tensors
,
maps
=
self
.
_maps_tensors
)
def
test_pick_indexing
(
self
):
pick
=
self
.
_inst
[
7
]
self
.
assertTrue
(
pick
.
equal
([
7
]))
self
.
assertTrue
(
np
.
array_equal
(
pick
.
maps
[
1
],
[[
0
]]))
self
.
assertTrue
(
len
(
pick
.
maps
),
1
)
pick
=
self
.
_inst
[
0
]
self
.
assertTrue
(
pick
.
equal
([[
0
]]))
self
.
assertTrue
(
np
.
array_equal
(
pick
.
maps
[
3
],
[[
0
,
0
,
0
]]))
self
.
assertTrue
(
len
(
pick
.
maps
),
1
)
def
test_slice_indexing
(
self
):
slce
=
self
.
_inst
[
1
:
7
]
self
.
assertTrue
(
slce
.
equal
([[
1
],
[
2
],
[
3
],
[
4
],
[
5
],
[
6
]]))
self
.
assertTrue
(
np
.
array_equal
(
slce
.
maps
[
3
],
[[
0
,
1
,
2
]]))
self
.
assertTrue
(
np
.
array_equal
(
slce
.
maps
[
2
],
[[
5
,
3
]]))
self
.
assertTrue
(
len
(
slce
.
maps
),
2
)
def
test_mask_indexing
(
self
):
mask
=
self
.
_inst
[
np
.
array
([
False
,
True
,
True
,
True
,
True
,
True
,
True
,
False
,
False
,
False
])]
self
.
assertTrue
(
mask
.
equal
([[
1
],
[
2
],
[
3
],
[
4
],
[
5
],
[
6
]]))
self
.
assertTrue
(
np
.
array_equal
(
mask
.
maps
[
3
],
[[
0
,
1
,
2
]]))
self
.
assertTrue
(
np
.
array_equal
(
mask
.
maps
[
2
],
[[
5
,
3
]]))
self
.
assertTrue
(
len
(
mask
.
maps
),
2
)
class
TensorMaps_NoFields_Test
(
TensorMaps_Test
):
def
setUp
(
self
):
self
.
_inst
=
tfields
.
TensorMaps
(
...
...
tfields/core.py
View file @
b06880c1
...
...
@@ -2120,13 +2120,13 @@ class Maps(sortedcontainers.SortedDict, AbstractObject):
if
issubclass
(
type
(
entry
),
tuple
):
if
np
.
issubdtype
(
type
(
entry
[
0
]),
np
.
integer
):
# Maps([(key, value), ...])
new_args
+=
(
entry
[
1
])
new_args
+=
(
entry
[
1
]
,
)
else
:
# Maps([(tensors, field1, field2), ...])
new_args
+=
(
entry
)
new_args
+=
(
entry
,
)
else
:
# Maps([mp, mp, ...])
args
=
tuple
(
args
[
0
]
)
new_
args
+
=
(
entry
,
)
args
=
new_args
elif
len
(
args
)
==
1
and
issubclass
(
type
(
args
[
0
]),
dict
):
# Maps([]) - includes Maps i.e. copy
...
...
@@ -2312,10 +2312,9 @@ class TensorMaps(TensorFields):
item
.
maps
=
Maps
(
item
.
maps
)
indices
=
np
.
arange
(
len
(
self
))
keep_indices
=
indices
[
index
]
if
np
.
issubdtyp
e
(
keep_indices
.
dtype
,
np
.
integer
):
if
isinstanc
e
(
keep_indices
,
(
int
,
np
.
integer
)
)
:
keep_indices
=
[
keep_indices
]
delete_indices
=
set
(
indices
.
flatten
())
\
.
difference
(
set
(
keep_indices
.
flatten
))
delete_indices
=
set
(
indices
).
difference
(
set
(
keep_indices
))
# correct all maps that contain deleted indices
for
map_dim
in
self
.
maps
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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