示例#1
0
def rank(A):

    if isinstance(A, ndarray):
        F = Algebra()
        r = F.rank(A._M)
        return int(r)
    else:
        raise PyValueException, "Rank function can only be called on matrix objects"
示例#2
0
文件: core.py 项目: Ajami712/cobrapy
def rank(A):
    
    if isinstance(A,ndarray):
        F = Algebra();
        r=F.rank(A._M);
        return int(r);
    else:
        raise PyValueException, "Rank function can only be called on matrix objects"
示例#3
0
 def __div__(A, B):
     try:
         F = Algebra();
         R = F.solve(A._M, B._M);
         return R;
     except (java.lang.IllegalArgumentException), e:
         # check the error class types according to the matrix class so we can intelligently report the error.
         print e.getMessage()
         return None
示例#4
0
def norm(A, ntype=None):
    F = Algebra()
    if ntype == 'fro':
        r = F.normF(A._M)
    elif ntype == 2:
        r = F.norm2(A._M)
    else:
        r = F.norm2(A._M)
    return r
示例#5
0
文件: core.py 项目: Ajami712/cobrapy
def norm(A,ntype=None):
    F = Algebra();
    if ntype=='fro':
        r=F.normF(A._M);
    elif ntype == 2:
        r=F.norm2(A._M);
    else:
        r=F.norm2(A._M);
    return r;
示例#6
0
 def __mul__(A, B):
     # need to check types and multiple based on them..
     try:
         F = Algebra()
         C = (F.mult(A._M, B._M))
     except:
         raise PyValueException, "Inner dimension mismatch in matrix multiply."
         return None
     return ndarray(C)
示例#7
0
 def __div__(A, B):
     try:
         F = Algebra()
         R = F.solve(A._M, B._M)
         return R
     except (java.lang.IllegalArgumentException), e:
         # check the error class types according to the matrix class so we can intelligently report the error.
         print e.getMessage()
         return None
示例#8
0
 def __mul__(A, B):  
     # need to check types and multiple based on them..     
     try:
         F = Algebra();
         C=(F.mult(A._M, B._M));
     except:
         raise PyValueException, "Inner dimension mismatch in matrix multiply.";
         return None;
     return ndarray(C) 
示例#9
0
文件: core.py 项目: Ajami712/cobrapy
def solve_transpose(A, B):
    F = Algebra();
    if isinstance(A, ndarray) and isinstance(B, float):
            return F.solveTranspose(A._M,B);
    elif isinstance(B, ndarray) and  isinstance(A, float):
            return F.solveTranspose(A, B._M);
    elif isinstance(A, ndarray) and isinstance(B, ndarray):
            return ndarray(F.solveTranspose(A._M, B._M));
    else:
        return A / B
示例#10
0
def solve(A, B):
    F = Algebra()
    if isinstance(A, ndarray) and isinstance(B, float):
        return F.solve(A._M, B)
    elif isinstance(B, ndarray) and isinstance(A, float):
        return F.solve(A, B._M)
    elif isinstance(A, ndarray) and isinstance(B, ndarray):
        return ndarray(F.solve(A._M, B._M))
    else:
        return A / B
示例#11
0
def directlinearsolve():
    from no.uib.cipr.matrix import Matrices, DenseMatrix, DenseVector
    from cern.colt.matrix import DoubleMatrix2D, DoubleFactory2D
    from cern.colt.matrix.linalg import Algebra

    sz = 1000
    # MTJ
    x = DenseVector(sz)
    t = time.time()
    mat = Matrices.random(sz,sz)
    b = Matrices.random(sz)
    mat.solve(b,x)
    print "Mtj :" + str(time.time() - t)

    # Colt
    alg = Algebra()
    f = DoubleFactory2D.dense
    t = time.time()
    A = f.random(sz,sz)
    b = f.random(sz,1)
    x = alg.solve(A,b)
    print "Colt :" + str(time.time() - t)
示例#12
0
文件: core.py 项目: Ajami712/cobrapy
def inverse(A):
    F = Algebra();
    x=F.inverse(A._M);
    return ndarray(x)
示例#13
0
文件: core.py 项目: Ajami712/cobrapy
def transpose(A):
    F = Algebra();
    if isinstance(A,float):
        return A;
    else:
        return ndarray(F.transpose(A._M));
示例#14
0
文件: core.py 项目: Ajami712/cobrapy
def cond(A):
    F = Algebra();
    return F.cond(A._M);
示例#15
0
def cond(A):
    F = Algebra()
    return F.cond(A._M)
示例#16
0
def transpose(A):
    F = Algebra()
    if isinstance(A, float):
        return A
    else:
        return ndarray(F.transpose(A._M))
示例#17
0
def inverse(A):
    F = Algebra()
    x = F.inverse(A._M)
    return ndarray(x)