How to use the chaospy.poly.base.Poly function in chaospy

To help you get started, we’ve selected a few chaospy 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 jonathf / chaospy / chaospy / poly / base.py View on Github external
def __ne__(self, other):
        if not isinstance(other, Poly):
            other = Poly(other)
        diff = abs(self - other)
        out = numpy.zeros(diff.shape, dtype=bool)
        for key in diff.keys:
            out = out + (diff.A[key]!=0)
        return out
github jonathf / chaospy / chaospy / poly / base.py View on Github external
def copy(self):
        """Return a copy of the polynomial."""
        return Poly(self.A.copy(), self.dim, self.shape,
            self.dtype)
github jonathf / chaospy / chaospy / poly / typing.py View on Github external
def dtyping(*args):
    """
    Find least common denominator dtype.

    Examples:
        >>> str(dtyping(int, float)) in ("", "")
        True
        >>> print(dtyping(int, Poly))
        
    """
    args = list(args)

    for idx, arg in enumerate(args):

        if isinstance(arg, Poly):
            args[idx] = Poly

        elif isinstance(arg, numpy.generic):
            args[idx] = numpy.asarray(arg).dtype

        elif isinstance(arg, (float, int)):
            args[idx] = type(arg)

    for type_ in DATATYPES:
        if type_ in args:
            return type_

    raise ValueError(
        "dtypes not recognised " + str([str(_) for _ in args]))
github jonathf / chaospy / chaospy / poly / base.py View on Github external
raise IndexError("Index out of range")

            subkey = slice(subkey, subkey+1,None)


        A0 = {}
        for key in self.keys:
            tmp = self.A[key][subset]
            if not numpy.all(tmp==0):
                A0[key] = tmp

        A1 = {}
        for key in list(A0.keys())[subkey]:
            A1[key] = A0[key]

        return Poly(A1, self.dim, shape, self.dtype)
github jonathf / chaospy / chaospy / poly / typing.py View on Github external
out = numpy.asarray(
            [{} for _ in range(numpy.prod(shape))],
            dtype=object
        )
        core = vari.A.copy()
        for key in core.keys():

            core[key] = core[key].flatten()

            for i in range(numpy.prod(shape)):

                if not numpy.all(core[key][i] == 0):
                    out[i][key] = core[key][i]

        for i in range(numpy.prod(shape)):
            out[i] = Poly(out[i], vari.dim, (), vari.dtype)

        out = out.reshape(shape)
        return out

    return numpy.asarray(vari)
github jonathf / chaospy / chaospy / poly / base.py View on Github external
def __contains__(self, y):
        """x.__contains__(y) <==> y in x"""

        if not isinstance(y, Poly):
            y = Poly(y)

        if self.shape==():
            if len(y.keys)>1:
                return NotImplemented
            return y.keys[0] in self.keys

        if len(y.shape)==len(self.shape)-1:
            return max(map(y.__eq__, self))

        if len(y.shape)
github jonathf / chaospy / chaospy / poly / base.py View on Github external
def __pos__(self):
        return Poly(self.A, self.dim, self.shape, self.dtype)
github jonathf / chaospy / chaospy / poly / collection / arithmetics.py View on Github external
dtype = chaospy.poly.typing.dtyping(part1.dtype, part2.dtype)

    zero = (0,)*part1.dim

    if zero not in core:
        core[zero] = np.zeros(part1.shape, dtype=int)

    core[zero] = core[zero] + part2

    if np.prod(part2.shape) > np.prod(part1.shape):

        ones = np.ones(part2.shape, dtype=dtype)
        for key in core:
            core[key] = core[key]*ones

    return Poly(core, part1.dim, None, dtype)
github jonathf / chaospy / chaospy / poly / dimension.py View on Github external
Q = P(*ones)
        ones[i] = 1
        if isinstance(Q, numpy.ndarray):
            continue
        Q = Q.A

        if zero in Q:
            del Q[zero]

        for key in Q:

            val = Q[key]
            A[-1][key] = val

    A = [Poly(a, dim, None, P.dtype) for a in A]
    P = Poly(A, dim, None, P.dtype)
    P = P + 1*(P(*(1,)*dim)==0)*M

    return P
github jonathf / chaospy / chaospy / poly / shaping.py View on Github external
Args:
        vari (chaospy.poly.base.Poly, numpy.ndarray):
            Input array or polynomial.
        axis (int):
            The axis to roll backwards. The positions of the other axes do not
            change relative to one another.
        start (int):
            The axis is rolled until it lies before thes position.
    """
    if isinstance(vari, Poly):
        core_old = vari.A.copy()
        core_new = {}
        for key in vari.keys:
            core_new[key] = rollaxis(core_old[key], axis, start)
        return Poly(core_new, vari.dim, None, vari.dtype)

    return numpy.rollaxis(vari, axis, start)