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
9f9d2886
Commit
9f9d2886
authored
1 year ago
by
hhakim
Browse files
Options
Downloads
Patches
Plain Diff
Add a complementary unit test for pyfaust.poly.invm_multiply and reformat its docstring.
parent
211249d2
No related branches found
No related tags found
No related merge requests found
Pipeline
#891554
passed
1 year ago
Stage: test
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
wrapper/python/pyfaust/poly.py
+10
-10
10 additions, 10 deletions
wrapper/python/pyfaust/poly.py
wrapper/python/pyfaust/tests/TestPoly.py
+31
-0
31 additions, 0 deletions
wrapper/python/pyfaust/tests/TestPoly.py
with
41 additions
and
10 deletions
wrapper/python/pyfaust/poly.py
+
10
−
10
View file @
9f9d2886
...
@@ -709,19 +709,19 @@ def invm_multiply(A, B, rel_err=1e-6, tradeoff='time', max_K=np.inf, dev='cpu',
...
@@ -709,19 +709,19 @@ def invm_multiply(A, B, rel_err=1e-6, tradeoff='time', max_K=np.inf, dev='cpu',
of
A
and
B
.
of
A
and
B
.
Returns
:
Returns
:
The
np
.
ndarray
which
is
the
approximate
action
of
matrix
inverse
of
A
on
B
.
The
np
.
ndarray
which
is
the
approximate
action
of
matrix
inverse
of
A
on
B
.
Example
:
Example
:
>>>
import
numpy
as
np
>>>
import
numpy
as
np
>>>
from
scipy.sparse
import
random
>>>
from
scipy.sparse
import
random
>>>
from
pyfaust.poly
import
invm_multiply
>>>
from
pyfaust.poly
import
invm_multiply
>>>
from
numpy.linalg
import
norm
,
inv
>>>
from
numpy.linalg
import
norm
,
inv
>>>
np
.
random
.
seed
(
42
)
# for reproducibility
>>>
np
.
random
.
seed
(
42
)
# for reproducibility
>>>
A
=
random
(
64
,
64
,
.
1
,
format
=
'
csr
'
)
>>>
A
=
random
(
64
,
64
,
.
1
,
format
=
'
csr
'
)
>>>
A
=
A
@A.T
>>>
A
=
A
@A.T
>>>
B
=
np
.
random
.
rand
(
A
.
shape
[
1
],
2
)
>>>
B
=
np
.
random
.
rand
(
A
.
shape
[
1
],
2
)
>>>
A_inv_B
=
invm_multiply
(
A
,
B
,
rel_err
=
1e-2
,
max_K
=
2048
)
>>>
A_inv_B
=
invm_multiply
(
A
,
B
,
rel_err
=
1e-2
,
max_K
=
2048
)
>>>
A_inv_B_ref
=
inv
(
A
.
toarray
())
@B
>>>
A_inv_B_ref
=
inv
(
A
.
toarray
())
@B
>>>
print
(
"
err:
"
,
norm
(
A_inv_B
-
A_inv_B_ref
)
/
norm
(
A_inv_B
))
>>>
print
(
"
err:
"
,
norm
(
A_inv_B
-
A_inv_B_ref
)
/
norm
(
A_inv_B
))
err
:
0.027283169722939017
err
:
0.027283169722939017
...
...
This diff is collapsed.
Click to expand it.
wrapper/python/pyfaust/tests/TestPoly.py
+
31
−
0
View file @
9f9d2886
...
@@ -241,3 +241,34 @@ class TestPoly(unittest.TestCase):
...
@@ -241,3 +241,34 @@ class TestPoly(unittest.TestCase):
self
.
assertRaisesRegex
(
ValueError
,
axis_err
,
_cat
,
(
F1
,
self
.
assertRaisesRegex
(
ValueError
,
axis_err
,
_cat
,
(
F1
,
S1
.
toarray
()),
S1
.
toarray
()),
2
)
2
)
def
test_invm_multiply
(
self
):
print
(
"
Test invm_multiply()
"
)
from
scipy.sparse
import
random
try
:
from
pyfaust.poly
import
invm_multiply
from
numpy.linalg
import
inv
np
.
random
.
seed
(
42
)
# for reproducibility
A
=
random
(
64
,
64
,
.
1
,
format
=
'
csr
'
)
A
=
A
@A.T
B
=
np
.
random
.
rand
(
A
.
shape
[
1
],
2
)
# tradeoff=='time' is already tested in docstrings
A_inv_B
=
invm_multiply
(
A
,
B
,
rel_err
=
1e-2
,
max_K
=
2048
,
tradeoff
=
'
memory
'
)
A_inv_B_ref
=
inv
(
A
.
toarray
())
@B
self
.
assertTrue
(
norm
(
A_inv_B
-
A_inv_B_ref
)
/
norm
(
A_inv_B
)
<=
0.0273
)
# test error cases
self
.
assertRaisesRegex
(
ValueError
,
'
poly_meth must be 1 or 2
'
,
invm_multiply
,
A
,
B
,
poly_meth
=
3
)
self
.
assertRaisesRegex
(
ValueError
,
"
tradeoff must be
'
memory
'
or
'
time
'"
,
invm_multiply
,
A
,
B
,
tradeoff
=
'
anything
'
)
# test singular A error case
sA
=
csr_matrix
(
A
)
sA
[
-
2
:,
:]
=
0
self
.
assertRaisesRegex
(
Exception
,
"
a <= 0 error: A is a singular matrix or its
"
"
spectrum contains negative values.
"
,
invm_multiply
,
A
,
B
)
except
ImportError
:
print
(
"
invm_multiply is only avaiable in experimental packages.
"
)
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