Skip to content
Snippets Groups Projects
Commit 8c4d934b authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Fix documentation of functions

parent 54725998
No related branches found
No related tags found
1 merge request!425Refactor and Improve Documentation
Pipeline #70112 passed
......@@ -123,4 +123,3 @@ API Documentation
:members:
.. automodule:: pystencils.backend.functions
:members:
......@@ -9,6 +9,20 @@ Every supported function might require handling logic in the following modules:
- If very special typing rules apply, a case in `typification.Typifier`.
In most cases, typification of function applications will require no special handling.
.. autoclass:: PsFunction
:members:
.. autoclass:: MathFunctions
:members:
:undoc-members:
.. autoclass:: PsMathFunction
:members:
.. autoclass:: CFunction
:members:
"""
from __future__ import annotations
......@@ -23,6 +37,31 @@ if TYPE_CHECKING:
from .ast.expressions import PsExpression
class PsFunction(ABC):
"""Base class for functions occuring in the IR"""
__match_args__ = ("name", "arg_count")
def __init__(self, name: str, num_args: int):
self._name = name
self._num_args = num_args
@property
def name(self) -> str:
"""Name of this function."""
return self._name
@property
def arg_count(self) -> int:
"Number of arguments this function takes"
return self._num_args
def __call__(self, *args: PsExpression) -> Any:
from .ast.expressions import PsCall
return PsCall(self, args)
class MathFunctions(Enum):
"""Mathematical functions supported by the backend.
......@@ -55,29 +94,30 @@ class MathFunctions(Enum):
self.num_args = num_args
class PsFunction(ABC):
"""Base class for functions occuring in the IR"""
class PsMathFunction(PsFunction):
"""Homogenously typed mathematical functions."""
__match_args__ = ("name", "arg_count")
__match_args__ = ("func",)
def __init__(self, name: str, num_args: int):
self._name = name
self._num_args = num_args
def __init__(self, func: MathFunctions) -> None:
super().__init__(func.function_name, func.num_args)
self._func = func
@property
def name(self) -> str:
"""Name of this function."""
return self._name
def func(self) -> MathFunctions:
return self._func
@property
def arg_count(self) -> int:
"Number of arguments this function takes"
return self._num_args
def __str__(self) -> str:
return f"{self._func.function_name}"
def __call__(self, *args: PsExpression) -> Any:
from .ast.expressions import PsCall
def __eq__(self, other: object) -> bool:
if not isinstance(other, PsMathFunction):
return False
return PsCall(self, args)
return self._func == other._func
def __hash__(self) -> int:
return hash(self._func)
class CFunction(PsFunction):
......@@ -134,29 +174,3 @@ class CFunction(PsFunction):
def __repr__(self) -> str:
return f"CFunction({self._name}, {self._param_types}, {self._return_type})"
class PsMathFunction(PsFunction):
"""Homogenously typed mathematical functions."""
__match_args__ = ("func",)
def __init__(self, func: MathFunctions) -> None:
super().__init__(func.function_name, func.num_args)
self._func = func
@property
def func(self) -> MathFunctions:
return self._func
def __str__(self) -> str:
return f"{self._func.function_name}"
def __eq__(self, other: object) -> bool:
if not isinstance(other, PsMathFunction):
return False
return self._func == other._func
def __hash__(self) -> int:
return hash(self._func)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment