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

add function._SetSpace (wip) #644

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
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
19 changes: 18 additions & 1 deletion nutils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from typing import Tuple, Union, Type, Callable, Sequence, Any, Optional, Iterator, Iterable, Dict, Mapping, overload, List, Set, FrozenSet
from . import evaluable, numeric, util, expression, types, warnings, debug_flags
from .transform import EvaluableTransformChain
from .transformseq import Transforms
from .transformseq import Transforms, IdentifierTransforms
import builtins, numpy, re, types as builtin_types, itertools, functools, operator, abc, numbers

IntoArray = Union['Array', numpy.ndarray, bool, int, float]
Expand Down Expand Up @@ -440,6 +440,23 @@ def argshapes(self) -> Mapping[str, Tuple[int, ...]]:
shapes[arg._name] = tuple(map(int, arg.shape))
return shapes

class _SetSpace(Array):

def __init__(self, arg: Array, space: str, value: Array):
if space not in arg.spaces:
raise ValueError('argument does not depend on space {!r}'.format(space))
if value.ndim != 1:
raise ValueError('expected one-dimensional coordinate for space {!r}'.format(space))
self._space = space
self._arg = arg
self._value = value
super().__init__(shape=arg.shape, dtype=arg.dtype, spaces=arg.spaces-{space})

def lower(self, points_shape: _PointsShape, transform_chains: _TransformChainsMap, coordinates: _CoordinatesMap) -> evaluable.Array:
value = self._value.lower(points_shape, transform_chains, coordinates)
chain = IdentifierTransforms(ndims=1, name='dummy', length=value.shape[-1]).get_evaluable(evaluable.asarray(0)) # <- identity
return self._arg.lower(points_shape, {self._space: (chain, chain), **transform_chains}, {self._space: value, **coordinates})

class _Unlower(Array):

def __init__(self, array: evaluable.Array, spaces: FrozenSet[str], points_shape: Tuple[evaluable.Array, ...], transform_chains: Tuple[EvaluableTransformChain, ...], coordinates: Tuple[evaluable.Array, ...]) -> None:
Expand Down