Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
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
Show more breadcrumbs
pycodegen
pystencils
Commits
b35ee506
Commit
b35ee506
authored
4 months ago
by
Frederik Hennig
Browse files
Options
Downloads
Patches
Plain Diff
Fix linting. Fix docs on mixing types. Add docs on default types.
parent
ac0dfad3
No related branches found
No related tags found
1 merge request
!443
Extended Support for Typing in the Symbolic Toolbox
Pipeline
#72618
passed
4 months ago
Stage: Code Quality
Stage: Unit Tests
Stage: legacy_test
Stage: docs
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
docs/source/reference/WorkingWithTypes.md
+28
-8
28 additions, 8 deletions
docs/source/reference/WorkingWithTypes.md
src/pystencils/field.py
+1
-1
1 addition, 1 deletion
src/pystencils/field.py
with
29 additions
and
9 deletions
docs/source/reference/WorkingWithTypes.md
+
28
−
8
View file @
b35ee506
...
...
@@ -23,8 +23,30 @@ import pystencils as ps
import sympy as sp
```
## Changing the Default Data Types
The pystencils code generator defines two default data types:
-
The default
*numeric type*
, which is applied to all numerical computations that are not
otherwise explicitly typed; the default is
`float64`
.
-
The default
*index type*
, which is used for all loop and field index calculations; the default is
`int64`
.
These can be modified by setting the
{any}
`default_dtype <CreateKernelConfig.default_dtype>`
and
{any}
`index_type <CreateKernelConfig.index_dtype>`
options of the code generator configuration:
```
{code-cell} ipython3
cfg = ps.CreateKernelConfig()
cfg.default_dtype = "float32"
cfg.index_dtype = "int32"
```
Modifying these will change the way types for
[
untyped symbols
](
#untyped-symbols
)
and
[
dynamically typed expressions
](
#dynamic-typing
)
are computed.
## Setting the Types of Fields and Symbols
(untyped-symbols)=
### Untyped Symbols
Symbols used inside a kernel are most commonly created using
...
...
@@ -65,6 +87,7 @@ str(f.dtype), str(g.dtype)
When using
`Field.create_generic`
or
`Field.create_fixed_size`
, on the other hand,
you can set the data type via the
`dtype`
keyword argument.
(dynamic-typing)=
### Dynamically Typed Symbols and Fields
Apart from explicitly setting data types,
...
...
@@ -92,9 +115,11 @@ if any type conflicts arise, it will terminate with an error.
Still, there are cases where you want to combine subexpressions of different types;
maybe you need to compute geometric information from loop counters or other integers,
or you are doing mixed-precision numerical computations.
In these cases, you might have to
1.
Introduce explicit type casts when values move from one type context to another;
2.
Annotate expressions with a specific data type to ensure computations are performed in that type.
In these cases, you might have to introduce explicit type casts when values move from one type context to another.
<!-- 2. Annotate expressions with a specific data type to ensure computations are performed in that type.
TODO: See #97 (https://i10git.cs.fau.de/pycodegen/pystencils/-/issues/97)
-->
(type_casts)=
### Type Casts
...
...
@@ -116,11 +141,6 @@ and then introduce a runtime cast to the target type.
That target type must comply with the type computed for the outer expression,
which the cast is embedded in.
(explicit_expression_types)=
### Setting Explicit Types for Expressions
## Understanding the pystencils Type Inference System
To correctly apply varying data types to pystencils kernels, it is important to understand
...
...
This diff is collapsed.
Click to expand it.
src/pystencils/field.py
+
1
−
1
View file @
b35ee506
...
...
@@ -7,7 +7,7 @@ import pickle
import
re
from
enum
import
Enum
from
itertools
import
chain
from
typing
import
List
,
Optional
,
Sequence
,
Set
,
Tuple
,
Union
from
typing
import
List
,
Optional
,
Sequence
,
Set
,
Tuple
from
warnings
import
warn
import
numpy
as
np
...
...
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