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
049e884b
Commit
049e884b
authored
2 years ago
by
hhakim
Browse files
Options
Downloads
Patches
Plain Diff
Add pyfaust LazyLinearOp support of matmul by a multidimensional numpy array (nd greater than 2).
parent
eda6ac6a
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/lazylinop.py
+21
-9
21 additions, 9 deletions
wrapper/python/pyfaust/lazylinop.py
with
21 additions
and
9 deletions
wrapper/python/pyfaust/lazylinop.py
+
21
−
9
View file @
049e884b
...
...
@@ -444,15 +444,16 @@ class LazyLinearOp(LinearOperator):
raise
TypeError
(
'
op must have a shape attribute
'
)
if
not
hasattr
(
op
,
'
ndim
'
):
raise
TypeError
(
'
op must have a ndim attribute
'
)
if
op
.
ndim
==
1
and
(
self
.
shape
[
0
]
if
swap
else
self
.
shape
[
1
])
!=
op
.
size
or
op
.
ndim
==
2
and
(
swap
and
op
.
shape
[
1
]
!=
self
.
shape
[
0
]
or
not
swap
and
self
.
shape
[
1
]
!=
op
.
shape
[
0
]):
if
op
.
ndim
==
1
and
(
self
.
shape
[
0
]
if
swap
else
self
.
shape
[
1
])
!=
\
op
.
size
or
op
.
ndim
>=
2
and
(
swap
and
op
.
shape
[
-
1
]
!=
self
.
shape
[
0
]
or
not
swap
and
self
.
shape
[
1
]
!=
op
.
shape
[
-
2
]):
raise
ValueError
(
'
dimensions must agree
'
)
def
__matmul__
(
self
,
op
):
...
...
@@ -473,6 +474,17 @@ class LazyLinearOp(LinearOperator):
if
isinstance
(
op
,
np
.
ndarray
)
or
issparse
(
op
):
if
op
.
ndim
==
1
and
self
.
_root_obj
is
not
None
:
res
=
self
.
lambdas
[
'
@
'
](
op
.
reshape
(
op
.
size
,
1
)).
ravel
()
elif
op
.
ndim
>
2
:
from
itertools
import
product
# op.ndim > 2
res
=
np
.
empty
((
*
op
.
shape
[:
-
2
],
self
.
shape
[
0
],
op
.
shape
[
-
1
]))
idl
=
[
list
(
range
(
op
.
shape
[
i
]))
for
i
in
range
(
op
.
ndim
-
2
)
]
for
t
in
product
(
*
idl
):
tr
=
(
*
t
,
slice
(
0
,
res
.
shape
[
-
2
]),
slice
(
0
,
res
.
shape
[
-
1
]))
to
=
(
*
t
,
slice
(
0
,
op
.
shape
[
-
2
]),
slice
(
0
,
op
.
shape
[
-
1
]))
R
=
self
.
lambdas
[
'
@
'
](
op
.
__getitem__
(
to
))
res
.
__setitem__
(
tr
,
R
)
# TODO: try to parallelize
else
:
res
=
self
.
lambdas
[
'
@
'
](
op
)
else
:
...
...
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