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
3ccde7e7
Commit
3ccde7e7
authored
1 year ago
by
hhakim
Browse files
Options
Downloads
Patches
Plain Diff
Extend TestPoly._test_poly to cases where L is a Faust.
parent
8be6abe9
No related branches found
No related tags found
No related merge requests found
Pipeline
#885292
passed
1 year ago
Stage: test
Changes
1
Pipelines
10
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wrapper/python/pyfaust/tests/TestPoly.py
+48
-40
48 additions, 40 deletions
wrapper/python/pyfaust/tests/TestPoly.py
with
48 additions
and
40 deletions
wrapper/python/pyfaust/tests/TestPoly.py
+
48
−
40
View file @
3ccde7e7
import
unittest
from
pyfaust.poly
import
basis
,
poly
,
expm_multiply
from
pyfaust
import
isFaust
from
numpy.random
import
randint
import
numpy
as
np
from
numpy.linalg
import
norm
...
...
@@ -100,50 +101,57 @@ class TestPoly(unittest.TestCase):
self
.
_test_poly_impl
(
'
py
'
)
def
_test_poly_impl
(
self
,
impl
):
from
pyfaust
import
Faust
d
=
self
.
d
L
=
self
.
L
K
=
self
.
K
density
=
self
.
density
F
=
basis
(
L
,
K
,
'
chebyshev
'
,
dev
=
self
.
dev
,
impl
=
impl
).
astype
(
self
.
dtype
)
coeffs
=
np
.
random
.
rand
(
K
+
1
).
astype
(
self
.
dtype
)
G
=
poly
(
coeffs
,
F
,
impl
=
impl
)
# Test polynomial as Faust
poly_ref
=
np
.
zeros
((
d
,
d
))
for
i
,
c
in
enumerate
(
coeffs
[:]):
poly_ref
+=
c
*
F
[
d
*
i
:(
i
+
1
)
*
d
,
:]
self
.
assertAlmostEqual
((
G
-
poly_ref
).
norm
(),
0
)
# Test polynomial as array
GM
=
poly
(
coeffs
,
F
.
toarray
(),
impl
=
impl
)
self
.
assertTrue
(
isinstance
(
GM
,
np
.
ndarray
))
err
=
norm
(
GM
-
poly_ref
.
toarray
())
/
norm
(
poly_ref
.
toarray
())
self
.
assertLessEqual
(
err
,
1e-6
)
# Test polynomial-vector product
x
=
np
.
random
.
rand
(
F
.
shape
[
1
],
1
).
astype
(
L
.
dtype
)
# Three ways to do (not all as efficient as each other)
Fx1
=
poly
(
coeffs
,
F
,
dev
=
self
.
dev
,
impl
=
impl
)
@x
Fx2
=
poly
(
coeffs
,
F
@x
,
dev
=
self
.
dev
,
impl
=
impl
)
Fx3
=
poly
(
coeffs
,
F
,
X
=
x
,
dev
=
self
.
dev
,
impl
=
impl
)
err
=
norm
(
Fx1
-
Fx2
)
/
norm
(
Fx1
)
self
.
assertLessEqual
(
err
,
1e-6
)
self
.
assertTrue
(
np
.
allclose
(
Fx1
,
Fx3
))
# Test polynomial-matrix product
X
=
np
.
random
.
rand
(
F
.
shape
[
1
],
18
).
astype
(
L
.
dtype
)
FX1
=
poly
(
coeffs
,
F
,
dev
=
self
.
dev
,
impl
=
impl
)
@X
FX2
=
poly
(
coeffs
,
F
@X
,
dev
=
self
.
dev
,
impl
=
impl
)
FX3
=
poly
(
coeffs
,
F
,
X
=
X
,
dev
=
self
.
dev
,
impl
=
impl
)
err
=
norm
(
FX1
-
FX2
)
/
norm
(
FX1
)
self
.
assertLessEqual
(
err
,
1e-6
)
self
.
assertTrue
(
np
.
allclose
(
FX2
,
FX3
))
# Test creating the polynomial basis on the fly
G2
=
poly
(
coeffs
,
'
chebyshev
'
,
L
,
impl
=
impl
)
self
.
assertAlmostEqual
((
G
-
G2
).
norm
(),
0
)
GX
=
poly
(
coeffs
,
'
chebyshev
'
,
L
,
X
=
X
,
dev
=
self
.
dev
,
impl
=
impl
)
err
=
norm
(
FX1
-
GX
)
/
norm
(
FX1
)
self
.
assertLessEqual
(
err
,
1e-6
)
# Test polynomial-matrix product with arbitrary T0
F_
=
basis
(
L
,
K
,
'
chebyshev
'
,
dev
=
self
.
dev
,
T0
=
csr_matrix
(
X
),
impl
=
impl
)
GT0eqX
=
poly
(
coeffs
,
F_
,
dev
=
self
.
dev
,
impl
=
impl
).
toarray
()
self
.
assertTrue
(
np
.
allclose
(
GT0eqX
,
FX1
))
for
L
in
[
self
.
L
,
Faust
(
self
.
L
)]:
if
impl
==
'
native
'
and
isFaust
(
L
):
# native impl doesn't handle Faust L
self
.
assertRaises
(
TypeError
,
basis
,
L
,
K
,
'
chebyshev
'
,
dev
=
self
.
dev
,
impl
=
impl
)
continue
F
=
basis
(
L
,
K
,
'
chebyshev
'
,
dev
=
self
.
dev
,
impl
=
impl
).
astype
(
self
.
dtype
)
self
.
assertEqual
(
F
.
shape
[
0
],
(
K
+
1
)
*
L
.
shape
[
0
])
coeffs
=
np
.
random
.
rand
(
K
+
1
).
astype
(
self
.
dtype
)
G
=
poly
(
coeffs
,
F
,
impl
=
impl
)
# Test polynomial as Faust
poly_ref
=
np
.
zeros
((
d
,
d
))
for
i
,
c
in
enumerate
(
coeffs
[:]):
poly_ref
+=
c
*
F
[
d
*
i
:(
i
+
1
)
*
d
,
:]
self
.
assertAlmostEqual
((
G
-
poly_ref
).
norm
(),
0
)
# Test polynomial as array
GM
=
poly
(
coeffs
,
F
.
toarray
(),
impl
=
impl
)
self
.
assertTrue
(
isinstance
(
GM
,
np
.
ndarray
))
err
=
norm
(
GM
-
poly_ref
.
toarray
())
/
norm
(
poly_ref
.
toarray
())
self
.
assertLessEqual
(
err
,
1e-6
)
# Test polynomial-vector product
x
=
np
.
random
.
rand
(
F
.
shape
[
1
],
1
).
astype
(
L
.
dtype
)
# Three ways to do (not all as efficient as each other)
Fx1
=
poly
(
coeffs
,
F
,
dev
=
self
.
dev
,
impl
=
impl
)
@x
Fx2
=
poly
(
coeffs
,
F
@x
,
dev
=
self
.
dev
,
impl
=
impl
)
Fx3
=
poly
(
coeffs
,
F
,
X
=
x
,
dev
=
self
.
dev
,
impl
=
impl
)
err
=
norm
(
Fx1
-
Fx2
)
/
norm
(
Fx1
)
self
.
assertLessEqual
(
err
,
1e-6
)
self
.
assertTrue
(
np
.
allclose
(
Fx1
,
Fx3
))
# Test polynomial-matrix product
X
=
np
.
random
.
rand
(
F
.
shape
[
1
],
18
).
astype
(
L
.
dtype
)
FX1
=
poly
(
coeffs
,
F
,
dev
=
self
.
dev
,
impl
=
impl
)
@X
FX2
=
poly
(
coeffs
,
F
@X
,
dev
=
self
.
dev
,
impl
=
impl
)
FX3
=
poly
(
coeffs
,
F
,
X
=
X
,
dev
=
self
.
dev
,
impl
=
impl
)
err
=
norm
(
FX1
-
FX2
)
/
norm
(
FX1
)
self
.
assertLessEqual
(
err
,
1e-6
)
self
.
assertTrue
(
np
.
allclose
(
FX2
,
FX3
))
# Test creating the polynomial basis on the fly
G2
=
poly
(
coeffs
,
'
chebyshev
'
,
L
,
impl
=
impl
)
self
.
assertAlmostEqual
((
G
-
G2
).
norm
(),
0
)
GX
=
poly
(
coeffs
,
'
chebyshev
'
,
L
,
X
=
X
,
dev
=
self
.
dev
,
impl
=
impl
)
err
=
norm
(
FX1
-
GX
)
/
norm
(
FX1
)
self
.
assertLessEqual
(
err
,
1e-6
)
# Test polynomial-matrix product with arbitrary T0
F_
=
basis
(
L
,
K
,
'
chebyshev
'
,
dev
=
self
.
dev
,
T0
=
csr_matrix
(
X
),
impl
=
impl
)
GT0eqX
=
poly
(
coeffs
,
F_
,
dev
=
self
.
dev
,
impl
=
impl
).
toarray
()
self
.
assertTrue
(
np
.
allclose
(
GT0eqX
,
FX1
))
def
test_expm_multiply
(
self
):
print
(
"
Test expm_multiply()
"
)
...
...
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