Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
arraycontext
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alexandru Fikl
arraycontext
Commits
696e6531
Commit
696e6531
authored
3 years ago
by
Kaushik Kulkarni
Browse files
Options
Downloads
Patches
Plain Diff
Avoids closure in LazilyCompilingFunctionCaller.__call__
parent
d3c82797
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
arraycontext/impl/pytato/compile.py
+24
-19
24 additions, 19 deletions
arraycontext/impl/pytato/compile.py
with
24 additions
and
19 deletions
arraycontext/impl/pytato/compile.py
+
24
−
19
View file @
696e6531
...
...
@@ -128,6 +128,26 @@ def _get_arg_id_to_arg_and_arg_id_to_descr(args: Tuple[Any, ...]
return
pmap
(
arg_id_to_arg
),
pmap
(
arg_id_to_descr
)
def
_get_f_placeholder_args
(
arg
,
iarg
,
arg_id_to_name
):
"""
Helper for :class:`LazilyCompilingFunctionCaller.__call__`. Returns the
placeholder version of an argument to
:attr:`LazilyCompilingFunctionCaller.f`.
"""
if
np
.
isscalar
(
arg
):
name
=
arg_id_to_name
[(
iarg
,)]
return
pt
.
make_placeholder
((),
np
.
dtype
(
arg
),
name
)
elif
is_array_container
(
arg
):
def
_rec_to_placeholder
(
keys
,
ary
):
name
=
arg_id_to_name
[(
iarg
,)
+
keys
]
return
pt
.
make_placeholder
(
ary
.
shape
,
ary
.
dtype
,
name
)
return
rec_keyed_map_array_container
(
_rec_to_placeholder
,
arg
)
else
:
raise
NotImplementedError
(
type
(
arg
))
@dataclass
class
LazilyCompilingFunctionCaller
:
"""
...
...
@@ -173,26 +193,11 @@ class LazilyCompilingFunctionCaller:
output_naming_map
=
{}
# input_naming_map: argument id to placeholder name in the generated
# pytato DAG.
input_naming_map
=
{}
def
to_placeholder
(
arg
,
pos
):
if
np
.
isscalar
(
arg
):
name
=
f
"
_actx_in_
{
pos
}
"
input_naming_map
[(
pos
,
)]
=
name
return
pt
.
make_placeholder
((),
np
.
dtype
(
arg
),
name
)
elif
is_array_container
(
arg
):
def
_rec_to_placeholder
(
keys
,
ary
):
name
=
(
f
"
_actx_in_
{
pos
}
_
"
+
_ary_container_key_stringifier
(
keys
))
input_naming_map
[(
pos
,)
+
keys
]
=
name
return
pt
.
make_placeholder
(
ary
.
shape
,
ary
.
dtype
,
name
)
return
rec_keyed_map_array_container
(
_rec_to_placeholder
,
arg
)
else
:
raise
NotImplementedError
(
type
(
arg
))
input_naming_map
=
{
arg_id
:
f
"
_actx_in_
{
_ary_container_key_stringifier
(
arg_id
)
}
"
for
arg_id
in
arg_id_to_arg
}
outputs
=
self
.
f
(
*
[
to
_placeholder
(
arg
,
iarg
)
outputs
=
self
.
f
(
*
[
_get_f
_placeholder
_args
(
arg
,
iarg
,
input_naming_map
)
for
iarg
,
arg
in
enumerate
(
args
)])
if
not
is_array_container
(
outputs
):
...
...
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