Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[next]: extend embedded implementation of premap() #1501

Merged
merged 51 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
7691834
WIP remap modes
egparedes Mar 15, 2024
b4199a9
Grab ruff version from constraints
egparedes Mar 15, 2024
5e0b16b
WIP adding test case
egparedes Mar 19, 2024
5034dee
WIP start testing
egparedes Mar 22, 2024
ae4b29e
Merge branch 'main' into extend_remap_embedded_tt
egparedes Mar 22, 2024
ffa3b19
Fix syntax
egparedes Mar 22, 2024
a22f59f
Undo related syntax changes
egparedes Mar 22, 2024
f1cf1a7
More undoings
egparedes Mar 22, 2024
9d9df0a
Final eve.utils reset
egparedes Mar 22, 2024
41b8fd3
Fixes
egparedes Mar 22, 2024
602bf68
Refactorings
egparedes Mar 22, 2024
8d5360b
Add proper domain indexing
egparedes Mar 22, 2024
cd913bc
Add IndexerCallable and refactor relative_ranges_to_domain functionality
egparedes Mar 26, 2024
3fe3932
Merge branch 'main' into extend_remap_embedded
egparedes Mar 26, 2024
451ec3a
Fixes WIP
egparedes Apr 4, 2024
5277218
Merge branch 'main' into extend_remap_embedded
egparedes Apr 4, 2024
14e0672
Fixes
egparedes Apr 4, 2024
e8f41aa
Introduce premap kinds (WIP)
egparedes Apr 10, 2024
5b62b38
Merge branch 'main' into extend_remap_embedded
egparedes Apr 10, 2024
ddbfc64
FIxes
egparedes Apr 11, 2024
21f832d
More fixes and add unit tests
egparedes Apr 17, 2024
d9cba38
Fix current tests
egparedes Apr 17, 2024
4e69784
Fixes
egparedes Apr 18, 2024
31d8e38
Fix doctest
egparedes Apr 18, 2024
ea1f2e9
Fix docstrings and typings in eve.utils
egparedes Apr 18, 2024
66ed142
Update src/gt4py/next/embedded/nd_array_field.py
egparedes Apr 18, 2024
0b27399
Update src/gt4py/next/common.py
egparedes Apr 22, 2024
1b1fc90
Update src/gt4py/next/common.py
egparedes Apr 22, 2024
607f349
Update src/gt4py/next/embedded/nd_array_field.py
egparedes Apr 22, 2024
5a41ca6
Address reviewer feedback
egparedes Apr 22, 2024
01a2dc8
Merge branch 'main' into extend_remap_embedded
egparedes Apr 24, 2024
e8a5c42
Merge branch 'main' into extend_remap_embedded
egparedes Apr 29, 2024
8d4cf62
Refactor identity_connectivity
egparedes Apr 29, 2024
469d914
Fix and test new sub domain creation feature
egparedes May 6, 2024
dca89a9
Merge branch 'main' into extend_remap_embedded
egparedes May 6, 2024
981589a
Update src/gt4py/next/common.py
egparedes May 6, 2024
6a6dde3
Fix format
egparedes May 6, 2024
b38792a
Fix CartesianConnectivity
egparedes May 6, 2024
dcf0ba0
Add CartesianConnectivity tests
egparedes May 6, 2024
542083c
Renaming and style changes.
egparedes May 6, 2024
0cb49e2
Fixes to CartesianConnectivity
egparedes May 7, 2024
e22ca5a
Renaming test
egparedes May 7, 2024
eabb6ea
Improve docstrings and address more reviewer's comments.
egparedes May 8, 2024
003dd44
Fix mypy issues.
egparedes May 8, 2024
bf567c5
Add missing changes from previous commit.
egparedes May 8, 2024
da04f07
Fix docstring.
egparedes May 8, 2024
c244008
Trigger CI
egparedes May 8, 2024
7ca1e93
Add explicit premap constructors to `CartesianConnectivity`
egparedes May 13, 2024
20cbde5
Merge branch 'main' into extend_remap_embedded
egparedes May 13, 2024
bf5af30
Address reviewer's comments.
egparedes May 16, 2024
20d3b2d
Merge branch 'main' into extend_remap_embedded
egparedes May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gt4py/_core/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import functools
import math
import numbers
from typing import overload

import numpy as np
import numpy.typing as npt
Expand All @@ -42,6 +41,7 @@
TypeVar,
Union,
cast,
overload,
)


Expand Down
12 changes: 10 additions & 2 deletions src/gt4py/eve/extended_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,16 @@ def __dir__() -> List[str]:
return self_func.__cached_dir


_T = TypeVar("_T")

# -- Common type aliases --
NoArgsCallable = Callable[[], Any]

_A = TypeVar("_A", contravariant=True)
_R = TypeVar("_R", covariant=True)


class ArgsOnlyCallable(Protocol[_A, _R]):
def __call__(self, *args: _A) -> _R: ...


# -- Typing annotations --
if _sys.version_info >= (3, 9):
Expand Down Expand Up @@ -367,6 +372,9 @@ def has_type_parameters(cls: Type) -> bool:
return issubclass(cls, Generic) and len(getattr(cls, "__parameters__", [])) > 0 # type: ignore[arg-type] # Generic not considered as a class


_T = TypeVar("_T")


def get_actual_type(obj: _T) -> Type[_T]:
"""Return type of an object (also working for GenericAlias instances which pretend to be an actual type)."""
return StdGenericAliasType if isinstance(obj, StdGenericAliasType) else type(obj)
Expand Down
32 changes: 32 additions & 0 deletions src/gt4py/eve/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from . import extended_typing as xtyping
from .extended_typing import (
Any,
ArgsOnlyCallable,
Callable,
Collection,
Dict,
Expand Down Expand Up @@ -84,6 +85,15 @@
T = TypeVar("T")


def first(iterable: Iterable[T], *, default: Union[T, NothingType] = NOTHING) -> T:
try:
return next(iter(iterable))
except StopIteration as error:
if default is not NOTHING:
return cast(T, default)
raise error


def isinstancechecker(type_info: Union[Type, Iterable[Type]]) -> Callable[[Any], bool]:
"""Return a callable object that checks if operand is an instance of `type_info`.

Expand Down Expand Up @@ -227,9 +237,31 @@ def itemgetter_(key: Any, default: Any = NOTHING) -> Callable[[Any], Any]:


_P = ParamSpec("_P")
_S = TypeVar("_S")
_T = TypeVar("_T")


@dataclasses.dataclass(frozen=True)
class IndexerCallable(Generic[_S, _T]):
"""
An indexer class applying the wrapped function to the index arguments.

Examples:
>>> indexer = IndexerCallable(lambda x: x**2)
>>> indexer[3]
9

>>> indexer = IndexerCallable(lambda a, b: a + b)
>>> indexer[3, 4]
7
"""

func: ArgsOnlyCallable[_S, _T]

def __getitem__(self, key: _S | Tuple[_S, ...]) -> _T:
return self.func(*key) if isinstance(key, tuple) else self.func(key)


class fluid_partial(functools.partial):
"""Create a `functools.partial` with support for multiple applications calling `.partial()`."""

Expand Down
Loading
Loading