matrix

The matrix module defines an abstract Matrix object and several implementations. Matrix objects support basic addition and subtraction operations and provide a consistent insterface for solving linear systems. Matrices can be converted into other forms suitable for external processing via the export method.

class nutils.matrix.Backend

Bases: object

backend base class

abstract assemble(self, data, index, shape)

Assemble a (sparse) tensor based on index-value pairs.

Note

This function is abstract.

__weakref__

list of weak references to the object (if defined)

class nutils.matrix.Matrix(shape)

Bases: object

matrix base class

__add__(self, other)

add two matrices

__mul__(self, other)

multiply matrix with a scalar

__matmul__(self, other)

multiply matrix with a dense tensor

__neg__(self)

negate matrix

property T

transpose matrix

rowsupp(self, tol=0)

return row indices with nonzero/non-small entries

solve(self, rhs=None, *, lhs0=None, constrain=None, rconstrain=None, solver='direct', **solverargs)

Solve system given right hand side vector and/or constraints.

Parameters
  • rhs (float vector or None) – Right hand side vector. None implies all zeros.

  • lhs0 (class:float vector or None) – Initial values. None implies all zeros.

  • constrain (float or bool array, or None) – Column constraints. For float values, a number signifies a constraint, NaN signifies a free dof. For boolean, a True value signifies a constraint to the value in lhs0, a False value signifies a free dof. None implies no constraints.

  • rconstrain (bool array or None) – Row constrains. A True value signifies a constrains, a False value a free dof. None implies that the constraints follow those defined in constrain (by implication the matrix must be square).

  • solver (str) – Name of the solver algorithm. The set of available solvers depends on the type of the matrix (i.e. the active backend), although all matrices should implement at least the ‘direct’ solver.

  • **kwargs – All remaining arguments are passed on to the selected solver method.

Returns

Left hand side vector.

Return type

numpy.ndarray

submatrix(self, rows, cols)

Create submatrix from selected rows, columns.

Parameters
  • rows (bool/int array selecting rows for keeping) –

  • cols (bool/int array selecting columns for keeping) –

Returns

Matrix instance of reduced dimensions

Return type

Matrix

export(self, form)

Export matrix data to any of supported forms.

Parameters

form (str) –

  • “dense” : return matrix as a single dense array

  • ”csr” : return matrix as 3-tuple of (data, indices, indptr)

  • ”coo” : return matrix as 2-tuple of (data, (row, col))

__weakref__

list of weak references to the object (if defined)

class nutils.matrix.Numpy

Bases: nutils.matrix.Backend

matrix backend based on numpy array

class nutils.matrix.NumpyMatrix(core)

Bases: nutils.matrix.Matrix

matrix based on numpy array

class nutils.matrix.Scipy

Bases: nutils.matrix.Backend

matrix backend based on scipy’s sparse matrices

class nutils.matrix.ScipyMatrix(core, scipy)

Bases: nutils.matrix.Matrix

matrix based on any of scipy’s sparse matrices

class nutils.matrix.MKL(threading=<Threading.SEQUENTIAL: 1>)

Bases: nutils.matrix.Backend

matrix backend based on Intel’s Math Kernel Library

class Threading(value, names=None, *, module=None, qualname=None, type=None, start=1)

Bases: enum.Enum

An enumeration.

class nutils.matrix.Pardiso(libmkl)

Bases: object

simple wrapper for libmkl.pardiso

https://software.intel.com/en-us/mkl-developer-reference-c-pardiso

__weakref__

list of weak references to the object (if defined)

class nutils.matrix.MKLMatrix(data, rowptr, colidx, ncols, libmkl)

Bases: nutils.matrix.Matrix

matrix implementation based on sorted coo data