Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
ab20d935
Commit
ab20d935
authored
Jun 20, 2018
by
Philipp Arras
Browse files
Fix Scalar multiplication
parent
5b696445
Pipeline
#31476
failed with stages
in 4 minutes and 39 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nifty5/models/model.py
View file @
ab20d935
...
...
@@ -57,7 +57,7 @@ class Model(NiftyMetaBase()):
def
__mul__
(
self
,
other
):
if
isinstance
(
other
,
(
float
,
int
)):
return
ScalarMul
(
self
.
_position
,
other
,
self
)
return
ScalarMul
(
other
,
self
)
if
isinstance
(
other
,
Model
):
return
Mul
.
make
(
self
,
other
)
raise
NotImplementedError
...
...
@@ -127,21 +127,19 @@ class Add(Model):
class
ScalarMul
(
Model
):
def
__init__
(
self
,
position
,
factor
,
op
):
super
(
ScalarMul
,
self
).
__init__
(
position
)
def
__init__
(
self
,
factor
,
op
):
super
(
ScalarMul
,
self
).
__init__
(
op
.
position
)
if
not
isinstance
(
factor
,
(
float
,
int
)):
raise
TypeError
if
not
isinstance
(
op
,
Model
):
raise
TypeError
self
.
_op
=
op
.
at
(
position
)
self
.
_op
=
op
self
.
_factor
=
factor
self
.
_value
=
self
.
_factor
*
self
.
_op
.
value
self
.
_gradient
=
self
.
_factor
*
self
.
_op
.
gradient
def
at
(
self
,
position
):
return
self
.
__class__
(
position
,
self
.
_factor
,
self
.
_op
)
return
self
.
__class__
(
self
.
_factor
,
self
.
_op
.
at
(
position
)
)
class
LinearModel
(
Model
):
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment