taichi.linalg#

class taichi.linalg.SparseMatrix(n=None, m=None, sm=None, dtype=f32)#

Taichi’s Sparse Matrix class

A sparse matrix allows the programmer to solve a large linear system.

Parameters
  • n (int) – the first dimension of a sparse matrix.

  • m (int) – the second dimension of a sparse matrix.

  • sm (SparseMatrix) – another sparse matrix that will be built from.

shape(self)#

The shape of the sparse matrix.

transpose(self)#

Sparse Matrix transpose.

Returns

The transposed sparse mastrix.

class taichi.linalg.SparseMatrixBuilder(num_rows=None, num_cols=None, max_num_triplets=0, dtype=f32)#

A python wrap around sparse matrix builder.

Use this builder to fill the sparse matrix.

Parameters
  • num_rows (int) – the first dimension of a sparse matrix.

  • num_cols (int) – the second dimension of a sparse matrix.

  • max_num_triplets (int) – the maximum number of triplets.

build(self, dtype=f32, _format='CSR')#

Create a sparse matrix using the triplets

print_triplets(self)#

Print the triplets stored in the builder

class taichi.linalg.SparseSolver(dtype=f32, solver_type='LLT', ordering='AMD')#

Sparse linear system solver

Use this class to solve linear systems represented by sparse matrices.

Parameters
  • solver_type (str) – The factorization type.

  • ordering (str) – The method for matrices re-ordering.

analyze_pattern(self, sparse_matrix)#

Reorder the nonzero elements of the matrix, such that the factorization step creates less fill-in.

Parameters

sparse_matrix (SparseMatrix) – The sparse matrix to be analyzed.

compute(self, sparse_matrix)#

This method is equivalent to calling both analyze_pattern and then factorize.

Parameters

sparse_matrix (SparseMatrix) – The sparse matrix to be computed.

factorize(self, sparse_matrix)#

Do the factorization step

Parameters

sparse_matrix (SparseMatrix) – The sparse matrix to be factorized.

info(self)#

Check if the linear systems are solved successfully.

Returns

True if the solving process succeeded, False otherwise.

Return type

bool

solve(self, b)#

Computes the solution of the linear systems. :param b: The right-hand side of the linear systems. :type b: numpy.array or Field

Returns

The solution of linear systems.

Return type

numpy.array

class taichi.linalg.sparse_matrix_builder#

Bases: taichi.types.annotations.sparse_matrix_builder