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
pycodegen
pystencils_autodiff
Commits
30763da4
Commit
30763da4
authored
Aug 13, 2019
by
Stephan Seitz
Browse files
Merge commit '
70d68574
'
parents
1c2c660d
70d68574
Pipeline
#17172
failed with stage
in 4 minutes and 40 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/pystencils_autodiff/__init__.py
View file @
30763da4
...
...
@@ -4,8 +4,8 @@ import pystencils_autodiff.backends # NOQA
from
pystencils_autodiff._field_to_tensors
import
(
# NOQA
tf_constant_from_field
,
tf_placeholder_from_field
,
tf_scalar_variable_from_field
,
tf_variable_from_field
,
torch_tensor_from_field
)
from
pystencils_autodiff.adjoint_field
import
AdjointField
from
pystencils_autodiff.autodiff
import
(
from
pystencils_autodiff.
_
adjoint_field
import
AdjointField
from
pystencils_autodiff.
_
autodiff
import
(
AutoDiffAstPair
,
AutoDiffOp
,
create_backward_assignments
,
get_jacobian_of_assignments
)
__all__
=
[
'backends'
,
...
...
src/pystencils_autodiff/adjoint_field.py
→
src/pystencils_autodiff/
_
adjoint_field.py
View file @
30763da4
File moved
src/pystencils_autodiff/autodiff.py
→
src/pystencils_autodiff/
_
autodiff.py
View file @
30763da4
File moved
src/pystencils_autodiff/tensorflow.py
deleted
100644 → 0
View file @
1c2c660d
import
numpy
as
np
try
:
import
tensorflow
as
tf
except
ImportError
:
pass
def
tf_constant_from_field
(
field
,
init_val
=
0
):
return
tf
.
constant
(
init_val
,
dtype
=
field
.
dtype
.
numpy_dtype
,
shape
=
field
.
shape
,
name
=
field
.
name
+
'_constant'
)
def
tf_scalar_variable_from_field
(
field
,
init_val
,
constraint
=
None
):
var
=
tf
.
Variable
(
init_val
,
dtype
=
field
.
dtype
.
numpy_dtype
,
name
=
field
.
name
+
'_variable'
,
constraint
=
constraint
)
return
var
*
tf_constant_from_field
(
field
,
1
)
def
tf_variable_from_field
(
field
,
init_val
=
0
,
constraint
=
None
):
if
isinstance
(
init_val
,
(
int
,
float
)):
init_val
*=
np
.
ones
(
field
.
shape
,
field
.
dtype
.
numpy_dtype
)
return
tf
.
Variable
(
init_val
,
dtype
=
field
.
dtype
.
numpy_dtype
,
name
=
field
.
name
+
'_variable'
,
constraint
=
constraint
)
def
tf_placeholder_from_field
(
field
):
return
tf
.
placeholder
(
dtype
=
field
.
dtype
.
numpy_dtype
,
name
=
field
.
name
+
'_placeholder'
,
shape
=
field
.
shape
)
src/pystencils_autodiff/torch.py
deleted
100644 → 0
View file @
1c2c660d
# -*- coding: utf-8 -*-
#
# Copyright © 2019 Stephan Seitz <stephan.seitz@fau.de>
#
# Distributed under terms of the GPLv3 license.
"""
"""
import
numpy
as
np
try
:
import
torch
except
ImportError
:
pass
def
torch_tensor_from_field
(
field
,
init_val
=
0
,
cuda
=
True
,
requires_grad
=
False
):
if
isinstance
(
init_val
,
(
int
,
float
)):
init_val
*=
np
.
ones
(
field
.
shape
,
field
.
dtype
.
numpy_dtype
)
device
=
torch
.
device
(
'cuda'
if
cuda
else
'cpu'
)
return
torch
.
tensor
(
init_val
,
requires_grad
=
requires_grad
,
device
=
device
)
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