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
31f2b698
Commit
31f2b698
authored
Aug 06, 2018
by
Daniel Boeckenhoff
Browse files
some python3 specifics
parent
9bc2a23f
Changes
5
Hide whitespace changes
Inline
Side-by-side
tfields/bases/manifold_3.py
View file @
31f2b698
...
...
@@ -129,7 +129,12 @@ def cartesian_to_spherical(array):
# phi for phi between -pi, pi
problemPhiIndices
=
np
.
where
((
array
[:,
0
]
<
0
)
&
(
array
[:,
1
]
==
0
))
with
warnings
.
catch_warnings
():
warnings
.
filterwarnings
(
'ignore'
,
message
=
"invalid value encountered in divide"
)
# python2.7
warnings
.
filterwarnings
(
'ignore'
,
message
=
"invalid value encountered in divide"
)
# python3.x
warnings
.
filterwarnings
(
'ignore'
,
message
=
"invalid value encountered in true_divide"
)
array
[:,
1
]
=
np
.
sign
(
array
[:,
1
])
*
np
.
arccos
(
array
[:,
0
]
/
np
.
sqrt
(
xy
))
array
[:,
1
][
problemPhiIndices
]
=
np
.
pi
...
...
tfields/core.py
View file @
31f2b698
...
...
@@ -183,7 +183,7 @@ class AbstractNdarray(np.ndarray):
inst
=
super
(
AbstractNdarray
,
self
).
copy
(
*
args
,
**
kwargs
)
for
attr
in
self
.
_iter_slots
():
value
=
getattr
(
self
,
attr
)
if
hasattr
(
value
,
'copy'
):
if
hasattr
(
value
,
'copy'
)
and
not
isinstance
(
value
,
list
)
:
setattr
(
inst
,
attr
,
value
.
copy
(
*
args
,
**
kwargs
))
elif
isinstance
(
value
,
list
):
list_copy
=
[]
...
...
@@ -307,7 +307,7 @@ class AbstractNdarray(np.ndarray):
part_dict
=
part
.
_as_dict
()
for
part_attr
,
part_value
in
part_dict
.
items
():
d
[
"{attr}::{i}::{part_attr}"
.
format
(
**
locals
())]
=
part_value
continue
continue
if
isinstance
(
value
,
AbstractNdarray
):
value
=
value
.
_as_dict
()
d
[
attr
]
=
value
...
...
@@ -1763,9 +1763,7 @@ class TensorMaps(TensorFields):
keep_indices
=
indices
[
mask
]
if
isinstance
(
keep_indices
,
int
):
keep_indices
=
[
keep_indices
]
delete_indices
=
set
(
indices
).
difference
(
set
(
keep_indices
))
# delete_indices = indices[~mask]
# delete_indices = set(delete_indices) # set speeds up everything enormously
delete_indices
=
set
(
indices
.
flat
).
difference
(
set
(
keep_indices
.
flat
))
masks
=
[]
for
mp_idx
in
range
(
len
(
self
.
maps
)):
...
...
@@ -1834,5 +1832,5 @@ class TensorMaps(TensorFields):
if
__name__
==
'__main__'
:
# pragma: no cover
import
doctest
doctest
.
testmod
()
# doctest.run_docstring_examples(Tensor
Fields.__getitem__
, globals())
# doctest.run_docstring_examples(Tensor
Maps.cut
, globals())
# doctest.run_docstring_examples(AbstractNdarray._save_npz, globals())
tfields/lib/grid.py
View file @
31f2b698
import
numpy
as
np
import
functools
def
ensure_complex
(
*
base_vectors
):
...
...
@@ -95,8 +96,8 @@ def igrid(*base_vectors, **kwargs):
else
:
base_vectors
=
to_base_vectors
(
*
base_vectors
)
obj
=
np
.
empty
(
shape
=
(
reduce
(
lambda
x
,
y
:
x
*
y
,
map
(
len
,
base_vectors
)),
obj
=
np
.
empty
(
shape
=
(
functools
.
reduce
(
lambda
x
,
y
:
x
*
y
,
map
(
len
,
base_vectors
)),
len
(
base_vectors
)))
def
loop_rec
(
y
,
n_max
,
i
=
0
,
n
=
None
,
*
vals
):
...
...
tfields/mesh3D.py
View file @
31f2b698
...
...
@@ -508,7 +508,7 @@ class Mesh3D(tfields.TensorMaps):
# new vertex
new_face
.
append
(
len
(
vertices
))
vertices
=
np
.
append
(
vertices
,
[
map
(
float
,
item
)
],
[
[
float
(
x
)
for
x
in
item
]
],
axis
=
0
)
fields
=
[
np
.
append
(
field
,
np
.
full
((
1
,)
+
field
.
shape
[
1
:],
np
.
nan
),
...
...
@@ -649,6 +649,7 @@ class Mesh3D(tfields.TensorMaps):
to redo the same cut fast
Examples:
define the cut
>>> import numpy as np
>>> import tfields
>>> from sympy.abc import x,y,z
>>> cutExpr = x > 1.5
...
...
tfields/triangles3D.py
View file @
31f2b698
...
...
@@ -407,8 +407,12 @@ class Triangles3D(tfields.TensorFields):
# matrix vector product for matrices and vectors
barCoords
=
np
.
einsum
(
'...ji,...i'
,
self
.
_baricentric_matrix
,
ap
)
with
warnings
.
catch_warnings
():
# python2.7
warnings
.
filterwarnings
(
'ignore'
,
message
=
"invalid value encountered in divide"
)
warnings
.
filterwarnings
(
'ignore'
,
message
=
"divide by zero encountered in divide"
)
# python3.x
warnings
.
filterwarnings
(
'ignore'
,
message
=
"invalid value encountered in true_divide"
)
warnings
.
filterwarnings
(
'ignore'
,
message
=
"divide by zero encountered in true_divide"
)
barCoords
[:,
2
]
/=
delta
# allow devide by 0.
return
barCoords
...
...
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