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
56cd389f
Commit
56cd389f
authored
May 22, 2018
by
Daniel Böckenhoff
Browse files
renaming
parent
c1bba9b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
tfields/core.py
View file @
56cd389f
...
...
@@ -846,21 +846,12 @@ class Tensors(AbstractNdarray):
# in current implementation Points3D use always cut method, never MeshMap
return
self
.
cut
(
cutOrMeshMap
,
coordSys
=
coordSys
),
None
def
to3DArrays
(
self
,
arrayShape
):
def
distances
(
self
,
other
,
**
kwargs
):
"""
Args:
arrayShape (tuple of lenght 3): how coordinates will be devided.
If you initialize Points3D with a grid of dimensions a,b,c and
want to retrieve the grid-points use (a,b,c)
"""
if
not
isinstance
(
arrayShape
,
tuple
):
raise
TypeError
(
"ArrayShape is not of type tuple but %s"
%
type
(
arrayShape
))
if
not
len
(
arrayShape
)
==
3
:
raise
TypeError
(
"ArrayShape is not of length 3 but %i"
%
len
(
arrayShape
))
return
self
.
T
.
reshape
((
3
,)
+
arrayShape
)
def
distances
(
self
,
other
,
metric
=
'euclidean'
,
**
kwargs
):
"""
other(array)
**kwargs:
... is forwarded to sp.spatial.distance.cdist
Examples:
>>> p = tfields.Tensors.grid((0, 2, 3j),
... (0, 2, 3j),
...
...
@@ -874,10 +865,21 @@ class Tensors(AbstractNdarray):
array([ 3.])
"""
return
sp
.
spatial
.
distance
.
cdist
(
self
,
other
,
metric
=
metric
,
**
kwargs
)
if
issubclass
(
type
(
other
),
Tensors
)
and
self
.
coordSys
!=
other
.
coordSys
:
other
=
other
.
copy
()
other
.
transform
(
self
.
coordSys
)
return
sp
.
spatial
.
distance
.
cdist
(
self
,
other
,
**
kwargs
)
def
minDistances
(
self
,
other
=
None
,
metric
=
'euclidean'
,
**
kwargs
):
def
minDistances
(
self
,
other
=
None
,
**
kwargs
):
"""
Args:
other(array or None)
**kwargs:
memory_saving (bool): for very large array comparisons
default False
... rest is forwarded to sp.spatial.distance.cdist
Examples:
>>> p = tfields.Tensors.grid((0, 2, 3),
... (0, 2, 3),
...
...
@@ -888,31 +890,31 @@ class Tensors(AbstractNdarray):
array([ 1. , 1. , 1. , 1. , 1.41421356,
1. , 1. , 1. , 1. ])
>>> dMin2 = p.minDistances(memory
S
aving=True)
>>> dMin2 = p.minDistances(memory
_s
aving=True)
>>> bool((dMin2 == dMin).all())
True
"""
memory
S
aving
=
kwargs
.
pop
(
'memory
S
aving'
,
False
)
memory
_s
aving
=
kwargs
.
pop
(
'memory
_s
aving'
,
False
)
if
other
is
not
None
:
raise
NotImplementedError
(
"Should be easy but make shure not to remove 0s"
)
else
:
if
other
is
None
:
other
=
self
else
:
raise
NotImplementedError
(
"Should be easy but make shure not to remove diagonal"
)
try
:
if
memory
S
aving
:
if
memory
_s
aving
:
raise
MemoryError
()
d
=
self
.
distances
(
other
,
metric
=
metric
,
**
kwargs
)
d
=
self
.
distances
(
other
,
**
kwargs
)
return
d
[
d
>
0
].
reshape
(
d
.
shape
[
0
],
-
1
).
min
(
axis
=
1
)
except
MemoryError
:
min
D
ists
=
np
.
empty
(
self
.
shape
[
0
])
min
_d
ists
=
np
.
empty
(
self
.
shape
[
0
])
for
i
,
point
in
enumerate
(
other
):
d
=
self
.
distances
([
point
],
metric
=
metric
,
**
kwargs
)
min
D
ists
[
i
]
=
d
[
d
>
0
].
reshape
(
-
1
).
min
()
return
min
D
ists
d
=
self
.
distances
([
point
],
**
kwargs
)
min
_d
ists
[
i
]
=
d
[
d
>
0
].
reshape
(
-
1
).
min
()
return
min
_d
ists
def
epsilon
N
eighbourhood
(
self
,
epsilon
):
def
epsilon
_n
eighbourhood
(
self
,
epsilon
):
"""
Returns:
indices for those sets of points that lie within epsilon around the other
...
...
@@ -923,7 +925,7 @@ class Tensors(AbstractNdarray):
... (0, 1, 2j),
... (0, 1, 2j))
>>> p = tfields.Tensors.merged(p, [[0.5, 0.5, 0.5]])
>>> [len(en) for en in p.epsilon
N
eighbourhood(0.9)]
>>> [len(en) for en in p.epsilon
_n
eighbourhood(0.9)]
[2, 2, 2, 2, 2, 2, 2, 2, 9]
"""
...
...
@@ -933,8 +935,6 @@ class Tensors(AbstractNdarray):
return
[
indices
[
die
]
for
die
in
distsInEpsilon
]
class
TensorFields
(
Tensors
):
"""
Discrete Tensor Field
...
...
Write
Preview
Supports
Markdown
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