Skip to content
GitLab
Menu
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
50bc7693
Commit
50bc7693
authored
Nov 06, 2020
by
dboe
Browse files
linting
parent
cfb1262a
Pipeline
#85980
passed with stages
in 56 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tfields/core.py
View file @
50bc7693
...
...
@@ -69,7 +69,7 @@ class AbstractObject(object): # pylint: disable=useless-object-inheritance
Saving by redirecting to the correct save method depending on path
Args:
path (str
or
buffer)
path (str
|
buffer)
*args: joined with path
**kwargs:
extension (str): only needed if path is buffer
...
...
@@ -357,7 +357,8 @@ class AbstractNdarray(np.ndarray, AbstractObject):
**kwargs: arguments corresponding to __slots__
TODO:
equality check
* equality check
* plot
"""
...
...
@@ -677,12 +678,12 @@ class Tensors(AbstractNdarray): # pylint: disable=too-many-public-methods
def
__new__
(
cls
,
tensors
,
**
kwargs
):
# pylint: disable=too-many-branches
dtype
=
kwargs
.
pop
(
"dtype"
,
None
)
order
=
kwargs
.
pop
(
"order"
,
None
)
dim
=
kwargs
.
pop
(
"dim"
,
None
)
# pylint: disable=redefined-outer-name
dim
_
=
kwargs
.
pop
(
"dim"
,
None
)
# copy constructor extracts the kwargs from tensors
if
issubclass
(
type
(
tensors
),
Tensors
):
if
dim
is
not
None
:
dim
=
tensors
.
dim
if
dim
_
is
not
None
:
dim
_
=
tensors
.
dim
coord_sys
=
kwargs
.
pop
(
"coord_sys"
,
tensors
.
coord_sys
)
tensors
=
tensors
.
copy
()
tensors
.
transform
(
coord_sys
)
...
...
@@ -709,13 +710,13 @@ class Tensors(AbstractNdarray): # pylint: disable=too-many-public-methods
if
len
(
tensors
)
==
0
:
if
issubclass
(
type
(
tensors
),
tfields
.
Tensors
):
tensors
=
np
.
empty
(
tensors
.
shape
,
dtype
=
tensors
.
dtype
)
elif
dim
is
not
None
:
tensors
=
np
.
empty
((
0
,
dim
))
elif
dim
_
is
not
None
:
tensors
=
np
.
empty
((
0
,
dim
_
))
if
issubclass
(
type
(
tensors
),
np
.
ndarray
):
# np.empty
pass
elif
hasattr
(
tensors
,
"shape"
):
dim
=
dim
(
tensors
)
dim
_
=
dim
_
(
tensors
)
else
:
raise
ValueError
(
"Empty tensors need dimension parameter 'dim'."
)
...
...
@@ -732,11 +733,11 @@ class Tensors(AbstractNdarray): # pylint: disable=too-many-public-methods
found
=
obj
.
shape
[
1
:],
**
locals
()
)
)
if
dim
is
not
None
:
if
dim
!=
obj
.
dim
:
if
dim
_
is
not
None
:
if
dim
_
!=
obj
.
dim
:
raise
ValueError
(
"Incorrect dimension: {obj.dim} given,"
" {dim} demanded."
.
format
(
**
locals
())
" {dim
_
} demanded."
.
format
(
**
locals
())
)
# update kwargs with defaults from slots
...
...
@@ -1920,13 +1921,13 @@ class TensorFields(Tensors):
@
classmethod
def
merged
(
cls
,
*
objects
,
**
kwargs
):
if
not
all
([
isinstance
(
o
,
cls
)
for
o
in
objects
]):
types
=
[
# pylint: disable=possibly-unused-variable
type
(
o
)
for
o
in
objects
]
# Note: could allow if all map_fields are none
raise
TypeError
(
"Merge constructor only accepts {cls} instances."
"Got objects of types {types} instead."
.
format
(
**
locals
())
"Got objects of types {types} instead."
.
format
(
cls
=
cls
,
types
=
[
type
(
o
)
for
o
in
objects
],
)
)
return_value
=
super
(
TensorFields
,
cls
).
merged
(
*
objects
,
**
kwargs
)
...
...
@@ -2156,28 +2157,28 @@ class Maps(sortedcontainers.SortedDict, AbstractObject):
super
().
__init__
(
*
args
,
**
kwargs
)
@
staticmethod
def
to_map
(
m
p
,
*
fields
,
copy
=
False
,
**
kwargs
):
# pylint: disable=invalid-name
def
to_map
(
m
ap_
,
*
fields
,
copy
=
False
,
**
kwargs
):
"""
Args:
m
p
(TensorFields)
m
ap_
(TensorFields)
*fields (Tensors)
copy (bool)
**kwargs: passed to TensorFields constructor
"""
if
not
copy
:
if
isinstance
(
m
p
,
TensorFields
)
and
not
fields
:
if
not
np
.
issubdtype
(
m
p
.
dtype
,
np
.
integer
):
m
p
=
m
p
.
astype
(
int
)
if
isinstance
(
m
ap_
,
TensorFields
)
and
not
fields
:
if
not
np
.
issubdtype
(
m
ap_
.
dtype
,
np
.
integer
):
m
ap_
=
m
ap_
.
astype
(
int
)
else
:
copy
=
True
if
copy
:
# not else, because in case of wrong m
p
type we initialize
if
copy
:
# not else, because in case of wrong m
ap_
type we initialize
kwargs
.
setdefault
(
"dtype"
,
int
)
m
p
=
TensorFields
(
m
p
,
*
fields
,
**
kwargs
)
return
m
p
m
ap_
=
TensorFields
(
m
ap_
,
*
fields
,
**
kwargs
)
return
m
ap_
def
__setitem__
(
self
,
dimension
,
m
p
):
m
p
=
self
.
to_map
(
m
p
)
super
().
__setitem__
(
dimension
,
m
p
)
def
__setitem__
(
self
,
dimension
,
m
ap_
):
m
ap_
=
self
.
to_map
(
m
ap_
)
super
().
__setitem__
(
dimension
,
m
ap_
)
def
_args
(
self
):
return
super
().
_args
()
+
(
list
(
self
.
items
()),)
...
...
@@ -2315,10 +2316,10 @@ class TensorMaps(TensorFields):
map_delete_mask
=
np
.
full
(
(
len
(
self
.
maps
[
map_dim
]),),
False
,
dtype
=
bool
)
for
i
,
m
p
in
enumerate
(
# pylint: disable=invalid-name
for
i
,
m
ap_
in
enumerate
(
# pylint: disable=invalid-name
self
.
maps
[
map_dim
]
):
for
node_index
in
m
p
:
for
node_index
in
m
ap_
:
if
node_index
in
delete_indices
:
map_delete_mask
[
i
]
=
True
break
...
...
@@ -2354,13 +2355,13 @@ class TensorMaps(TensorFields):
else
:
inst
,
templates
=
(
return_value
,
None
)
dim_maps_dict
=
{}
# {dim: {i: m
p
}
dim_maps_dict
=
{}
# {dim: {i: m
ap_
}
for
i
,
obj
in
enumerate
(
objects
):
for
dimension
,
m
p
in
obj
.
maps
.
items
():
# pylint: disable=invalid-name
m
p
=
m
p
+
cum_tensor_lengths
[
i
]
# pylint: disable=invalid-name
for
dimension
,
m
ap_
in
obj
.
maps
.
items
():
# pylint: disable=invalid-name
m
ap_
=
m
ap_
+
cum_tensor_lengths
[
i
]
# pylint: disable=invalid-name
if
dimension
not
in
dim_maps_dict
:
dim_maps_dict
[
dimension
]
=
{}
dim_maps_dict
[
dimension
][
i
]
=
m
p
dim_maps_dict
[
dimension
][
i
]
=
m
ap_
maps
=
[]
template_maps_list
=
[[]
for
i
in
range
(
len
(
objects
))]
...
...
@@ -2374,7 +2375,7 @@ class TensorMaps(TensorFields):
)
if
return_templates
:
(
m
p
,
# pylint: disable=invalid-name
m
ap_
,
# pylint: disable=invalid-name
dimension_map_templates
,
)
=
return_value
for
i
in
range
(
len
(
objects
)):
...
...
@@ -2382,8 +2383,8 @@ class TensorMaps(TensorFields):
(
dimension
,
dimension_map_templates
[
i
])
)
else
:
m
p
=
return_value
# pylint: disable=invalid-name
maps
.
append
(
m
p
)
m
ap_
=
return_value
# pylint: disable=invalid-name
maps
.
append
(
m
ap_
)
inst
.
maps
=
maps
if
return_templates
:
# pylint: disable=no-else-return
...
...
@@ -2438,16 +2439,16 @@ class TensorMaps(TensorFields):
# bulk was cut so we need to correct the map references.
index_lut
=
np
.
full
(
len
(
self
),
np
.
nan
)
# float type
index_lut
[
template
.
fields
[
0
]]
=
np
.
arange
(
len
(
template
.
fields
[
0
]))
for
mp_dim
,
m
p
in
self
.
maps
.
items
():
# pylint: disable=invalid-name
m
p
=
m
p
.
_cut_template
(
# pylint: disable=
invalid-name,
protected-access
template
.
maps
[
mp_dim
]
for
m
a
p_dim
,
m
ap_
in
self
.
maps
.
items
():
m
ap_
=
m
ap_
.
_cut_template
(
# pylint: disable=protected-access
template
.
maps
[
m
a
p_dim
]
)
if
template
.
fields
:
# correct
m
p
=
Maps
.
to_map
(
# pylint: disable=invalid-name
index_lut
[
m
p
],
*
m
p
.
fields
m
ap_
=
Maps
.
to_map
(
# pylint: disable=invalid-name
index_lut
[
m
ap_
],
*
m
ap_
.
fields
)
inst
.
maps
[
mp_dim
]
=
m
p
inst
.
maps
[
m
a
p_dim
]
=
m
ap_
return
inst
def
equal
(
self
,
other
,
**
kwargs
):
...
...
@@ -2557,12 +2558,10 @@ class TensorMaps(TensorFields):
# self.maps in case stale vertices where removed
for
map_dim
in
inst
.
maps
:
for
face_index
in
range
(
len
(
inst
.
maps
[
map_dim
])):
# face index
mp
=
np
.
array
(
# noqa: E501 pylint: disable=invalid-name
inst
.
maps
[
map_dim
],
dtype
=
int
)
if
tensor_index
in
mp
[
face_index
]:
map_
=
np
.
array
(
inst
.
maps
[
map_dim
],
dtype
=
int
)
if
tensor_index
in
map_
[
face_index
]:
index
=
tfields
.
lib
.
util
.
index
(
m
p
[
face_index
],
tensor_index
m
ap_
[
face_index
],
tensor_index
)
inst
.
maps
[
map_dim
][
face_index
][
index
]
=
duplicate_index
if
remove_mask
.
any
():
...
...
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