Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NIFTy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ift
NIFTy
Commits
ea476444
Commit
ea476444
authored
6 years ago
by
Martin Reinecke
Browse files
Options
Downloads
Patches
Plain Diff
tweaks
parent
c0916fb8
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
nifty5/operators/linear_interpolation.py
+19
-19
19 additions, 19 deletions
nifty5/operators/linear_interpolation.py
with
19 additions
and
19 deletions
nifty5/operators/linear_interpolation.py
+
19
−
19
View file @
ea476444
...
@@ -18,8 +18,7 @@
...
@@ -18,8 +18,7 @@
from
__future__
import
absolute_import
,
division
,
print_function
from
__future__
import
absolute_import
,
division
,
print_function
from
numpy
import
(
abs
,
arange
,
array
,
int64
,
mgrid
,
prod
,
ravel
,
import
numpy
as
np
ravel_multi_index
,
zeros
)
from
scipy.sparse
import
coo_matrix
from
scipy.sparse
import
coo_matrix
from
scipy.sparse.linalg
import
aslinearoperator
from
scipy.sparse.linalg
import
aslinearoperator
...
@@ -37,10 +36,11 @@ class LinearInterpolator(LinearOperator):
...
@@ -37,10 +36,11 @@ class LinearInterpolator(LinearOperator):
Multilinear interpolation for points in an RGSpace
Multilinear interpolation for points in an RGSpace
:param domain:
:param domain:
RGSpace
:param positions:
:param positions:
positions at which to interpolate
positions at which to interpolate
Field with UnstructuredDomain, shape (dim, ndata)
Field with UnstructuredDomain, shape (dim, ndata)
positions that are not within the RGSpace
get
wrapped
positions that are not within the RGSpace
are
wrapped
according to periodic boundary conditions
according to periodic boundary conditions
"""
"""
self
.
_domain
=
makeDomain
(
domain
)
self
.
_domain
=
makeDomain
(
domain
)
...
@@ -51,31 +51,31 @@ class LinearInterpolator(LinearOperator):
...
@@ -51,31 +51,31 @@ class LinearInterpolator(LinearOperator):
def
_build_mat
(
self
,
positions
,
N_points
):
def
_build_mat
(
self
,
positions
,
N_points
):
ndim
=
positions
.
shape
[
0
]
ndim
=
positions
.
shape
[
0
]
mg
=
mgrid
[(
slice
(
0
,
2
),)
*
ndim
]
mg
=
np
.
mgrid
[(
slice
(
0
,
2
),)
*
ndim
]
mg
=
array
(
list
(
map
(
ravel
,
mg
)))
mg
=
np
.
array
(
list
(
map
(
np
.
ravel
,
mg
)))
dist
=
[]
dist
=
[]
for
dom
in
self
.
domain
:
for
dom
in
self
.
domain
:
if
isinstance
(
dom
,
RGSpace
):
if
not
isinstance
(
dom
,
RGSpace
):
dist
.
append
(
list
(
dom
.
distances
))
else
:
raise
TypeError
raise
TypeError
dist
=
array
(
dist
).
reshape
((
-
1
,
1
))
dist
.
append
(
list
(
dom
.
distances
))
dist
=
np
.
array
(
dist
).
reshape
((
-
1
,
1
))
pos
=
positions
/
dist
pos
=
positions
/
dist
excess
=
pos
-
pos
.
astype
(
int64
)
excess
=
pos
-
pos
.
astype
(
np
.
int64
)
pos
=
pos
.
astype
(
int64
)
pos
=
pos
.
astype
(
np
.
int64
)
max_index
=
array
(
self
.
domain
.
shape
).
reshape
(
-
1
,
1
)
max_index
=
np
.
array
(
self
.
domain
.
shape
).
reshape
(
-
1
,
1
)
data
=
zeros
((
len
(
mg
[
0
]),
N_points
))
data
=
np
.
zeros
((
len
(
mg
[
0
]),
N_points
))
ii
=
zeros
((
len
(
mg
[
0
]),
N_points
),
dtype
=
int64
)
ii
=
np
.
zeros
((
len
(
mg
[
0
]),
N_points
),
dtype
=
np
.
int64
)
jj
=
zeros
((
len
(
mg
[
0
]),
N_points
),
dtype
=
int64
)
jj
=
np
.
zeros
((
len
(
mg
[
0
]),
N_points
),
dtype
=
np
.
int64
)
for
i
in
range
(
len
(
mg
[
0
])):
for
i
in
range
(
len
(
mg
[
0
])):
factor
=
prod
(
abs
(
1
-
mg
[:,
i
].
reshape
((
-
1
,
1
))
-
excess
),
axis
=
0
)
factor
=
np
.
prod
(
np
.
abs
(
1
-
mg
[:,
i
].
reshape
((
-
1
,
1
))
-
excess
),
axis
=
0
)
data
[
i
,
:]
=
factor
data
[
i
,
:]
=
factor
fromi
=
(
pos
+
mg
[:,
i
].
reshape
((
-
1
,
1
)))
%
max_index
fromi
=
(
pos
+
mg
[:,
i
].
reshape
((
-
1
,
1
)))
%
max_index
ii
[
i
,
:]
=
arange
(
N_points
)
ii
[
i
,
:]
=
np
.
arange
(
N_points
)
jj
[
i
,
:]
=
ravel_multi_index
(
fromi
,
self
.
domain
.
shape
)
jj
[
i
,
:]
=
np
.
ravel_multi_index
(
fromi
,
self
.
domain
.
shape
)
self
.
_mat
=
coo_matrix
((
data
.
reshape
(
-
1
),
self
.
_mat
=
coo_matrix
((
data
.
reshape
(
-
1
),
(
ii
.
reshape
(
-
1
),
jj
.
reshape
(
-
1
))),
(
ii
.
reshape
(
-
1
),
jj
.
reshape
(
-
1
))),
(
N_points
,
prod
(
self
.
domain
.
shape
)))
(
N_points
,
np
.
prod
(
self
.
domain
.
shape
)))
self
.
_mat
=
aslinearoperator
(
self
.
_mat
)
self
.
_mat
=
aslinearoperator
(
self
.
_mat
)
def
apply
(
self
,
x
,
mode
):
def
apply
(
self
,
x
,
mode
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment