예제 #1
0
파일: covsol.py 프로젝트: ssbirute/openvsip
def covsol(a, b):
    """Solve a covariance linear system."""

    m = import_module('vsip.math.solvers.covsol', dtype)
    m = import_module(v.dtype)
    x = matrix(b.dtype, b.rows(), b.cols())
    m.covsol(a.block, b.block, x.block)
    return x
예제 #2
0
def prodj(v, w):
    """Return the matrix product of v and the Hermitian of w."""

    b1 = v.block
    b2 = w.block
    if b1.dtype == b2.dtype:
        mod = import_module('vsip.math.matvec', b1.dtype)
        return matrix(block=mod.prodj(b1, b2))
    else:
        import numpy
        mod = import_module('vsip.math.matvec', b2.dtype)
        return matrix(array=numpy.tensordot(array(b1), array(mod.conj(b2)), (1,0)))
예제 #3
0
def kaiser(dtype, N, beta):
    """Create a vector with Kaiser window weights.

    arguments:

      :dtype: data type of the vector (e.g. float)
      :N: length of the vector

    """

    import_module('vsip.block', dtype)
    m = import_module('vsip.signal.window', dtype)
    return vector(block=m.kaiser(N, beta))
예제 #4
0
def prodh(v, w):
    """Return the matrix product of v and the Hermitian of w."""

    b1 = v.block
    b2 = w.block
    if b1.dtype == b2.dtype:
        mod = import_module('vsip.math.matvec', b1.dtype)
        return matrix(block=mod.prodh(b1, b2))
    else:
        import numpy
        mod = import_module('vsip.math.matvec', b2.dtype)
        return matrix(
            array=numpy.tensordot(array(b1), array(mod.herm(b2)), (1, 0)))
예제 #5
0
파일: random.py 프로젝트: ssbirute/openvsip
    def __init__(self, dtype, seed=0, portable=False):
        """Create a random number generator.

        arguments:

          :dtype: type of the data to be generated
          :seed: initial seed
          :portable: whether or not to use a portable (reproducible) sequence
        """

        # Make sure the proper block module is loaded, too
        import_module('vsip.block', dtype)
        mod = import_module('vsip.rand', dtype)
        self._rand = mod.rand(seed, portable)
예제 #6
0
    def __init__(self, dtype, seed=0, portable=False):
        """Create a random number generator.

        arguments:

          :dtype: type of the data to be generated
          :seed: initial seed
          :portable: whether or not to use a portable (reproducible) sequence
        """

        # Make sure the proper block module is loaded, too
        import_module("vsip.block", dtype)
        mod = import_module("vsip.rand", dtype)
        self._rand = mod.rand(seed, portable)
예제 #7
0
def cheby(dtype, N, ripple):
    """Create a vector with a Dolph-Chebyshev window of length N.

    arguments:

      :dtype: data type of the vector (e.g. float)
      :N: length of the vector
      :ripple: 

"""

    import_module('vsip.block', dtype)
    m = import_module('vsip.signal.window', dtype)
    return vector(block=m.cheby(N, ripple))
예제 #8
0
def blackman(dtype, N):
    """Create a vector with blackman window weights.

    arguments:

      :dtype: data type of the vector (e.g. float)
      :N: length of the vector

    .. math::

       y_i = 0.42 * 0.5 * cos(\\frac{2*\pi*i}{N-1}) + 0.08 * cos(\\frac{4*\pi*i}{N-1})"""

    import_module('vsip.block', dtype)
    m = import_module('vsip.signal.window', dtype)
    return vector(block=m.blackman(N))
예제 #9
0
def llsqsol(a, b):
    """Solve a linear least squares problem."""

    m = import_module('vsip.math.solvers.llsqsol', a.dtype)
    x = matrix(b.dtype, a.cols(), b.cols())
    m.llsqsol(a.block, b.block, x.block)
    return x
예제 #10
0
def llsqsol(a, b):
    """Solve a linear least squares problem."""

    m = import_module('vsip.math.solvers.llsqsol', a.dtype)
    x = matrix(b.dtype, a.cols(), b.cols())
    m.llsqsol(a.block, b.block, x.block)
    return x
