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
b1adf2ae
Commit
b1adf2ae
authored
4 years ago
by
Michael Kuron
Browse files
Options
Downloads
Patches
Plain Diff
RNG node cleanup
parent
b49316af
No related branches found
No related tags found
1 merge request
!194
Make the RNG node behave more like a regular node
Pipeline
#28505
passed
4 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pystencils/rng.py
+5
-6
5 additions, 6 deletions
pystencils/rng.py
with
5 additions
and
6 deletions
pystencils/rng.py
+
5
−
6
View file @
b1adf2ae
...
@@ -19,7 +19,7 @@ def _get_rng_template(name, data_type, num_vars):
...
@@ -19,7 +19,7 @@ def _get_rng_template(name, data_type, num_vars):
return
template
return
template
def
_get_rng_code
(
template
,
dialect
,
vector_instruction_set
,
args
,
dim
,
result_symbols
):
def
_get_rng_code
(
template
,
dialect
,
vector_instruction_set
,
args
,
result_symbols
):
if
dialect
==
'
cuda
'
or
(
dialect
==
'
c
'
and
vector_instruction_set
is
None
):
if
dialect
==
'
cuda
'
or
(
dialect
==
'
c
'
and
vector_instruction_set
is
None
):
return
template
.
format
(
parameters
=
'
,
'
.
join
(
str
(
a
)
for
a
in
args
),
return
template
.
format
(
parameters
=
'
,
'
.
join
(
str
(
a
)
for
a
in
args
),
result_symbols
=
result_symbols
)
result_symbols
=
result_symbols
)
...
@@ -44,14 +44,14 @@ class RNGBase(CustomCodeNode):
...
@@ -44,14 +44,14 @@ class RNGBase(CustomCodeNode):
if
dim
<
3
:
if
dim
<
3
:
coordinates
.
append
(
0
)
coordinates
.
append
(
0
)
self
.
_args
=
sp
.
sympify
([
time_step
,
*
coordinates
,
*
keys
])
self
.
result_symbols
=
tuple
(
TypedSymbol
(
f
'
random_
{
self
.
id
}
_
{
i
}
'
,
self
.
_data_type
)
self
.
result_symbols
=
tuple
(
TypedSymbol
(
f
'
random_
{
self
.
id
}
_
{
i
}
'
,
self
.
_data_type
)
for
i
in
range
(
self
.
_num_vars
))
for
i
in
range
(
self
.
_num_vars
))
symbols_read
=
set
.
union
(
*
[
s
p
.
sympify
(
s
)
.
atoms
(
sp
.
Symbol
)
for
s
in
list
(
keys
)
+
coordinates
+
[
time_step
]
])
symbols_read
=
set
.
union
(
*
[
s
.
atoms
(
sp
.
Symbol
)
for
s
in
self
.
args
])
super
().
__init__
(
""
,
symbols_read
=
symbols_read
,
symbols_defined
=
self
.
result_symbols
)
super
().
__init__
(
""
,
symbols_read
=
symbols_read
,
symbols_defined
=
self
.
result_symbols
)
self
.
headers
=
[
f
'"
{
self
.
_name
}
_rand.h
"'
]
self
.
headers
=
[
f
'"
{
self
.
_name
}
_rand.h
"'
]
self
.
_args
=
sp
.
sympify
([
time_step
,
*
coordinates
,
*
keys
])
self
.
_dim
=
dim
RNGBase
.
id
+=
1
RNGBase
.
id
+=
1
@property
@property
...
@@ -60,8 +60,7 @@ class RNGBase(CustomCodeNode):
...
@@ -60,8 +60,7 @@ class RNGBase(CustomCodeNode):
def
get_code
(
self
,
dialect
,
vector_instruction_set
):
def
get_code
(
self
,
dialect
,
vector_instruction_set
):
template
=
_get_rng_template
(
self
.
_name
,
self
.
_data_type
,
self
.
_num_vars
)
template
=
_get_rng_template
(
self
.
_name
,
self
.
_data_type
,
self
.
_num_vars
)
return
_get_rng_code
(
template
,
dialect
,
vector_instruction_set
,
return
_get_rng_code
(
template
,
dialect
,
vector_instruction_set
,
self
.
args
,
self
.
result_symbols
)
self
.
args
,
self
.
_dim
,
self
.
result_symbols
)
def
__repr__
(
self
):
def
__repr__
(
self
):
return
(
"
,
"
.
join
([
'
{}
'
]
*
self
.
_num_vars
)
+
"
\\
leftarrow {}RNG
"
).
format
(
*
self
.
result_symbols
,
return
(
"
,
"
.
join
([
'
{}
'
]
*
self
.
_num_vars
)
+
"
\\
leftarrow {}RNG
"
).
format
(
*
self
.
result_symbols
,
...
...
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