Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pystencils_autodiff
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
Model registry
Operate
Environments
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
pycodegen
pystencils_autodiff
Commits
dc5023b5
Commit
dc5023b5
authored
5 years ago
by
Stephan Seitz
Browse files
Options
Downloads
Patches
Plain Diff
Add test for ugly hack
parent
f280ee36
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#18973
failed
5 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/pystencils_autodiff/field_tensor_conversion.py
+11
-2
11 additions, 2 deletions
src/pystencils_autodiff/field_tensor_conversion.py
with
11 additions
and
2 deletions
src/pystencils_autodiff/field_tensor_conversion.py
+
11
−
2
View file @
dc5023b5
...
...
@@ -2,6 +2,7 @@ import numpy as np
import
sympy
from
pystencils
import
Field
from
pystencils.field
import
FieldType
class
_WhatEverClass
:
...
...
@@ -10,9 +11,13 @@ class _WhatEverClass:
class
ArrayWithIndexDimensions
:
def
__init__
(
self
,
array
,
index_dimensions
):
def
__init__
(
self
,
array
,
index_dimensions
,
field_type
=
FieldType
.
GENERIC
):
self
.
array
=
array
self
.
index_dimensions
=
index_dimensions
self
.
field_type
=
field_type
def
__array__
(
self
):
return
self
.
array
...
...
@@ -34,9 +39,11 @@ def _torch_tensor_to_numpy_shim(tensor):
def
create_field_from_array_like
(
field_name
,
maybe_array
):
if
isinstance
(
maybe_array
,
ArrayWithIndexDimensions
):
index_dimensions
=
maybe_array
.
index_dimensions
field_type
=
maybe_array
.
field_type
maybe_array
=
maybe_array
.
array
else
:
index_dimensions
=
0
field_type
=
FieldType
.
GENERIC
try
:
import
torch
...
...
@@ -48,7 +55,9 @@ def create_field_from_array_like(field_name, maybe_array):
if
isinstance
(
maybe_array
,
torch
.
Tensor
):
maybe_array
=
_torch_tensor_to_numpy_shim
(
maybe_array
)
return
Field
.
create_from_numpy_array
(
field_name
,
maybe_array
,
index_dimensions
)
field
=
Field
.
create_from_numpy_array
(
field_name
,
maybe_array
,
index_dimensions
)
field
.
field_type
=
field_type
return
field
def
coerce_to_field
(
field_name
,
array_like
):
...
...
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