def __mul__(self, other): if isinstance(other, Number): return Matrix(API.scalarMultiply(self._matrix, other)) elif isinstance(other, Vector): return Vector(API.operate(self._matrix, other._vector)) else: return Matrix(API.multiply(self._matrix, other._matrix))
def __init__(self, mat): self._dec = API.newSingularValueDecompositionImpl(mat._matrix)
def __sub__(self, other): if isinstance(other, Number): return Matrix(API.scalarAdd(self._matrix, -other)) else: return Matrix(API.subtract(self._matrix, other._matrix))
def init_fromsize(self, rows, columns): self._matrix = API.newArray2DRowRealMatrix(rows, columns)
def norm(self): return API.getNorm(self._vector)
def __setitem__(self, i, val): if 0 <= i < len(self): API.setEntry(self._vector, i, val) else: raise IndexError
def __mul__(self, other): if isinstance(other, Number): return Vector(API.mapMultiply(self._vector, other)) else: return Vector(API.dotProduct(self._vector, other._vector))
def __add__(self, other): return Vector(API.add(self._vector, other._vector))
def rows(self): return API.getRowDimension(self._matrix)
def increment(self, i, j, val): API.addToEntry(self._matrix, i, j, val)
def __getitem__(self, ij): i, j = ij return API.getEntry(self._matrix, i, j)
def __setitem__(self, ij, val): i, j = ij API.setEntry(self._matrix, i, j, val)
def __pow__(self, n): return Matrix(API.power(self._matrix, n))
def __init__(self): self._vector = API.newArrayRealVector()
def columns(self): return API.getColumnDimension(self._matrix)
def init_fromlist(self, data): self._vector = API.newArrayRealVector(data)
def norm(self): return API.getNorm(self._matrix)
def __sub__(self, other): return Vector(API.subtract(self._vector, other._vector))
def trace(self): return API.getTrace(self._matrix)
def __getitem__(self, i): if 0 <= i < len(self): return API.getEntry(self._vector, i) else: raise IndexError
def solve_matrix(self, mat): return Matrix(API.solve(self._solver, mat._matrix))
def __len__(self): return API.getDimension(self._vector)
def solve_vector(self, vec): return Vector(API.solve(self._solver, vec._vector))
def __init__(self): self._matrix = API.newArray2DRowRealMatrix()
def solver(self): try: solver = self._solver except AttributeError: solver = self._solver = Solver(API.getSolver(self._dec)) return solver
def init_fromdata(self, data): self._matrix = API.newArray2DRowRealMatrix(data)
def __add__(self, other): if isinstance(other, Number): return Matrix(API.scalarAdd(self._matrix, other)) else: return Matrix(API.add(self._matrix, other._matrix))