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
071c85db
Commit
071c85db
authored
Nov 23, 2018
by
Daniel Boeckenhoff
Browse files
passing rtol to base_vectors in grdi
parent
8bf5862c
Changes
2
Hide whitespace changes
Inline
Side-by-side
tfields/core.py
View file @
071c85db
...
...
@@ -934,25 +934,36 @@ class Tensors(AbstractNdarray):
"""
return
any
(
self
.
equal
(
other
,
return_bool
=
False
).
all
(
1
))
def
indices
(
self
,
tensor
):
def
indices
(
self
,
tensor
,
rtol
=
None
,
atol
=
None
,
early_stopping
=
False
):
"""
Returns:
list of int: indices of tensor occuring
"""
x
,
y
=
np
.
asarray
(
self
),
np
.
asarray
(
tensor
)
if
rtol
is
None
and
atol
is
None
:
equal_method
=
np
.
array_equal
else
:
equal_method
=
lambda
a
,
b
:
np
.
isclose
(
a
,
b
,
rtol
=
rtol
,
atol
=
atol
)
indices
=
[]
for
i
,
p
in
enumerate
(
self
):
if
all
(
p
==
tensor
):
for
i
,
p
in
enumerate
(
x
):
if
equal_method
(
p
,
y
).
all
(
):
indices
.
append
(
i
)
if
early_stopping
:
break
return
indices
def
index
(
self
,
tensor
):
def
index
(
self
,
tensor
,
**
kwargs
):
"""
Args:
tensor
Returns:
int: index of tensor occuring
Raises:
ValueError: Multiple occurences
use early_stopping=True if first entry should be returned
"""
indices
=
self
.
indices
(
tensor
)
indices
=
self
.
indices
(
tensor
,
**
kwargs
)
print
(
indices
)
if
not
indices
:
return
None
if
len
(
indices
)
==
1
:
...
...
tfields/lib/grid.py
View file @
071c85db
...
...
@@ -123,7 +123,7 @@ def igrid(*base_vectors, **kwargs):
return
obj
def
base_vectors
(
array
):
def
base_vectors
(
array
,
rtol
=
None
,
atol
=
None
):
"""
describe the array in terms of base vectors
Inverse function of igrid
...
...
@@ -141,6 +141,17 @@ def base_vectors(array):
"""
if
len
(
array
.
shape
)
==
1
:
values
=
sorted
(
set
(
array
))
if
rtol
is
not
None
and
atol
is
not
None
:
duplicates
=
set
([])
for
v1
,
v2
in
tfields
.
lib
.
util
.
pairwise
(
values
):
if
np
.
isclose
(
v1
,
v2
,
rtol
=
rtol
,
atol
=
atol
):
duplicates
.
add
(
v2
)
values
=
values
.
difference
(
duplicates
)
# round to given absolute precision
n_digits
=
int
(
abs
(
np
.
log10
(
atol
)))
+
1
values
=
{
round
(
v
,
n_digits
)
for
v
in
values
}
elif
rtol
is
not
None
or
atol
is
not
None
:
raise
ValueError
(
"rtol and atol arguments only come in pairs."
)
spacing
=
complex
(
0
,
len
(
values
))
vmin
=
min
(
values
)
vmax
=
max
(
values
)
...
...
@@ -148,7 +159,7 @@ def base_vectors(array):
elif
len
(
array
.
shape
)
==
2
:
bases
=
[]
for
i
in
range
(
array
.
shape
[
1
]):
bases
.
append
(
base_vectors
(
array
[:,
i
]))
bases
.
append
(
base_vectors
(
array
[:,
i
]
,
rtol
=
rtol
,
atol
=
atol
))
return
bases
else
:
raise
NotImplementedError
(
"Description yet only till rank 1"
)
...
...
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