Пример #1
0
def vdot(a, b):
    """Returns the dot product of 2 vectors (or anything that can be made into
    a vector). NB: this is not the same as `dot`, as it takes the conjugate
    of its first argument if complex and always returns a scalar."""
    a, b = _na.ravel(a), _na.ravel(b)
    try:
        return _dotblas.vdot(a, b)
    # in case we get an integer Value
    except TypeError:
        return _numarray.dot(a, b)
Пример #2
0
def vdot(a, b):
    """Returns the dot product of 2 vectors (or anything that can be made into
    a vector). NB: this is not the same as `dot`, as it takes the conjugate
    of its first argument if complex and always returns a scalar."""
    a, b = _na.ravel(a), _na.ravel(b)
    try:
        return _dotblas.vdot(a, b)
    # in case we get an integer Value
    except TypeError:
        return _numarray.dot(a, b)
Пример #3
0
def tensormultiply(array1, array2):
    """tensormultiply returns the product for any rank >=1 arrays, defined as:

    r_{xxx, yyy} = \sum_k array1_{xxx, k} array2_{k, yyyy}

    where xxx, yyy denote the rest of the a and b dimensions.
    """
    array1, array2 = _na.asarray(array1), _na.asarray(array2)
    if array1.shape[-1] != array2.shape[0]:
        raise ValueError, "Unmatched dimensions"
    shape = array1.shape[:-1] + array2.shape[1:]
    return _gen.reshape(dot(_gen.reshape(array1, (-1, array1.shape[-1])),
                            _gen.reshape(array2, (array2.shape[0], -1))), shape)
Пример #4
0
def tensormultiply(array1, array2):
    """tensormultiply returns the product for any rank >=1 arrays, defined as:

    r_{xxx, yyy} = \sum_k array1_{xxx, k} array2_{k, yyyy}

    where xxx, yyy denote the rest of the a and b dimensions.
    """
    array1, array2 = _na.asarray(array1), _na.asarray(array2)
    if array1.shape[-1] != array2.shape[0]:
        raise ValueError, "Unmatched dimensions"
    shape = array1.shape[:-1] + array2.shape[1:]
    return _gen.reshape(
        dot(_gen.reshape(array1, (-1, array1.shape[-1])),
            _gen.reshape(array2, (array2.shape[0], -1))), shape)
Пример #5
0
 def dot(a, b):
     """returns matrix-multiplication between a and b.
     The product-sum is over the last dimension of a and the
     second-to-last dimension of b.
     
     NB: No conjugation of complex arguments is performed.
     
     This version uses the BLAS optimized routines where possible.
     """
     try:
         return _dotblas.dot(a, b) 
     except TypeError:
         try:
             return _numarray.dot(a, b)
         except TypeError,detail:
             if _na.shape(a) == () or _na.shape(b) == ():
                 return a*b
             else:
                 raise TypeError, detail or "invalid types for dot"
Пример #6
0
 def dot(a, b):
     """returns matrix-multiplication between a and b.
     The product-sum is over the last dimension of a and the
     second-to-last dimension of b.
     
     NB: No conjugation of complex arguments is performed.
     
     This version uses the BLAS optimized routines where possible.
     """
     try:
         return _dotblas.dot(a, b)
     except TypeError:
         try:
             return _numarray.dot(a, b)
         except TypeError, detail:
             if _na.shape(a) == () or _na.shape(b) == ():
                 return a * b
             else:
                 raise TypeError, detail or "invalid types for dot"