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
c88eadc1
Commit
c88eadc1
authored
5 years ago
by
Philipp Arras
Browse files
Options
Downloads
Patches
Plain Diff
Fix MatrixProductOperator
parent
93b3fdd9
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!368
Add more automatic checks for operators
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
nifty5/operators/simple_linear_operators.py
+9
-10
9 additions, 10 deletions
nifty5/operators/simple_linear_operators.py
test/test_operators/test_adjoint.py
+12
-0
12 additions, 0 deletions
test/test_operators/test_adjoint.py
with
21 additions
and
10 deletions
nifty5/operators/simple_linear_operators.py
+
9
−
10
View file @
c88eadc1
...
@@ -364,20 +364,19 @@ class MatrixProductOperator(EndomorphicOperator):
...
@@ -364,20 +364,19 @@ class MatrixProductOperator(EndomorphicOperator):
`dot()` and `transpose()` in the style of numpy arrays.
`dot()` and `transpose()` in the style of numpy arrays.
"""
"""
def
__init__
(
self
,
domain
,
matrix
):
def
__init__
(
self
,
domain
,
matrix
):
self
.
_domain
=
domain
self
.
_domain
=
DomainTuple
.
make
(
domain
)
shp
=
self
.
_domain
.
shape
if
len
(
shp
)
>
1
:
raise
TypeError
(
'
Only 1D-domain supported yet.
'
)
if
matrix
.
shape
!=
(
*
shp
,
*
shp
):
raise
ValueError
self
.
_capability
=
self
.
TIMES
|
self
.
ADJOINT_TIMES
self
.
_capability
=
self
.
TIMES
|
self
.
ADJOINT_TIMES
self
.
_mat
=
matrix
self
.
_mat
=
matrix
self
.
_mat_tr
=
matrix
.
transpose
()
self
.
_mat_tr
=
matrix
.
transpose
()
.
conjugate
()
def
apply
(
self
,
x
,
mode
):
def
apply
(
self
,
x
,
mode
):
self
.
_check_input
(
x
,
mode
)
self
.
_check_input
(
x
,
mode
)
res
=
x
.
to_global_data
()
res
=
x
.
to_global_data
()
if
mode
==
self
.
TIMES
:
f
=
self
.
_mat
.
dot
if
mode
==
self
.
TIMES
else
self
.
_mat_tr
.
dot
res
=
self
.
_mat
.
dot
(
res
)
res
=
f
(
res
)
if
mode
==
self
.
ADJOINT_TIMES
:
res
=
self
.
_mat_tr
.
dot
(
res
)
return
Field
.
from_global_data
(
self
.
_domain
,
res
)
return
Field
.
from_global_data
(
self
.
_domain
,
res
)
def
__repr__
(
self
):
return
"
MatrixProductOperator
"
This diff is collapsed.
Click to expand it.
test/test_operators/test_adjoint.py
+
12
−
0
View file @
c88eadc1
...
@@ -297,6 +297,18 @@ def testValueInserter(sp, seed):
...
@@ -297,6 +297,18 @@ def testValueInserter(sp, seed):
ift
.
extra
.
consistency_check
(
op
)
ift
.
extra
.
consistency_check
(
op
)
@pmp
(
'
sp
'
,
[
ift
.
RGSpace
(
10
)])
@pmp
(
'
seed
'
,
[
12
,
3
])
def
testMatrixProductOperator
(
sp
,
seed
):
np
.
random
.
seed
(
seed
)
mat
=
np
.
random
.
randn
(
*
sp
.
shape
,
*
sp
.
shape
)
op
=
ift
.
MatrixProductOperator
(
sp
,
mat
)
ift
.
extra
.
consistency_check
(
op
)
mat
=
mat
+
1j
*
np
.
random
.
randn
(
*
sp
.
shape
,
*
sp
.
shape
)
op
=
ift
.
MatrixProductOperator
(
sp
,
mat
)
ift
.
extra
.
consistency_check
(
op
)
@pmp
(
'
seed
'
,
[
12
,
3
])
@pmp
(
'
seed
'
,
[
12
,
3
])
def
testPartialExtractor
(
seed
):
def
testPartialExtractor
(
seed
):
np
.
random
.
seed
(
seed
)
np
.
random
.
seed
(
seed
)
...
...
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