예제 #11
0
def unary(func, a):

    b = a.block
    m = import_module('vsip.math.elementwise', b.dtype)
    f = getattr(m, func)
    v = a.__class__
    return v(block=f(b))
예제 #12
0
def unary(func, a):

    b = a.block
    m = import_module('vsip.math.elementwise', b.dtype)
    f = getattr(m, func)
    v = a.__class__
    return v(block=f(b))
예제 #13
0
파일: qrd.py 프로젝트: ssbirute/openvsip
    def __init__(self, dtype, rows, cols, storage):

        self._rows = rows
        self._cols = cols
        self.qstorage = storage
        mod = import_module('vsip.math.solvers.qrd', dtype)
        self.impl_ = mod.qrd(rows, cols, storage)
예제 #14
0
def hanning(dtype, N):
    """Create a vector with Hanning window weights.

    arguments:

      :dtype: data type of the vector (e.g. float)
      :N: length of the vector

    .. math::

       y_i = \\frac{1}{2}(1 - cos(\\frac{2\pi(i+1)}{N+1}))"""


    import_module('vsip.block', dtype)
    m = import_module('vsip.signal.window', dtype)
    return vector(block=m.hanning(N))
예제 #15
0
    def __init__(self, dtype, symmetry, support, i, decimation, n, hint):

        self.dtype = dtype
        self.symmetry = symmetry
        self.support = support

        m = import_module('vsip.signal.conv', dtype)
        self._impl = m.conv(symmetry, i, decimation, support, n, hint)
예제 #16
0
파일: svd.py 프로젝트: ssbirute/openvsip
    def __init__(self, dtype, rows, cols, ustorage, vstorage):

        self.dtype = dtype
        self._rows = rows
        self._cols = cols
        self.ustorage = ustorage
        self.vstorage = vstorage
        mod = import_module('vsip.math.solvers.svd', dtype)
        self.impl_ = mod.svd(rows, cols, ustorage, vstorage)
예제 #17
0
파일: clip.py 프로젝트: bradhowes/openvsip
def invclip(v, lt, mt, ut, lc, uc):

    m = import_module('vsip.selgen.clip', v.dtype)
    if isinstance(v, vector):
        vout = vector(v.dtype, v.length())
    else:
        vout = matrix(v.dtype, v.rows(), v.cols())
    m.invclip(v.block, vout.block, lt, mt, ut, lc, uc)
    return vout
예제 #18
0
파일: clip.py 프로젝트: ssbirute/openvsip
def invclip(v, lt, mt, ut, lc, uc):

    m = import_module('vsip.selgen.clip', v.dtype)
    if isinstance(v, vector):
        vout = vector(v.dtype, v.length())
    else:
        vout = matrix(v.dtype, v.rows(), v.cols())
    m.invclip(v.block, vout.block, lt, mt, ut, lc, uc)
    return vout
예제 #19
0
파일: svd.py 프로젝트: bradhowes/openvsip
    def __init__(self, dtype, rows, cols, ustorage, vstorage):

        self.dtype = dtype
        self._rows = rows
        self._cols = cols
        self.ustorage = ustorage
        self.vstorage = vstorage
        mod = import_module('vsip.math.solvers.svd', dtype)
        self.impl_ = mod.svd(rows, cols, ustorage, vstorage)
예제 #20
0
def outer(alpha, v, w):
    """Return the outer product of v and w."""

    b1 = v.block
    b2 = w.block
    if b1.dtype == b2.dtype:
        mod = import_module('vsip.math.matvec', b1.dtype)
        return mod.outer(alpha, b1, b2)
    else:
        pass
예제 #21
0
def outer(alpha, v, w):
    """Return the outer product of v and w."""

    b1 = v.block
    b2 = w.block
    if b1.dtype == b2.dtype:
        mod = import_module('vsip.math.matvec', b1.dtype)
        return mod.outer(alpha, b1, b2)
    else:
        pass
예제 #22
0
def vmmul(axis, v, m):
    """Return the elementwise multiplication of m with the replication of v."""

    vb = v.block
    mb = m.block
    if vb.dtype == mb.dtype:
        mod = import_module('vsip.math.matvec', vb.dtype)
        return matrix(block=mod.vmmul(axis, vb, mb))
    else:
        pass
예제 #23
0
def vmmul(axis, v, m):
    """Return the elementwise multiplication of m with the replication of v."""

    vb = v.block
    mb = m.block
    if vb.dtype == mb.dtype:
        mod = import_module('vsip.math.matvec', vb.dtype)
        return matrix(block=mod.vmmul(axis, vb, mb))
    else:
        pass
예제 #24
0
def kron(alpha, v, w):
    """Return the Kronecker product of v and w."""

    b1 = v.block
    b2 = w.block
    if b1.dtype == b2.dtype:
        mod = import_module('vsip.math.matvec', b1.dtype)
        return mod.kron(alpha, b1, b2)
    else:
        import numpy
        return numpy.kron(b1, b2)
예제 #25
0
def kron(alpha, v, w):
    """Return the Kronecker product of v and w."""

    b1 = v.block
    b2 = w.block
    if b1.dtype == b2.dtype:
        mod = import_module('vsip.math.matvec', b1.dtype)
        return mod.kron(alpha, b1, b2)
    else:
        import numpy
        return numpy.kron(b1, b2)
예제 #26
0
def binary(func, a1, a2):

    b1 = a1.block
    b2 = a2.block
    if b1.dtype == b2.dtype:
        m = import_module('vsip.math.elementwise', b1.dtype)
    else:
        raise ValueError, 'Unsupported combination of dtypes (%s, %s)'%(b1.dtype, b2.dtype)
    f = getattr(m, func)
    v = a1.__class__
    return v(block=f(b1, b2))
예제 #27
0
def binary(func, a1, a2):

    b1 = a1.block
    b2 = a2.block
    if b1.dtype == b2.dtype:
        m = import_module('vsip.math.elementwise', b1.dtype)
    else:
        raise ValueError, 'Unsupported combination of dtypes (%s, %s)' % (
            b1.dtype, b2.dtype)
    f = getattr(m, func)
    v = a1.__class__
    return v(block=f(b1, b2))
예제 #28
0
def dot(a, b):
    """Compute the dot product of a and b.
    dot(a, b) = a * b"""

    b1 = a.block
    b2 = b.block
    if b1.dtype == b2.dtype:
        mod = import_module('vsip.math.matvec', b1.dtype)
        return mod.dot(b1, b2)
    else:
        import operator
        import numpy
        return reduce(operator.add, map(operator.mul, numpy.array(b1), numpy.array(b2)))
예제 #29
0
def dot(a, b):
    """Compute the dot product of a and b.
    dot(a, b) = a * b"""

    b1 = a.block
    b2 = b.block
    if b1.dtype == b2.dtype:
        mod = import_module('vsip.math.matvec', b1.dtype)
        return mod.dot(b1, b2)
    else:
        import operator
        import numpy
        return reduce(operator.add,
                      map(operator.mul, numpy.array(b1), numpy.array(b2)))
예제 #30
0
def prod(v, w):
    """Return the matrix product of v and w."""

    b1 = v.block
    b2 = w.block
    if b1.dtype == b2.dtype:
        mod = import_module('vsip.math.matvec', b1.dtype)
        b3 = mod.prod(b1, b2)
        if len(b3.shape) == 2:
            return matrix(block=b3)
        else:
            return vector(block=b3)
    else:
        import numpy
        if len(b1.shape) == len(b2.shape):
            return matrix(array=numpy.tensordot(array(b1), array(b2), (1,0)))
        elif len(b1.shape) == 1:
            return vector(array=numpy.tensordot(array(b1), array(b2), (0,0)))
        else:
            return vector(array=numpy.tensordot(array(b1), array(b2), (1,0)))
예제 #31
0
def subblock(parent, slice):
    """Create a subblock of 'parent'.

    Arguments:

      parent: the parent block to reference.
      slice: the slice of the parent to refer to.
    """

    dtype = parent.dtype
    mod = import_module("vsip.block", dtype)

    if len(slice) == 1:
        return mod.subblock(parent, slice[0])
    elif len(slice) == 2:
        return mod.subblock(parent, slice[0], slice[1])
    elif len(slice) == 3:
        return mod.subblock(parent, slice[0], slice[1], slice[2])
    else:
        raise ValueError, "Unsupported slice %s" % slice
예제 #32
0
def prod(v, w):
    """Return the matrix product of v and w."""

    b1 = v.block
    b2 = w.block
    if b1.dtype == b2.dtype:
        mod = import_module('vsip.math.matvec', b1.dtype)
        b3 = mod.prod(b1, b2)
        if len(b3.shape) == 2:
            return matrix(block=b3)
        else:
            return vector(block=b3)
    else:
        import numpy
        if len(b1.shape) == len(b2.shape):
            return matrix(array=numpy.tensordot(array(b1), array(b2), (1, 0)))
        elif len(b1.shape) == 1:
            return vector(array=numpy.tensordot(array(b1), array(b2), (0, 0)))
        else:
            return vector(array=numpy.tensordot(array(b1), array(b2), (1, 0)))
예제 #33
0
파일: block.py 프로젝트: ssbirute/openvsip
def subblock(parent, slice):
    """Create a subblock of 'parent'.

    Arguments:

      parent: the parent block to reference.
      slice: the slice of the parent to refer to.
    """

    dtype = parent.dtype
    mod = import_module('vsip.parallel.block', dtype)

    if len(slice) == 1:
        return mod.subblock(parent, slice[0])
    elif len(slice) == 2:
        return mod.subblock(parent, slice[0], slice[1])
    elif len(slice) == 3:
        return mod.subblock(parent, slice[0], slice[1], slice[2])
    else:
        raise ValueError, 'Unsupported slice %s' % slice
예제 #34
0
파일: block.py 프로젝트: ssbirute/openvsip
def block(*args, **kwargs):
    """Create a distributed block.

        Valid argument combinations:

        block(array, map): create a block from an existing array-like container
        block(dtype, shape, map): create a block of the given type and shape
        block(dtype, shape, value, map): create a block of the given type and shape and initialize it to value
    """

    # Unpack constructor arguments
    array = value = None
    if len(args) == 2:
        array, map = args[0], args[1]
        array = numpy.array(array, copy=False)
        shape = array.shape
    elif len(args) == 3:
        dtype, shape, map = args[0], args[1], args[2]
        value = None
    elif len(args) == 4:
        dtype, shape, value, map = args[0], args[1], args[2], args[3]

    mod = import_module('vsip.parallel.block', dtype)

    if 'array' in kwargs:
        return mod.block(array, map)

    # Create a new block
    if len(shape) == 1:
        return value and mod.block(shape[0], value, map) or mod.block(
            shape[0], map)
    elif len(shape) == 2:
        return value and mod.block(shape[0], shape[1], value,
                                   map) or mod.block(shape[0], shape[1], map)
    elif len(shape) == 3:
        return value and mod.block(shape[0], shape[1], shape[2],
                                   value, map) or mod.block(
                                       shape[0], shape[1], shape[2], map)
    else:
        raise ValueError, 'Unsupported shape %s' % shape
예제 #35
0
파일: block.py 프로젝트: bradhowes/openvsip
def block(*args, **kwargs):
    """Create a distributed block.

        Valid argument combinations:

        block(array, map): create a block from an existing array-like container
        block(dtype, shape, map): create a block of the given type and shape
        block(dtype, shape, value, map): create a block of the given type and shape and initialize it to value
    """

    # Unpack constructor arguments
    array = value = None
    if len(args) == 2:
        array, map = args[0], args[1]
        array = numpy.array(array, copy=False)
        shape = array.shape
    elif len(args) == 3:
        dtype, shape, map = args[0], args[1], args[2]
        value = None
    elif len(args) == 4:
        dtype, shape, value, map = args[0], args[1], args[2], args[3]

    mod = import_module('vsip.parallel.block', dtype)

    if 'array' in kwargs:
        return mod.block(array, map)
        
    # Create a new block
    if len(shape) == 1:
        return value and mod.block(shape[0], value, map) or mod.block(shape[0], map)
    elif len(shape) == 2:
        return value and mod.block(shape[0], shape[1], value, map) or mod.block(shape[0], shape[1], map)
    elif len(shape) == 3:
        return value and mod.block(shape[0], shape[1], shape[2], value, map) or mod.block(shape[0], shape[1], shape[2], map)
    else:
        raise ValueError, 'Unsupported shape %s'%shape
