コード例 #1
0
ファイル: lobpcg.py プロジェクト: thouis/scipy
def makeOperator(operatorInput, expectedShape):
    """Internal. Takes a dense numpy array or a sparse matrix or
    a function and makes an operator performing matrix * blockvector
    products.

    Examples
    --------
    >>> A = makeOperator( arrayA, (n, n) )
    >>> vectorB = A( vectorX )

    """
    if operatorInput is None:

        def ident(x):
            return x

        operator = LinearOperator(expectedShape, ident, matmat=ident)
    else:
        operator = aslinearoperator(operatorInput)

    if operator.shape != expectedShape:
        raise ValueError('operator has invalid shape')

    if sys.version_info[0] >= 3:
        # special methods are looked up on the class -- so make a new one
        operator.__class__ = CallableLinearOperator
    else:
        operator.__call__ = operator.matmat

    return operator
コード例 #2
0
ファイル: lobpcg.py プロジェクト: gcasey/scipy
def makeOperator( operatorInput, expectedShape ):
    """Internal. Takes a dense numpy array or a sparse matrix or
    a function and makes an operator performing matrix * blockvector
    products.

    Examples
    --------
    >>> A = makeOperator( arrayA, (n, n) )
    >>> vectorB = A( vectorX )

    """
    if operatorInput is None:
        def ident(x):
            return x
        operator = LinearOperator(expectedShape, ident, matmat=ident)
    else:
        operator = aslinearoperator(operatorInput)

    if operator.shape != expectedShape:
        raise ValueError('operator has invalid shape')

    if sys.version_info[0] >= 3:
        # special methods are looked up on the class -- so make a new one
        operator.__class__ = CallableLinearOperator
    else:
        operator.__call__ = operator.matmat

    return operator
コード例 #3
0
def makeOperator(operatorInput, expectedShape):
    """Internal. Takes a dense numpy array or a sparse matrix or
    a function and makes an operator performing matrix * blockvector
    products.

    Example
    -------

    >>> A = makeOperator( arrayA, (n, n) )
    >>> vectorB = A( vectorX )

    """
    if operatorInput is None:

        def ident(x):
            return x

        operator = LinearOperator(expectedShape, ident, matmat=ident)
    else:
        operator = aslinearoperator(operatorInput)

    if operator.shape != expectedShape:
        raise ValueError('operator has invalid shape')

    operator.__call__ = operator.matmat

    return operator
コード例 #4
0
ファイル: lobpcg.py プロジェクト: decarlin/stuartlab-scripts
def makeOperator( operatorInput, expectedShape ):
    """Internal. Takes a dense numpy array or a sparse matrix or
    a function and makes an operator performing matrix * blockvector
    products.

    Example
    -------

    >>> A = makeOperator( arrayA, (n, n) )
    >>> vectorB = A( vectorX )

    """
    if operatorInput is None:
        def ident(x):
            return x
        operator = LinearOperator(expectedShape, ident, matmat=ident)
    else:
        operator = aslinearoperator(operatorInput)

    if operator.shape != expectedShape:
        raise ValueError('operator has invalid shape')

    operator.__call__ = operator.matmat

    return operator
コード例 #5
0
def Operator(f, size=None):
	"""Create a stacked version of the function f, casted as a LinearOperator.
	
	size is the dimension of the operator f."""
	
	if size == None: size = f.Size
	
	operator = LinearOperator((size,size), matvec = StackFunction(f), dtype=float64)
	operator.__call__ = lambda x: operator * x
	
	return operator
コード例 #6
0
def Operator(f, size=None):
    """Create a stacked version of the function f, casted as a LinearOperator.
	
	size is the dimension of the operator f."""

    if size == None: size = f.Size

    operator = LinearOperator((size, size),
                              matvec=StackFunction(f),
                              dtype=float64)
    operator.__call__ = lambda x: operator * x

    return operator