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
Show more breadcrumbs
faust group
faust
Commits
9713ce7c
Commit
9713ce7c
authored
2 years ago
by
hhakim
Browse files
Options
Downloads
Patches
Plain Diff
In pyfaust.lazylinop fix eye when m==None and add doc for eye and diag.
parent
2a4493c2
No related branches found
No related tags found
No related merge requests found
Pipeline
#834125
skipped
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wrapper/python/pyfaust/lazylinop.py
+79
-2
79 additions, 2 deletions
wrapper/python/pyfaust/lazylinop.py
with
79 additions
and
2 deletions
wrapper/python/pyfaust/lazylinop.py
+
79
−
2
View file @
9713ce7c
...
@@ -1089,6 +1089,45 @@ def eye(m, n=None, k=0, dtype='float'):
...
@@ -1089,6 +1089,45 @@ def eye(m, n=None, k=0, dtype='float'):
positive integer for a diagonal above.
positive integer for a diagonal above.
dtype: (str) data type of the LazyLinearOp.
dtype: (str) data type of the LazyLinearOp.
Example:
>>>
from
pyfaust.lazylinop
import
eye
>>>
le1
=
eye
(
5
)
>>>
le1
<
5
x5
LazyLinearOp
with
unspecified
dtype
>
>>>
le1
.
toarray
()
array
([[
1.
,
0.
,
0.
,
0.
,
0.
],
[
0.
,
1.
,
0.
,
0.
,
0.
],
[
0.
,
0.
,
1.
,
0.
,
0.
],
[
0.
,
0.
,
0.
,
1.
,
0.
],
[
0.
,
0.
,
0.
,
0.
,
1.
]])
>>>
le2
=
eye
(
5
,
2
)
>>>
le2
<
5
x2
LazyLinearOp
with
unspecified
dtype
>
>>>
le2
.
toarray
()
array
([[
1.
,
0.
],
[
0.
,
1.
],
[
0.
,
0.
],
[
0.
,
0.
],
[
0.
,
0.
]])
>>>
le3
=
eye
(
5
,
3
,
1
)
>>>
le3
<
5
x3
LazyLinearOp
with
unspecified
dtype
>
>>>
le3
.
toarray
()
array
([[
0.
,
1.
,
0.
],
[
0.
,
0.
,
1.
],
[
0.
,
0.
,
0.
],
[
0.
,
0.
,
0.
],
[
0.
,
0.
,
0.
]])
>>>
le4
=
eye
(
5
,
3
,
-
1
)
>>>
le4
<
5
x3
LazyLinearOp
with
unspecified
dtype
>
>>>
le4
.
toarray
()
array
([[
0.
,
0.
,
0.
],
[
1.
,
0.
,
0.
],
[
0.
,
1.
,
0.
],
[
0.
,
0.
,
1.
],
[
0.
,
0.
,
0.
]])
<b>See also:</b> scipy.sparse.eye.
<b>See also:</b> scipy.sparse.eye.
"""
"""
def
matmat
(
x
,
m
,
n
,
k
):
def
matmat
(
x
,
m
,
n
,
k
):
...
@@ -1100,7 +1139,6 @@ def eye(m, n=None, k=0, dtype='float'):
...
@@ -1100,7 +1139,6 @@ def eye(m, n=None, k=0, dtype='float'):
x_1dim
=
True
x_1dim
=
True
else
:
else
:
x_1dim
=
False
x_1dim
=
False
n
=
n
if
n
is
not
None
else
m
minmn
=
min
(
m
,
n
)
minmn
=
min
(
m
,
n
)
x_islop
=
isLazyLinearOp
(
x
)
x_islop
=
isLazyLinearOp
(
x
)
if
k
<
0
:
if
k
<
0
:
...
@@ -1133,12 +1171,13 @@ def eye(m, n=None, k=0, dtype='float'):
...
@@ -1133,12 +1171,13 @@ def eye(m, n=None, k=0, dtype='float'):
if
x_1dim
:
if
x_1dim
:
mul
=
mul
.
reshape
(
-
1
)
mul
=
mul
.
reshape
(
-
1
)
return
mul
return
mul
n
=
n
if
n
is
not
None
else
m
return
LazyLinearOperator
((
m
,
n
),
matmat
=
lambda
x
:
matmat
(
x
,
m
,
n
,
k
),
return
LazyLinearOperator
((
m
,
n
),
matmat
=
lambda
x
:
matmat
(
x
,
m
,
n
,
k
),
rmatmat
=
lambda
x
:
matmat
(
x
,
n
,
m
,
-
k
))
rmatmat
=
lambda
x
:
matmat
(
x
,
n
,
m
,
-
k
))
def
diag
(
v
,
k
=
0
):
def
diag
(
v
,
k
=
0
):
"""
"""
Construct a diagonal LazyLinearOp.
Construct
s
a diagonal LazyLinearOp.
Args:
Args:
v: a 1-D numpy array for the diagonal.
v: a 1-D numpy array for the diagonal.
...
@@ -1147,6 +1186,44 @@ def diag(v, k=0):
...
@@ -1147,6 +1186,44 @@ def diag(v, k=0):
Returns:
Returns:
The diagonal LazyLinearOperator.
The diagonal LazyLinearOperator.
Example:
>>>
from
pyfaust.lazylinop
import
diag
>>>
import
numpy
as
np
>>>
v
=
np
.
arange
(
1
,
6
)
>>>
v
array
([
1
,
2
,
3
,
4
,
5
])
>>>
ld1
=
diag
(
v
)
>>>
ld1
<
5
x5
LazyLinearOp
with
unspecified
dtype
>
>>>
ld1
.
toarray
()
array
([[
1.
,
0.
,
0.
,
0.
,
0.
],
[
0.
,
2.
,
0.
,
0.
,
0.
],
[
0.
,
0.
,
3.
,
0.
,
0.
],
[
0.
,
0.
,
0.
,
4.
,
0.
],
[
0.
,
0.
,
0.
,
0.
,
5.
]])
>>>
ld2
=
diag
(
v
,
-
2
)
>>>
ld2
<
7
x7
LazyLinearOp
with
unspecified
dtype
>
>>>
ld2
.
toarray
()
array
([[
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
],
[
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
],
[
1.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
],
[
0.
,
2.
,
0.
,
0.
,
0.
,
0.
,
0.
],
[
0.
,
0.
,
3.
,
0.
,
0.
,
0.
,
0.
],
[
0.
,
0.
,
0.
,
4.
,
0.
,
0.
,
0.
],
[
0.
,
0.
,
0.
,
0.
,
5.
,
0.
,
0.
]])
>>>
ld3
=
diag
(
v
,
2
)
>>>
ld3
<
7
x7
LazyLinearOp
with
unspecified
dtype
>
>>>
ld3
.
toarray
()
array
([[
0.
,
0.
,
1.
,
0.
,
0.
,
0.
,
0.
],
[
0.
,
0.
,
0.
,
2.
,
0.
,
0.
,
0.
],
[
0.
,
0.
,
0.
,
0.
,
3.
,
0.
,
0.
],
[
0.
,
0.
,
0.
,
0.
,
0.
,
4.
,
0.
],
[
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
5.
],
[
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
],
[
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
]])
"""
"""
if
v
.
ndim
>
1
or
v
.
ndim
==
0
:
if
v
.
ndim
>
1
or
v
.
ndim
==
0
:
raise
ValueError
(
"
v must be a 1-dim vector.
"
)
raise
ValueError
(
"
v must be a 1-dim vector.
"
)
...
...
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