Skip to content
Snippets Groups Projects

Improved Source File and Code Structure Modelling

Merged Frederik Hennig requested to merge fhennig/source-files into master
All threads resolved!
Viewing commit 9aba6a1e
Next
Show latest version
5 files
+ 392
267
Preferences
Compare changes
Files
5
@@ -4,6 +4,7 @@ from abc import ABC, abstractmethod
@@ -4,6 +4,7 @@ from abc import ABC, abstractmethod
import numpy as np
import numpy as np
import sympy as sp
import sympy as sp
from functools import reduce
from functools import reduce
 
from warnings import warn
from pystencils import Field
from pystencils import Field
from pystencils.codegen import Kernel
from pystencils.codegen import Kernel
@@ -252,7 +253,13 @@ class SfgBasicComposer(SfgIComposer):
@@ -252,7 +253,13 @@ class SfgBasicComposer(SfgIComposer):
func = SfgFunction(name, tree)
func = SfgFunction(name, tree)
self._ctx.add_function(func)
self._ctx.add_function(func)
def function(self, name: str, return_type: UserTypeSpec = void):
def function(
 
self,
 
name: str,
 
returns: UserTypeSpec = void,
 
inline: bool = False,
 
return_type: UserTypeSpec | None = None,
 
):
"""Add a function.
"""Add a function.
The syntax of this function adder uses a chain of two calls to mimic C++ syntax:
The syntax of this function adder uses a chain of two calls to mimic C++ syntax:
@@ -265,12 +272,23 @@ class SfgBasicComposer(SfgIComposer):
@@ -265,12 +272,23 @@ class SfgBasicComposer(SfgIComposer):
The function body is constructed via sequencing (see `make_sequence`).
The function body is constructed via sequencing (see `make_sequence`).
"""
"""
 
if return_type is not None:
 
warn(
 
"The parameter `return_type` to `function()` is deprecated and will be removed by version 0.1. "
 
"Setting it will override the value of the `returns` parameter. "
 
"Use `returns` instead.",
 
FutureWarning,
 
)
 
returns = return_type
 
if self._ctx.get_function(name) is not None:
if self._ctx.get_function(name) is not None:
raise ValueError(f"Function {name} already exists.")
raise ValueError(f"Function {name} already exists.")
def sequencer(*args: SequencerArg):
def sequencer(*args: SequencerArg):
tree = make_sequence(*args)
tree = make_sequence(*args)
func = SfgFunction(name, tree, return_type=create_type(return_type))
func = SfgFunction(
 
name, tree, return_type=create_type(returns), inline=inline
 
)
self._ctx.add_function(func)
self._ctx.add_function(func)
return sequencer
return sequencer