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
8bf5862c
Commit
8bf5862c
authored
Nov 22, 2018
by
Daniel Boeckenhoff
Browse files
base_vectors implemented
parent
ad417b24
Changes
1
Hide whitespace changes
Inline
Side-by-side
tfields/lib/grid.py
View file @
8bf5862c
...
...
@@ -14,7 +14,7 @@ def ensure_complex(*base_vectors):
return
base_vectors
def
to_base_vectors
(
*
base_vectors
):
def
_
to_base_vectors
(
*
base_vectors
):
"""
Transform tuples to arrays with np.mgrid
Args:
...
...
@@ -99,7 +99,7 @@ def igrid(*base_vectors, **kwargs):
obj
=
np
.
mgrid
[
base_vectors
]
obj
=
obj
.
reshape
(
obj
.
shape
[
0
],
-
1
).
T
else
:
base_vectors
=
to_base_vectors
(
*
base_vectors
)
base_vectors
=
_
to_base_vectors
(
*
base_vectors
)
obj
=
np
.
empty
(
shape
=
(
functools
.
reduce
(
lambda
x
,
y
:
x
*
y
,
map
(
len
,
base_vectors
)),
...
...
@@ -123,6 +123,37 @@ def igrid(*base_vectors, **kwargs):
return
obj
def
base_vectors
(
array
):
"""
describe the array in terms of base vectors
Inverse function of igrid
Examples:
>>> import tfields
>>> grid = tfields.igrid((3, 5, 5j))
>>> tfields.lib.grid.base_vectors(grid[:, 0])
(3.0, 5.0, 5j)
>>> grid2 = tfields.igrid((3, 5, 5j),
... (1, 2, 2j))
>>> grid_circle = tfields.igrid(*tfields.lib.grid.base_vectors(grid2))
>>> assert tfields.Tensors(grid_circle).equal(grid2)
"""
if
len
(
array
.
shape
)
==
1
:
values
=
sorted
(
set
(
array
))
spacing
=
complex
(
0
,
len
(
values
))
vmin
=
min
(
values
)
vmax
=
max
(
values
)
return
(
vmin
,
vmax
,
spacing
)
elif
len
(
array
.
shape
)
==
2
:
bases
=
[]
for
i
in
range
(
array
.
shape
[
1
]):
bases
.
append
(
base_vectors
(
array
[:,
i
]))
return
bases
else
:
raise
NotImplementedError
(
"Description yet only till rank 1"
)
def
swap_columns
(
array
,
*
index_tuples
):
"""
Args:
...
...
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