Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
faust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Admin message
GitLab upgrade completed. Current version is 17.11.4.
Show more breadcrumbs
faust group
faust
Commits
ce3b81d3
Commit
ce3b81d3
authored
2 years ago
by
hhakim
Browse files
Options
Downloads
Patches
Plain Diff
Add unit tests for pyfaust.LazLinearOp.
parent
18daf38a
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
wrapper/python/pyfaust/tests/TestLazyLinearOp.py
+161
-0
161 additions, 0 deletions
wrapper/python/pyfaust/tests/TestLazyLinearOp.py
with
161 additions
and
0 deletions
wrapper/python/pyfaust/tests/TestLazyLinearOp.py
0 → 100644
+
161
−
0
View file @
ce3b81d3
import
unittest
import
pyfaust
as
pf
from
pyfaust.lazylinop
import
LazyLinearOp
import
numpy.linalg
as
LA
import
numpy
as
np
class
TestLazyLinearOpFaust
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
lop
=
LazyLinearOp
.
create
(
pf
.
rand
(
10
,
15
))
self
.
lopA
=
self
.
lop
.
toarray
()
self
.
lop2
=
LazyLinearOp
.
create
(
pf
.
rand
(
10
,
15
))
self
.
lop2A
=
self
.
lop2
.
toarray
()
self
.
lop3
=
LazyLinearOp
.
create
(
pf
.
rand
(
15
,
10
))
self
.
lop3A
=
self
.
lop3
.
toarray
()
def
test_shape
(
self
):
self
.
assertEqual
(
self
.
lop
.
shape
,
self
.
lop
.
eval
().
shape
)
def
test_ndim
(
self
):
self
.
assertEqual
(
self
.
lop
.
ndim
,
2
)
def
test_transp
(
self
):
lopT
=
self
.
lop
.
T
self
.
assertAlmostEqual
(
LA
.
norm
(
lopT
.
toarray
()
-
self
.
lopA
.
T
),
0
)
lopT
=
self
.
lop
.
transpose
()
self
.
assertAlmostEqual
(
LA
.
norm
(
lopT
.
toarray
()
-
self
.
lopA
.
T
),
0
)
def
test_conj
(
self
):
lopC
=
self
.
lop
.
conj
()
self
.
assertAlmostEqual
(
LA
.
norm
(
lopC
.
toarray
()
-
self
.
lopA
.
conj
()),
0
)
def
test_adjoint
(
self
):
lopH
=
self
.
lop
.
H
self
.
assertAlmostEqual
(
LA
.
norm
(
lopH
.
toarray
()
-
self
.
lopA
.
conj
().
T
),
0
)
lopH
=
self
.
lop
.
getH
()
self
.
assertAlmostEqual
(
LA
.
norm
(
lopH
.
toarray
()
-
self
.
lopA
.
conj
().
T
),
0
)
def
test_add
(
self
):
ladd
=
self
.
lop
+
self
.
lop2
self
.
assertAlmostEqual
(
LA
.
norm
(
ladd
.
toarray
()
-
(
self
.
lopA
+
self
.
lop2A
)),
0
)
M
=
np
.
random
.
rand
(
*
self
.
lop
.
shape
)
ladd2
=
self
.
lop
+
M
self
.
assertTrue
(
isinstance
(
ladd2
,
LazyLinearOp
))
self
.
assertAlmostEqual
(
LA
.
norm
(
ladd2
.
toarray
()
-
(
self
.
lopA
+
M
)),
0
)
def
test_iadd
(
self
):
self
.
assertRaises
(
NotImplementedError
,
self
.
lop
.
__iadd__
,
self
.
lop2
)
def
test_radd
(
self
):
M
=
np
.
random
.
rand
(
*
self
.
lop
.
shape
)
ladd2
=
M
+
self
.
lop
self
.
assertTrue
(
isinstance
(
ladd2
,
LazyLinearOp
))
self
.
assertAlmostEqual
(
LA
.
norm
(
ladd2
.
toarray
()
-
(
M
+
self
.
lopA
)),
0
)
def
test_sub
(
self
):
lsub
=
self
.
lop
-
self
.
lop2
self
.
assertAlmostEqual
(
LA
.
norm
(
lsub
.
toarray
()
-
(
self
.
lopA
-
self
.
lop2A
)),
0
)
M
=
np
.
random
.
rand
(
*
self
.
lop
.
shape
)
lsub2
=
self
.
lop
-
M
self
.
assertTrue
(
isinstance
(
lsub2
,
LazyLinearOp
))
self
.
assertAlmostEqual
(
LA
.
norm
(
lsub2
.
toarray
()
-
(
self
.
lopA
-
M
)),
0
)
def
test_rsub
(
self
):
M
=
np
.
random
.
rand
(
*
self
.
lop
.
shape
)
lsub2
=
M
-
self
.
lop
self
.
assertTrue
(
isinstance
(
lsub2
,
LazyLinearOp
))
self
.
assertAlmostEqual
(
LA
.
norm
(
lsub2
.
toarray
()
-
(
M
-
self
.
lopA
)),
0
)
def
test_isub
(
self
):
self
.
assertRaises
(
NotImplementedError
,
self
.
lop
.
__isub__
,
self
.
lop2
)
def
test_matmul_dot_matvec
(
self
):
lmul
=
self
.
lop
@
self
.
lop3
self
.
assertAlmostEqual
(
LA
.
norm
(
lmul
.
toarray
()
-
(
self
.
lopA
@
self
.
lop3A
)),
0
)
lmul
=
self
.
lop
.
dot
(
self
.
lop3
)
self
.
assertAlmostEqual
(
LA
.
norm
(
lmul
.
toarray
()
-
(
self
.
lopA
@
self
.
lop3A
)),
0
)
M
=
np
.
random
.
rand
(
self
.
lop
.
shape
[
1
],
15
)
lmul2
=
self
.
lop
@
M
self
.
assertTrue
(
isinstance
(
lmul2
,
np
.
ndarray
))
self
.
assertAlmostEqual
(
LA
.
norm
(
lmul2
-
(
self
.
lopA
@
M
)),
0
)
lmul2
=
self
.
lop
.
matvec
(
M
[:,
0
])
self
.
assertTrue
(
isinstance
(
lmul2
,
np
.
ndarray
))
self
.
assertAlmostEqual
(
LA
.
norm
(
lmul2
-
(
self
.
lopA
@
M
[:,
0
])),
0
)
def
test_rmatmul
(
self
):
M
=
np
.
random
.
rand
(
15
,
self
.
lop
.
shape
[
0
])
lmul2
=
M
@
self
.
lop
self
.
assertTrue
(
isinstance
(
lmul2
,
np
.
ndarray
))
self
.
assertAlmostEqual
(
LA
.
norm
(
lmul2
-
(
M
@
self
.
lopA
)),
0
)
def
test_imatmul
(
self
):
self
.
assertRaises
(
NotImplementedError
,
self
.
lop
.
__imatmul__
,
self
.
lop2
)
def
test_mul
(
self
):
v
=
np
.
random
.
rand
(
self
.
lop
.
shape
[
1
])
lmul2
=
self
.
lop
*
v
self
.
assertTrue
(
isinstance
(
lmul2
,
LazyLinearOp
))
self
.
assertAlmostEqual
(
LA
.
norm
(
lmul2
.
toarray
()
-
(
self
.
lopA
*
v
)),
0
)
v
=
np
.
random
.
rand
(
1
,
self
.
lop
.
shape
[
1
])
lmul2
=
self
.
lop
*
v
self
.
assertTrue
(
isinstance
(
lmul2
,
LazyLinearOp
))
self
.
assertAlmostEqual
(
LA
.
norm
(
lmul2
.
toarray
()
-
(
self
.
lopA
*
v
)),
0
)
s
=
np
.
random
.
rand
(
1
,
1
)[
0
,
0
]
lmul2
=
self
.
lop
*
s
self
.
assertTrue
(
isinstance
(
lmul2
,
LazyLinearOp
))
self
.
assertAlmostEqual
(
LA
.
norm
(
lmul2
.
toarray
()
-
(
self
.
lopA
*
s
)),
0
)
def
test_rmul
(
self
):
v
=
np
.
random
.
rand
(
self
.
lop
.
shape
[
1
])
lmul2
=
v
*
self
.
lop
self
.
assertTrue
(
isinstance
(
lmul2
,
LazyLinearOp
))
self
.
assertAlmostEqual
(
LA
.
norm
(
lmul2
.
toarray
()
-
(
v
*
self
.
lopA
)),
0
)
v
=
np
.
random
.
rand
(
1
,
self
.
lop
.
shape
[
1
])
lmul2
=
v
*
self
.
lop
self
.
assertTrue
(
isinstance
(
lmul2
,
LazyLinearOp
))
self
.
assertAlmostEqual
(
LA
.
norm
(
lmul2
.
toarray
()
-
(
v
*
self
.
lopA
)),
0
)
s
=
np
.
random
.
rand
(
1
,
1
)[
0
,
0
]
lmul2
=
s
*
self
.
lop
self
.
assertTrue
(
isinstance
(
lmul2
,
LazyLinearOp
))
self
.
assertAlmostEqual
(
LA
.
norm
(
lmul2
.
toarray
()
-
(
s
*
self
.
lopA
)),
0
)
def
test_concatenate
(
self
):
lcat
=
self
.
lop
.
concatenate
(
self
.
lop2
,
axis
=
0
)
self
.
assertAlmostEqual
(
LA
.
norm
(
lcat
.
toarray
()
-
np
.
vstack
((
self
.
lopA
,
self
.
lop2A
))),
0
)
lcat
=
self
.
lop
.
concatenate
(
self
.
lop2
,
axis
=
1
)
self
.
assertAlmostEqual
(
LA
.
norm
(
lcat
.
toarray
()
-
np
.
hstack
((
self
.
lopA
,
self
.
lop2A
))),
0
)
def
test_chain_ops
(
self
):
lchain
=
self
.
lop
+
self
.
lop2
lchain
=
lchain
@
self
.
lop3
lchain
=
2
*
lchain
v
=
np
.
random
.
rand
(
lchain
.
shape
[
1
])
lchain
=
lchain
*
v
lchain
=
lchain
.
concatenate
(
self
.
lop3
,
axis
=
0
)
mat_ref
=
np
.
vstack
(((
2
*
(
self
.
lopA
+
self
.
lop2A
)
@
self
.
lop3A
)
*
v
,
self
.
lop3A
))
self
.
assertAlmostEqual
(
LA
.
norm
(
lchain
.
toarray
()
-
mat_ref
),
0
)
if
'
__main__
'
==
__name__
:
unittest
.
main
()
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