Beispiel #1
0
    def __new__(cls, mat):
        if not mat.is_Matrix:
            raise TypeError("input to Trace, %s, is not a matrix" % str(mat))

        if not mat.is_square:
            raise ShapeError("Trace of a non-square matrix")

        return Basic.__new__(cls, mat)
Beispiel #2
0
    def __new__(cls, mat):
        mat = sympify(mat)
        if not mat.is_Matrix:
            raise TypeError("Input to Determinant, %s, not a matrix" % str(mat))

        if not mat.is_square:
            raise ShapeError("Det of a non-square matrix")

        return Basic.__new__(cls, mat)
Beispiel #3
0
 def _new(cls, *args, **kwargs):
     shape, flat_list = cls._handle_ndarray_creation_inputs(*args, **kwargs)
     shape = Tuple(*map(_sympify, shape))
     flat_list = flatten(flat_list)
     flat_list = Tuple(*flat_list)
     self = Basic.__new__(cls, flat_list, shape, **kwargs)
     self._shape = shape
     self._array = tuple(flat_list)
     self._rank = len(shape)
     self._loop_size = functools.reduce(lambda x, y: x * y,
                                        shape) if shape else 0
     return self
Beispiel #4
0
 def __new__(cls, parent, rowslice, colslice):
     rowslice = normalize(rowslice, parent.shape[0])
     colslice = normalize(colslice, parent.shape[1])
     if not (len(rowslice) == len(colslice) == 3):
         raise IndexError()
     if ((0 > rowslice[0]) is S.true
             or (parent.shape[0] < rowslice[1]) is S.true
             or (0 > colslice[0]) is S.true
             or (parent.shape[1] < colslice[1]) is S.true):
         raise IndexError()
     if isinstance(parent, MatrixSlice):
         return mat_slice_of_slice(parent, rowslice, colslice)
     return Basic.__new__(cls, parent, Tuple(*rowslice), Tuple(*colslice))
Beispiel #5
0
    def __new__(cls, domain, condition):
        if condition is True:
            return domain
        cond = rv_subs(condition)
        # Check that we aren't passed a condition like die1 == z
        # where 'z' is a symbol that we don't know about
        # We will never be able to test this equality through iteration
        if not cond.free_symbols.issubset(domain.free_symbols):
            raise ValueError(
                'Condition "%s" contains foreign symbols \n%s.\n' %
                (condition, tuple(cond.free_symbols - domain.free_symbols)) +
                "Will be unable to iterate using this condition")

        return Basic.__new__(cls, domain, cond)
Beispiel #6
0
    def __new__(cls, *domains):
        symbols = sumsets([domain.symbols for domain in domains])

        # Flatten any product of products
        domains2 = []
        for domain in domains:
            if not domain.is_ProductDomain:
                domains2.append(domain)
            else:
                domains2.extend(domain.domains)
        domains2 = FiniteSet(*domains2)

        if all(domain.is_Finite for domain in domains2):
            from diofant.stats.frv import ProductFiniteDomain
            cls = ProductFiniteDomain
        if all(domain.is_Continuous for domain in domains2):
            from diofant.stats.crv import ProductContinuousDomain
            cls = ProductContinuousDomain

        return Basic.__new__(cls, *domains2)
Beispiel #7
0
    def __new__(cls, *spaces):
        rs_space_dict = {}
        for space in spaces:
            for value in space.values:
                rs_space_dict[value] = space

        symbols = FiniteSet(*[val.symbol for val in rs_space_dict.keys()])

        # Overlapping symbols
        if len(symbols) < sum(len(space.symbols) for space in spaces):
            raise ValueError("Overlapping Random Variables")

        if all(space.is_Finite for space in spaces):
            from diofant.stats.frv import ProductFinitePSpace
            cls = ProductFinitePSpace
        if all(space.is_Continuous for space in spaces):
            from diofant.stats.crv import ProductContinuousPSpace
            cls = ProductContinuousPSpace

        obj = Basic.__new__(cls, *FiniteSet(*spaces))

        return obj
Beispiel #8
0
 def __new__(cls, rows, cols, lamda):
     rows, cols = sympify(rows), sympify(cols)
     return Basic.__new__(cls, rows, cols, lamda)
Beispiel #9
0
 def __new__(cls):
     global instantiated
     instantiated += 1
     return Basic.__new__(cls)
Beispiel #10
0
 def __new__(cls, symbol, set):
     if not isinstance(set, FiniteSet):
         set = FiniteSet(*set)
     return Basic.__new__(cls, symbol, set)
Beispiel #11
0
 def __new__(cls, *args):
     args = list(map(sympify, args))
     return Basic.__new__(cls, *args)
Beispiel #12
0
 def __new__(cls, symbol, set):
     assert symbol.is_Symbol
     return Basic.__new__(cls, symbol, set)
Beispiel #13
0
 def __new__(cls, symbols, *args):
     symbols = FiniteSet(*symbols)
     return Basic.__new__(cls, symbols, *args)
Beispiel #14
0
 def __new__(cls, pspace, symbol):
     if not isinstance(symbol, Symbol):
         raise TypeError("symbol should be of type Symbol")
     if not isinstance(pspace, PSpace):
         raise TypeError("pspace variable should be of type PSpace")
     return Basic.__new__(cls, pspace, symbol)
Beispiel #15
0
 def __new__(cls, s, distribution):
     if isinstance(s, str):
         s = Symbol(s)
     if not isinstance(s, Symbol):
         raise TypeError("s should have been string or Symbol")
     return Basic.__new__(cls, s, distribution)
Beispiel #16
0
 def __new__(cls, name, antisym, **kwargs):
     obj = Basic.__new__(cls, name, antisym, **kwargs)
     obj.name = name
     obj.antisym = antisym
     return obj
Beispiel #17
0
 def __new__(cls, density):
     density = Dict(density)
     return Basic.__new__(cls, density)
Beispiel #18
0
 def __new__(cls, fulldomain, condition):
     condition = condition.xreplace({rs: rs.symbol
                                     for rs in random_symbols(condition)})
     return Basic.__new__(cls, fulldomain, condition)