Skip to content
GitLab
Menu
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
441fffe6
Commit
441fffe6
authored
Jun 25, 2021
by
Philipp Arras
Browse files
Compile forward derivative
parent
820803ac
Pipeline
#104399
passed with stages
in 28 minutes and 4 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/operators/jax_operator.py
View file @
441fffe6
...
...
@@ -55,13 +55,14 @@ class JaxOperator(Operator):
self
.
_target
=
makeDomain
(
target
)
self
.
_func
=
jax
.
jit
(
func
)
self
.
_vjp
=
jax
.
jit
(
lambda
x
:
jax
.
vjp
(
func
,
x
))
self
.
_fwd
=
jax
.
jit
(
lambda
x
,
y
:
jax
.
jvp
(
self
.
_func
,
(
x
,),
(
y
,))[
1
])
def
apply
(
self
,
x
):
from
..sugar
import
is_linearization
,
makeField
self
.
_check_input
(
x
)
if
is_linearization
(
x
):
res
,
bwd
=
self
.
_vjp
(
x
.
val
.
val
)
fwd
=
lambda
y
:
jax
.
jvp
(
self
.
_f
unc
,
(
x
.
val
.
val
,
),
(
y
,))[
1
]
fwd
=
lambda
y
:
self
.
_f
wd
(
x
.
val
.
val
,
y
)
jac
=
_JaxJacobian
(
self
.
_domain
,
self
.
_target
,
fwd
,
bwd
)
return
x
.
new
(
makeField
(
self
.
_target
,
_jax2np
(
res
)),
jac
)
return
makeField
(
self
.
_target
,
_jax2np
(
self
.
_func
(
x
.
val
)))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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