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
d23dec96
Commit
d23dec96
authored
May 09, 2020
by
dboe
Browse files
really just subclassing list now
parent
6ec44d8a
Changes
2
Hide whitespace changes
Inline
Side-by-side
test/test_core.py
View file @
d23dec96
...
...
@@ -32,8 +32,6 @@ class AbstractNdarray_Check(object):
def
test_dict
(
self
):
d
=
self
.
_inst
.
_as_dict
()
print
(
"DONE"
)
print
(
d
)
other
=
type
(
self
.
_inst
).
_from_dict
(
**
d
)
self
.
demand_equal
(
other
)
...
...
@@ -204,16 +202,24 @@ class Container_Test(Container_Check, unittest.TestCase):
self
.
_inst
=
tfields
.
Container
([
sphere
,
sphere2
])
class
ContainerFolded_Test
(
Container_Check
,
unittest
.
TestCase
):
class
ContainerNoList_Test
(
Container_Check
,
unittest
.
TestCase
):
def
demand_equal_tensors
(
self
,
one
,
other
,
atol
=
False
,
transformed
=
False
):
if
atol
:
self
.
assertTrue
(
one
.
equal
(
other
,
atol
=
ATOL
))
else
:
self
.
assertTrue
(
one
.
equal
(
other
))
if
not
transformed
:
self
.
assertEqual
(
one
.
coord_sys
,
other
.
coord_sys
)
self
.
assertEqual
(
one
.
name
,
other
.
name
)
def
demand_equal
(
self
,
other
):
self
.
demand_equal_tensors
(
self
.
_inst
.
items
.
items
[
0
],
other
)
self
.
demand_equal_tensors
(
self
.
_inst
.
items
.
items
[
1
],
other
)
def
setUp
(
self
):
sphere
=
tfields
.
Mesh3D
.
grid
(
(
1
,
1
,
1
),
(
-
np
.
pi
,
np
.
pi
,
3
),
(
-
np
.
pi
/
2
,
np
.
pi
/
2
,
3
),
coord_sys
=
'spherical'
)
sphere2
=
sphere
.
copy
()
*
3
self
.
_container
=
tfields
.
Container
([
sphere
,
sphere2
])
self
.
_inst
=
tfields
.
Container
(
self
.
_container
)
t
=
tfields
.
TensorFields
([[
1
,
2
,
3
]])
self
.
_inst
=
tfields
.
Container
(
t
)
print
(
self
.
_inst
.
items
)
if
__name__
==
'__main__'
:
...
...
tfields/core.py
View file @
d23dec96
...
...
@@ -469,7 +469,8 @@ class AbstractNdarray(np.ndarray):
sub_dict
=
list_dict
[
key
]
list_dict
[
key
]
=
[]
for
index
in
sorted
(
list
(
sub_dict
)):
bulk_type
=
sub_dict
[
index
].
get
(
"bulk_type"
).
tolist
()
bulk_type
=
sub_dict
[
index
].
get
(
"bulk_type"
)
# bulk_type = bulk_type.tolist() was necessary before. no clue
if
isinstance
(
bulk_type
,
bytes
):
# asthonishingly, this is not necessary under linux.
# Found under nt. ???
...
...
@@ -483,6 +484,8 @@ class AbstractNdarray(np.ndarray):
'''
bulk
=
kwargs
.
pop
(
'bulk'
)
bulk_type
=
kwargs
.
pop
(
'bulk_type'
)
print
(
"-"
*
100
)
print
(
bulk
,
bulk_type
,
kwargs
)
obj
=
cls
.
__new__
(
cls
,
bulk
,
**
kwargs
)
'''
...
...
@@ -1928,7 +1931,7 @@ class Container(AbstractNdarray):
__slots__
=
[
"items"
,
"labels"
]
def
__new__
(
cls
,
items
,
**
kwargs
):
if
issubclass
(
type
(
items
),
cls
):
if
issubclass
(
type
(
items
),
Container
):
kwargs
.
setdefault
(
'labels'
,
items
.
labels
)
items
=
items
.
items
kwargs
[
"items"
]
=
items
...
...
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