예제 #36
0
def block(*args, **kwargs):
    """Create a block.

    Valid argument combinations:

      block(dtype, shape): create a block of the given type and shape
      block(dtype, shape, value): create a block of the given type and shape and initialize it to value
      block(array=A): create a block from an existing array-like container
    """

    # First figure out the data type so we know which
    # module to import.
    if args:
        dtype = args[0]
        shape = args[1]
        value = len(args) == 3 and args[2] or None

    elif "array" in kwargs:
        # make sure we have all the required metadata
        array = numpy.array(kwargs["array"], copy=False)
        dtype = array.dtype

    mod = import_module("vsip.block", dtype)

    if "array" in kwargs:
        return mod.block(array)

    # Create a new block
    if len(shape) == 1:
        return value and mod.block(shape[0], value) or mod.block(shape[0])
    elif len(shape) == 2:
        return value and mod.block(shape[0], shape[1], value) or mod.block(shape[0], shape[1])
    elif len(shape) == 3:
        return value and mod.block(shape[0], shape[1], shape[2], value) or mod.block(shape[0], shape[1], shape[2])
    else:
        raise ValueError, "Unsupported shape %s" % shape
예제 #37
0
def herm(m):
    """Return the Hermitian, i.e. the conjugate transpose of matrix 'm'"""

    mod = import_module('vsip.math.matvec', m.block.dtype)
    return matrix(array=mod.herm(m.block))
예제 #38
0
파일: lud.py 프로젝트: bradhowes/openvsip
    def __init__(self, dtype, length):

        m = import_module('vsip.math.solvers.lud', dtype)
        self.impl_ = mod.lud(length)
예제 #39
0
def herm(m):
    """Return the Hermitian, i.e. the conjugate transpose of matrix 'm'"""

    mod = import_module('vsip.math.matvec', m.block.dtype)
    return matrix(array=mod.herm(m.block))
예제 #40
0
def trans(m):
    """Return the transpose of matrix 'm'"""
    
    mod = import_module('vsip.math.matvec', m.block.dtype)
    return matrix(array=mod.trans(m.block))
예제 #41
0
    def local(self):
        """Return the local submatrix if this is a distributed matrix, 'self' otherwise."""

        import_module('vsip.block', self.block.dtype)
        return matrix(block=self.block.local())
예제 #42
0
파일: vector.py 프로젝트: ssbirute/openvsip
    def local(self):
        """Return the local subvector if this is a distributed vector, 'self' otherwise."""

        import_module('vsip.block', self.block.dtype)
        return vector(block=self.block.local())
예제 #43
0
파일: chold.py 프로젝트: bradhowes/openvsip
    def __init__(self, dtype, uplo, length):

        mod = import_module('vsip.math.solvers.chold', dtype)
        self.uplo = uplo
        self.length = length
        self.impl_ = mod.chold(uplo, length)
예제 #44
0
파일: lud.py 프로젝트: ssbirute/openvsip
    def __init__(self, dtype, length):

        m = import_module('vsip.math.solvers.lud', dtype)
        self.impl_ = mod.lud(length)
예제 #45
0
    def __init__(self, dtype, uplo, length):

        mod = import_module('vsip.math.solvers.chold', dtype)
        self.uplo = uplo
        self.length = length
        self.impl_ = mod.chold(uplo, length)
예제 #46
0
    def local(self):
        """Return the local submatrix if this is a distributed matrix, 'self' otherwise."""

        import_module('vsip.block', self.block.dtype)
        return matrix(block=self.block.local())
예제 #47
0
    def local(self):
        """Return the local subvector if this is a distributed vector, 'self' otherwise."""

        import_module('vsip.block', self.block.dtype)
        return vector(block=self.block.local())
예제 #48
0
def trans(m):
    """Return the transpose of matrix 'm'"""

    mod = import_module('vsip.math.matvec', m.block.dtype)
    return matrix(array=mod.trans(m.block))