How to use the clifford._multivector.MultiVector function in clifford

To help you get started, we’ve selected a few clifford examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pygae / clifford / clifford / numba / _multivector.py View on Github external
def MultiVector_normal(self):
    return MultiVector.normal
github pygae / clifford / clifford / _mvarray.py View on Github external
def _interrogate_nested_mvs(input_array) -> Tuple[Tuple[int, ...], Layout, np.dtype]:
    """
    Calculates the shape of the nested input_array, and gets the associated layout.
    Stops descending when it encounters a MultiVector.
    """
    if not isinstance(input_array, MultiVector):
        nested_shape, layout, dtype = _interrogate_nested_mvs(input_array[0])
        return (len(input_array), *nested_shape), layout, dtype
    else:
        return (), input_array.layout, input_array.value.dtype
github pygae / clifford / clifford / numba / _layout.py View on Github external
def impl(self, value):
        return MultiVector(self, value)
    return impl
github pygae / clifford / clifford / __init__.py View on Github external
def randomMV(
        layout, min=-2.0, max=2.0, grades=None, mvClass=MultiVector,
        uniform=None, n=1, normed=False):
    """n Random MultiVectors with given layout.

    Coefficients are between min and max, and if grades is a list of integers,
    only those grades will be non-zero.


    Examples
    --------
    >>> randomMV(layout, min=-2.0, max=2.0, grades=None, uniform=None, n=2)  # doctest: +SKIP

    """

    if n > 1:
        # return many multivectors
        return [randomMV(layout=layout, min=min, max=max, grades=grades,
github pygae / clifford / clifford / numba / _multivector.py View on Github external
@numba.extending.lower_builtin(MultiVector, LayoutType, types.Any)
def impl_MultiVector(context, builder, sig, args):
    typ = sig.return_type
    layout, value = args
    mv = cgutils.create_struct_proxy(typ)(context, builder)
    mv.layout = layout
    mv.value = value
    return impl_ret_borrowed(context, builder, sig.return_type, mv._getvalue())
github pygae / clifford / clifford / _parser.py View on Github external
def parse_multivector(layout: Layout, mv_string: str) -> MultiVector:
    # Create a multivector
    mv_out = MultiVector(layout)

    # parser state
    sign = None
    coeff = None
    last_t = None

    # TODO: this could do with a recursive parser to handle parens
    for t, m, data in _tokenize(layout, mv_string):
        if t == 'space':
            continue  # don't update the tokenizer
        elif t in '()':
            # Not implemented, old behavior was to just strip these - do the same
            warnings.warn(
                "Parentheses are not parsed, behavior may be surprising",
                stacklevel=3)
            continue
github pygae / clifford / clifford / _multivector.py View on Github external
def __getitem__(self, key: Union['MultiVector', tuple, int]) -> numbers.Number:
        """
        ``value = self[key]``.

        If key is a blade tuple (e.g. ``(0, 1)`` or ``(1, 3)``), or a blade,
        (e.g. ``e12``),  then return the (real) value of that blade's coefficient.

        .. deprecated:: 1.4.0
            If an integer is passed, it is treated as an index into ``self.value``.
            Use ``self.value[i]`` directly.
        """
        if isinstance(key, MultiVector):
            inds, = np.nonzero(key.value)
            if len(inds) > 1:
                raise ValueError("Must be a single basis element")
            return self.value[inds[0]]
        elif isinstance(key, tuple):
            sign, idx = self.layout._sign_and_index_from_tuple(key)
            return sign*self.value[idx]
        else:
            warnings.warn(
                "Treating MultiVector objects like a sequence is deprecated. "
                "To access the coefficients as a sequence, use the `.value` attribute.",
                DeprecationWarning, stacklevel=2)
            return self.value[key]
github pygae / clifford / clifford / numba / _multivector.py View on Github external
layout_type = self.layout._numba_type_

    cache = layout_type._cache
    dt = self.value.dtype

    # now use the dtype to key that cache.
    try:
        return cache[dt]
    except KeyError:
        # Computing and hashing `dtype_type` is slow, so we do not use it as a
        # hash key. The raw numpy dtype is much faster to use as a key.
        dtype_type = _numpy_support.from_dtype(dt)
        ret = cache[dt] = MultiVectorType(layout_type, dtype_type)
        return ret

MultiVector._numba_type_ = _numba_type_


@numba.extending.register_model(MultiVectorType)
class MultiVectorModel(numba.extending.models.StructModel):
    def __init__(self, dmm, fe_type):
        members = [
            ('layout', fe_type.layout_type),
            ('value', fe_type.value_type),
        ]
        super().__init__(dmm, fe_type, members)


@numba.extending.type_callable(MultiVector)
def type_MultiVector(context):
    def typer(layout, value):
        if isinstance(layout, LayoutType) and isinstance(value, types.Array):
github pygae / clifford / clifford / _mvarray.py View on Github external
import functools
import operator
from typing import Tuple

import numpy as np

from clifford.io import write_ga_file, read_ga_file  # noqa: F401
from ._layout import Layout
from ._multivector import MultiVector

dual_array = np.vectorize(MultiVector.dual)
normal_array = np.vectorize(MultiVector.normal)
call_array = np.vectorize(MultiVector.__call__)


def _interrogate_nested_mvs(input_array) -> Tuple[Tuple[int, ...], Layout, np.dtype]:
    """
    Calculates the shape of the nested input_array, and gets the associated layout.
    Stops descending when it encounters a MultiVector.
    """
    if not isinstance(input_array, MultiVector):
        nested_shape, layout, dtype = _interrogate_nested_mvs(input_array[0])
        return (len(input_array), *nested_shape), layout, dtype
    else:
        return (), input_array.layout, input_array.value.dtype