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
ift
NIFTy
Commits
29f141e5
Commit
29f141e5
authored
May 06, 2019
by
Lukas Platz
Browse files
add operator to multiply fields with matrices
parent
157402e6
Pipeline
#47790
passed with stages
in 8 minutes and 19 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nifty5/__init__.py
View file @
29f141e5
...
...
@@ -45,7 +45,8 @@ from .operators.block_diagonal_operator import BlockDiagonalOperator
from
.operators.outer_product_operator
import
OuterProduct
from
.operators.simple_linear_operators
import
(
VdotOperator
,
ConjugationOperator
,
Realizer
,
FieldAdapter
,
ducktape
,
GeometryRemover
,
NullOperator
)
FieldAdapter
,
ducktape
,
GeometryRemover
,
NullOperator
,
MatrixProductOperator
)
from
.operators.value_inserter
import
ValueInserter
from
.operators.energy_operators
import
(
EnergyOperator
,
GaussianEnergy
,
PoissonianEnergy
,
InverseGammaLikelihood
,
...
...
nifty5/operators/simple_linear_operators.py
View file @
29f141e5
...
...
@@ -22,6 +22,7 @@ from ..multi_domain import MultiDomain
from
..multi_field
import
MultiField
from
.endomorphic_operator
import
EndomorphicOperator
from
.linear_operator
import
LinearOperator
from
..
import
utilities
class
VdotOperator
(
LinearOperator
):
...
...
@@ -344,3 +345,36 @@ class _PartialExtractor(LinearOperator):
if
mode
==
self
.
TIMES
:
return
x
.
extract
(
self
.
_target
)
return
MultiField
.
from_dict
({
key
:
x
[
key
]
for
key
in
x
.
domain
.
keys
()})
class
MatrixProductOperator
(
EndomorphicOperator
):
"""Endomorphic matrix multiplication with input field.
Parameters
----------
domain: DomainTuple
Domain of the operator.
matrix:
Matrix of shape (field.shape, field.shape)
space: int, optional
The index of the subdomain on which the operator should act
"""
def
__init__
(
self
,
domain
,
matrix
,
space
=
None
):
self
.
_domain
=
DomainTuple
.
make
(
domain
)
self
.
_capability
=
self
.
TIMES
|
self
.
ADJOINT_TIMES
self
.
_space
=
utilities
.
infer_space
(
self
.
_domain
,
space
)
self
.
_mat
=
matrix
self
.
_mat_tr
=
matrix
.
transpose
()
def
apply
(
self
,
x
,
mode
):
self
.
_check_input
(
x
,
mode
)
res
=
x
.
to_global_data
()
if
mode
==
self
.
TIMES
:
res
=
self
.
_mat
.
dot
(
res
)
if
mode
==
self
.
ADJOINT_TIMES
:
res
=
self
.
_mat_tr
.
dot
(
res
)
return
Field
.
from_global_data
(
self
.
_domain
,
res
)
def
__repr__
(
self
):
return
"MatrixProductOperator"
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