VeraGridEngine.Utils.Sparse packageο
Submodulesο
VeraGridEngine.Utils.Sparse.csc moduleο
- class VeraGridEngine.Utils.Sparse.csc.CscMat(arg1, shape=None, dtype=None, copy=False)[source]ο
Bases:
csc_matrixMatrix in compressed-column or triplet form.
- mο
- nο
- VeraGridEngine.Utils.Sparse.csc.csc_stack_2d_ff(mats, m_rows=1, m_cols=1, row_major=True)[source]ο
Assemble matrix from a list of matrices representing a βsuper matrixβ
|mat11 | mat12 | mat13 | |mat21 | mat22 | mat23 |
if row-major turns into:
mats = [mat11, mat12, mat13, mat21, mat22, mat23]
else: (it is column major)
mats = [mat11, mat21, mat12, mat22, mat31, mat32]
m_rows = 2 m_cols = 3
- Parameters:
mats β array of CSC matrices arranged in row-major or column-major order into a list
m_rows β number of rows of the mats structure
m_cols β number of cols of the mats structure
row_major β mats is sorted in row major, else it is sorted in column major
- Returns:
Final assembled matrix in CSC format
- VeraGridEngine.Utils.Sparse.csc.csc_stack_2d_ff_old(mats, m_rows=1, m_cols=1)[source]ο
Assemble matrix from a list of matrices representing a βsuper matrixβ
|mat11 | mat12 | mat13 | |mat21 | mat22 | mat23 |
turns into:
mats = [mat11, mat12, mat13, mat21, mat22, mat23] m_rows = 2 m_cols = 3
- Parameters:
mats β array of CSC matrices arranged in row-major order into a list
m_rows β number of rows of the mats structure
m_cols β number of cols of the mats structure
- Returns:
Final assembled matrix
- VeraGridEngine.Utils.Sparse.csc.dense_to_csc(mat: ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]], threshold: float) csc_matrix[source]ο
Extract the sparse matrix from a dense matrix where abs values are below a threshold :param mat: dense matrix :param threshold: threshold :return: CSC sparse matrix
- VeraGridEngine.Utils.Sparse.csc.diagc(n, value) csc_matrix[source]ο
Create constant value diagonal matrix :param n: size :param value: value :return:
- VeraGridEngine.Utils.Sparse.csc.diags(array: ndarray) csc_matrix[source]ο
Convert array to CSC diagonal matrix :param array: :return:
- VeraGridEngine.Utils.Sparse.csc.pack_3_by_4(A11: CscMat, A12: CscMat, A21: CscMat)[source]ο
Stack 3 CSC matrices in a 2 by 2 structure stack csc sparse float matrices like this: | A11 | A12 | | A21 | 0 | :param A11: Upper left matrix :param A12: Upper right matrix :param A21: Lower left matrix :return: Stitched matrix
- VeraGridEngine.Utils.Sparse.csc.pack_4_by_4(A11: CscMat, A12: CscMat, A21: CscMat, A22: CscMat)[source]ο
Stack 4 CSC matrices in a 2 by 2 structure stack csc sparse float matrices like this: | A11 | A12 | | A21 | A22 | :param A11: Upper left matrix :param A12: Upper right matrix :param A21: Lower left matrix :param A22: Lower right matrix :return: Stitched matrix
- VeraGridEngine.Utils.Sparse.csc.pack_4_by_4_scipy(A11: csc_matrix, A12: csc_matrix, A21: csc_matrix, A22: csc_matrix) csc_matrix[source]ο
Stack 4 CSC matrices in a 2 by 2 structure stack csc sparse float matrices like this: | A11 | A12 | | A21 | A22 | :param A11: Upper left matrix :param A12: Upper right matrix :param A21: Lower left matrix :param A22: Lower right matrix :return: Stitched matrix
- VeraGridEngine.Utils.Sparse.csc.scipy_to_mat(scipy_mat: csc_matrix)[source]ο
Build CsCMat from csc_matrix :param scipy_mat: :return: CscMat
- VeraGridEngine.Utils.Sparse.csc.sp_slice(mat: csc_matrix, rows, cols)[source]ο
- /*
This function performs the trivial slicing of the CSC sparse matrix A
Steps:
Slice the columns with βsp_submat_c(A, cols)β
convert to CSR with .t() {transpose}
Slice the rows with sp_submat_c(B, rows), because it is a CSR now
Convert the result back to CSC with the final .t()
*/
- Parameters:
mat
rows
cols
- Returns:
- VeraGridEngine.Utils.Sparse.csc.sp_slice_cols(mat: csc_matrix, cols: ndarray)[source]ο
Slice columns :param mat: Matrix to slice :param cols: vector of columns :return: New sliced matrix
VeraGridEngine.Utils.Sparse.csc2 moduleο
- class VeraGridEngine.Utils.Sparse.csc2.CSC(*args, **kwargs)[source]ο
Bases:
CSCnumba CSC matrix struct
- class_type = jitclass.CSC#7beb32d82cd0<n_rows:int32,n_cols:int32,nnz:int32,data:array(float64, 1d, A),indices:array(int32, 1d, A),indptr:array(int32, 1d, A),format:unicode_type>ο
- class VeraGridEngine.Utils.Sparse.csc2.CxCSC(*args, **kwargs)[source]ο
Bases:
CxCSCnumba CSC matrix struct
- class_type = jitclass.CxCSC#7beb32da03d0<n_rows:int32,n_cols:int32,nnz:int32,data:array(complex128, 1d, A),indices:array(int32, 1d, A),indptr:array(int32, 1d, A),format:unicode_type>ο
- VeraGridEngine.Utils.Sparse.csc2.csc_add_cx2(Am, An, Aindptr, Aindices, Adata, Bn, Bindptr, Bindices, Bdata)[source]ο
C = A + B
@param A: column-compressed matrix @param B: column-compressed matrix @return: C=alpha*A + beta*B, null on error (Cm, Cn, Cp, Ci, Cx)
- VeraGridEngine.Utils.Sparse.csc2.csc_add_ff(A: CSC, B: CSC, alpha=1.0, beta=1.0) CSC[source]ο
C = alpha*A + beta*B
@param A: column-compressed matrix @param B: column-compressed matrix @param alpha: scalar alpha @param beta: scalar beta @return: C=alpha*A + beta*B, null on error (Cm, Cn, Cp, Ci, Cx)
- VeraGridEngine.Utils.Sparse.csc2.csc_add_ff2(Am, An, Aindptr, Aindices, Adata, Bn, Bindptr, Bindices, Bdata)[source]ο
C = A + B
@param A: column-compressed matrix @param B: column-compressed matrix @return: C=alpha*A + beta*B, null on error (Cm, Cn, Cp, Ci, Cx)
- VeraGridEngine.Utils.Sparse.csc2.csc_cumsum_i(p, c, n)[source]ο
p [0..n] = cumulative sum of c [0..n-1], and then copy p [0..n-1] into c
@param p: size n+1, cumulative sum of c @param c: size n, overwritten with p [0..n-1] on output @param n: length of c @return: sum (c), null on error
- VeraGridEngine.Utils.Sparse.csc2.csc_matvec_cx(A: CxCSC, x: ndarray) ndarray[source]ο
- Parameters:
A
x
- Returns:
- VeraGridEngine.Utils.Sparse.csc2.csc_matvec_ff(A: CSC, x: ndarray) ndarray[source]ο
- Parameters:
A
x
- Returns:
- VeraGridEngine.Utils.Sparse.csc2.csc_multiply_cx(A: CxCSC, B: CSC) CxCSC[source]ο
Sparse matrix multiplication, C = A*B where A and B are CSC sparse matrices :param A: :param B: :return:
- VeraGridEngine.Utils.Sparse.csc2.csc_multiply_ff(A: CSC, B: CSC) CSC[source]ο
Sparse matrix multiplication, C = A*B where A and B are CSC sparse matrices :param A: :param B: :return:
- VeraGridEngine.Utils.Sparse.csc2.csc_multiply_ff2(Am, An, Ap, Ai, Ax, Bm, Bn, Bp, Bi, Bx)[source]ο
Sparse matrix multiplication, C = A*B where A and B are CSC sparse matrices :param Am: number of rows in A :param An: number of columns in A :param Ap: column pointers of A :param Ai: indices of A :param Ax: data of A :param Bm: number of rows in B :param Bn: number of columns in B :param Bp: column pointers of B :param Bi: indices of B :param Bx: data of B :return: Cm, Cn, Cp, Ci, Cx, Cnzmax
- VeraGridEngine.Utils.Sparse.csc2.csc_scatter_cx(Ap, Ai, Ax, j, beta, w, x, mark, Ci, nz)[source]ο
Scatters and sums a sparse vector A(:,j) into a dense vector, x = x + beta * A(:,j) :param Ap: :param Ai: :param Ax: :param j: the column of A to use :param beta: scalar multiplied by A(:,j) :param w: size m, node i is marked if w[i] = mark :param x: size m, ignored if null :param mark: mark value of w :param Ci: pattern of x accumulated in C.i :param nz: pattern of x placed in C starting at C.i[nz] :return: new value of nz, -1 on error, x and w are modified
- VeraGridEngine.Utils.Sparse.csc2.csc_scatter_f(Ap, Ai, Ax, j, beta, w, x, mark, Ci, nz)[source]ο
Scatters and sums a sparse vector A(:,j) into a dense vector, x = x + beta * A(:,j) :param Ap: :param Ai: :param Ax: :param j: the column of A to use :param beta: scalar multiplied by A(:,j) :param w: size m, node i is marked if w[i] = mark :param x: size m, ignored if null :param mark: mark value of w :param Ci: pattern of x accumulated in C.i :param nz: pattern of x placed in C starting at C.i[nz] :return: new value of nz, -1 on error, x and w are modified
- VeraGridEngine.Utils.Sparse.csc2.csc_spalloc_cx(m, n, nzmax)[source]ο
Allocate a sparse matrix (triplet form or compressed-column form).
@param m: number of rows @param n: number of columns @param nzmax: maximum number of entries @return: m, n, Aindptr, Aindices, Adata, Anzmax
- VeraGridEngine.Utils.Sparse.csc2.csc_spalloc_f(m, n, nzmax)[source]ο
Allocate a sparse matrix (triplet form or compressed-column form).
@param m: number of rows @param n: number of columns @param nzmax: maximum number of entries @return: m, n, Aindptr, Aindices, Adata, Anzmax
- VeraGridEngine.Utils.Sparse.csc2.csc_stack_2d_ff(mats: List[CSC], n_rows: int = 1, n_cols: int = 1) CSC[source]ο
Assemble matrix from a list of matrices representing a βsuper matrixβ
|mat11 | mat12 | mat13 | |mat21 | mat22 | mat23 |
turns into:
[mat11, mat12, mat13, mat21, mat22, mat23] m_rows = 2 m_cols = 3
- Parameters:
mats β list of CSC matrices arranged in row-major order (i.e. [mat11, mat12, mat13, mat21, mat22, mat23]
n_rows β number of rows of the mats structure
n_cols β number of cols of the mats structure
- Returns:
Final assembled matrix in CSC format
- VeraGridEngine.Utils.Sparse.csc2.diagc(m: int, value: float = 1.0) CSC[source]ο
Get diagonal sparse matrix from value :param m: size of the matrix :param value: value to set :return: CSC matrix
- VeraGridEngine.Utils.Sparse.csc2.diags(array: ndarray[tuple[Any, ...], dtype[float64]]) CSC[source]ο
Get diagonal sparse matrix from array :param array: :return:
- VeraGridEngine.Utils.Sparse.csc2.extend(A: CSC, last_col: ndarray[tuple[Any, ...], dtype[float64]], last_row: ndarray[tuple[Any, ...], dtype[float64]], corner_val: float) CSC[source]ο
- B = | A last_col |
- last_row val |
- Parameters:
A β Original matrix
last_col β last column to be added to A
last_row β last row to be added to A | last_col
corner_val β The botton-right corner value
- Returns:
Extended matrix
- VeraGridEngine.Utils.Sparse.csc2.mat_to_scipy(csc: CSC | CxCSC) csc_matrix[source]ο
CSC or CxCSC Matrix to Scipy :param csc: :return:
- VeraGridEngine.Utils.Sparse.csc2.pack_3_by_4(A: CSC, B: CSC, C: CSC) CSC[source]ο
Stack 3 CSC matrices in a 2 by 2 structure stack csc sparse float matrices like this: | A | B | | C | 0 | :param A: Upper left matrix :param B: Upper right matrix :param C: Lower left matrix :return: Stitched matrix
- VeraGridEngine.Utils.Sparse.csc2.pack_4_by_4(A: CSC, B: CSC, C: CSC, D: CSC) CSC[source]ο
Stack 4 CSC matrices in a 2 by 2 structure stack csc sparse float matrices like this: | A | B | | C | D | :param A: Upper left matrix :param B: Upper right matrix :param C: Lower left matrix :param D: Lower right matrix :return: Stitched matrix
- VeraGridEngine.Utils.Sparse.csc2.scipy_to_cxmat(mat: csc_matrix) CxCSC[source]ο
Scipy CSC matrix to CxCSC marix :param mat: Scipy CSC matrix :return: CxCSC marix
- VeraGridEngine.Utils.Sparse.csc2.scipy_to_mat(mat: csc_matrix) CSC[source]ο
Scipy CSC matrix to CSC marix :param mat: Scipy CSC matrix :return: CSC marix
- VeraGridEngine.Utils.Sparse.csc2.sp_slice(A: CSC, rows: ndarray[tuple[Any, ...], dtype[int64]], cols: ndarray[tuple[Any, ...], dtype[int64]])[source]ο
- /*
This function performs the trivial slicing of the CSC sparse matrix A
Steps:
Slice the columns with βsp_submat_c(A, cols)β
convert to CSR with .t() {transpose}
Slice the rows with sp_submat_c(B, rows), because it is a CSR now
Convert the result back to CSC with the final .t()
*/
- Parameters:
A
rows
cols
- Returns:
- VeraGridEngine.Utils.Sparse.csc2.sp_slice_cols(A: CSC, cols: ndarray[tuple[Any, ...], dtype[int64]]) CSC[source]ο
Slice columns :param A: Matrix to slice :param cols: vector of columns :return: New sliced matrix
- VeraGridEngine.Utils.Sparse.csc2.sp_slice_rows(mat: CSC, rows: ndarray) CSC[source]ο
Slice rows :param mat: :param rows: :return: CSC matrix
- VeraGridEngine.Utils.Sparse.csc2.sp_transpose(A: CSC) CSC[source]ο
Actual CSC transpose unlike scipyβs :param A: CSC matrix :return: CSC transposed matrix
VeraGridEngine.Utils.Sparse.csc_numba moduleο
- VeraGridEngine.Utils.Sparse.csc_numba.binary_find(N, x, array)[source]ο
Binary search :param N: size of the array :param x: value :param array: array :return: position where it is found. -1 if it is not found
- VeraGridEngine.Utils.Sparse.csc_numba.coo_to_csc(m, n, Ti, Tj, Tx, nnz)[source]ο
C = compressed-column form of a triplet matrix T. The columns of T are not sorted, and duplicate entries may be present in T.
- Parameters:
m β row number
n β column number
Ti β array of row indices
Tj β array of column indices
Tx β array of data
nnz β non-zero entries, if there are no duplicate entries, nnz = len(Tx)
- Returns:
Cm, Cn, Cp, Ci, Cx
- VeraGridEngine.Utils.Sparse.csc_numba.csc_add_ff(Am, An, Aindptr, Aindices, Adata, Bm, Bn, Bindptr, Bindices, Bdata, alpha, beta)[source]ο
C = alpha*A + beta*B
@param A: column-compressed matrix @param B: column-compressed matrix @param alpha: scalar alpha @param beta: scalar beta @return: C=alpha*A + beta*B, null on error (Cm, Cn, Cp, Ci, Cx)
- VeraGridEngine.Utils.Sparse.csc_numba.csc_cumsum_i(p, c, n)[source]ο
p [0..n] = cumulative sum of c [0..n-1], and then copy p [0..n-1] into c
@param p: size n+1, cumulative sum of c @param c: size n, overwritten with p [0..n-1] on output @param n: length of c @return: sum (c), null on error
- VeraGridEngine.Utils.Sparse.csc_numba.csc_diagonal(m, value=1.0)[source]ο
Build CSC diagonal matrix of the given value :param m: size :param value: value :return: CSC matrix
- VeraGridEngine.Utils.Sparse.csc_numba.csc_diagonal_from_array(array)[source]ο
- Parameters:
m
array
- Returns:
- VeraGridEngine.Utils.Sparse.csc_numba.csc_diagonal_from_complex_array(array)[source]ο
- Parameters:
m
array
- Returns:
- VeraGridEngine.Utils.Sparse.csc_numba.csc_diagonal_from_number(m: int, value: float)[source]ο
- Parameters:
m
value
- Returns:
- VeraGridEngine.Utils.Sparse.csc_numba.csc_mat_vec_ff(m, n, Ap, Ai, Ax, x)[source]ο
Sparse matrix times dense column vector, y = A * x. :param m: number of rows :param n: number of columns :param Ap: pointers :param Ai: indices :param Ax: data :param x: vector x (n) :return: vector y (m)
- VeraGridEngine.Utils.Sparse.csc_numba.csc_multiply_ff(Am, An, Ap, Ai, Ax, Bm, Bn, Bp, Bi, Bx)[source]ο
Sparse matrix multiplication, C = A*B where A and B are CSC sparse matrices :param Am: number of rows in A :param An: number of columns in A :param Ap: column pointers of A :param Ai: indices of A :param Ax: data of A :param Bm: number of rows in B :param Bn: number of columns in B :param Bp: column pointers of B :param Bi: indices of B :param Bx: data of B :return: Cm, Cn, Cp, Ci, Cx, Cnzmax
- VeraGridEngine.Utils.Sparse.csc_numba.csc_norm(n, Ap, Ax)[source]ο
Computes the 1-norm of a sparse matrix = max (sum (abs (A))), largest column sum.
@param A: column-compressed matrix @return: the 1-norm if successful, -1 on error
- VeraGridEngine.Utils.Sparse.csc_numba.csc_scatter_f(Ap, Ai, Ax, j, beta, w, x, mark, Ci, nz)[source]ο
Scatters and sums a sparse vector A(:,j) into a dense vector, x = x + beta * A(:,j) :param Ap: :param Ai: :param Ax: :param j: the column of A to use :param beta: scalar multiplied by A(:,j) :param w: size m, node i is marked if w[i] = mark :param x: size m, ignored if null :param mark: mark value of w :param Ci: pattern of x accumulated in C.i :param nz: pattern of x placed in C starting at C.i[nz] :return: new value of nz, -1 on error, x and w are modified
- VeraGridEngine.Utils.Sparse.csc_numba.csc_scatter_ff(Aindptr, Aindices, Adata, j, beta, w, x, mark, Ci, nz)[source]ο
Scatters and sums a sparse vector A(:,j) into a dense vector, x = x + beta * A(:,j) :param Aindptr: :param Aindices: :param Adata: :param j: the column of A to use :param beta: scalar multiplied by A(:,j) :param w: size m, node i is marked if w[i] = mark :param x: size m, ignored if null :param mark: mark value of w :param Ci: pattern of x accumulated in C.i :param nz: pattern of x placed in C starting at C.i[nz] :return: new value of nz, -1 on error, x and w are modified
- VeraGridEngine.Utils.Sparse.csc_numba.csc_spalloc_f(m, n, nzmax)[source]ο
Allocate a sparse matrix (triplet form or compressed-column form).
@param m: number of rows @param n: number of columns @param nzmax: maximum number of entries @return: m, n, Aindptr, Aindices, Adata, Anzmax
- VeraGridEngine.Utils.Sparse.csc_numba.csc_sprealloc_f(An, Aindptr, Aindices, Adata, nzmax)[source]ο
Change the max # of entries a sparse matrix can hold. :param An: number of columns :param Aindptr: csc column pointers :param Aindices: csc row indices :param Adata: csc data :param nzmax:new maximum number of entries :return: indices, data, nzmax
- VeraGridEngine.Utils.Sparse.csc_numba.csc_stack_2d_ff_col_major(mats_data, mats_indptr, mats_indices, mats_cols, mats_rows, m_rows=1, m_cols=1)[source]ο
Assemble matrix from a list of matrices representing a βsuper matrixβ
|mat11 | mat12 | mat13 | |mat21 | mat22 | mat23 |
turns into:
mats = [mat11, mat12, mat13, mat21, mat22, mat23] m_rows = 2 m_cols = 3
- Parameters:
mats_data β array of numpy arrays with the data of each CSC matrix
mats_indptr β array of numpy arrays with the indptr of each CSC matrix
mats_indices β array of numpy arrays with the indices of each CSC matrix
mats_cols β array with the number of columns of each CSC matrix
mats_rows β array with the number of rows of each CSC matrix
m_rows β number of rows of the mats structure
m_cols β number of cols of the mats structure
- Returns:
Final assembled matrix
- VeraGridEngine.Utils.Sparse.csc_numba.csc_stack_2d_ff_row_major(mats_data, mats_indptr, mats_indices, mats_cols, mats_rows, m_rows=1, m_cols=1)[source]ο
Assemble matrix from a list of matrices representing a βsuper matrixβ
|mat11 | mat12 | mat13 | |mat21 | mat22 | mat23 |
turns into:
mats = [mat11, mat12, mat13, mat21, mat22, mat23] m_rows = 2 m_cols = 3
- Parameters:
mats_data β array of numpy arrays with the data of each CSC matrix
mats_indptr β array of numpy arrays with the indptr of each CSC matrix
mats_indices β array of numpy arrays with the indices of each CSC matrix
mats_cols β array with the number of columns of each CSC matrix
mats_rows β array with the number of rows of each CSC matrix
m_rows β number of rows of the mats structure
m_cols β number of cols of the mats structure
- Returns:
Final assembled matrix
- VeraGridEngine.Utils.Sparse.csc_numba.csc_stack_3_by_4_ff(am, an, Ai, Ap, Ax, bm, bn, Bi, Bp, Bx, cm, cn, Ci, Cp, Cx)[source]ο
stack csc sparse float matrices like this: | A | B | | C | 0 |
- Parameters:
am
an
Ai
Ap
Ax
bm
bn
Bi
Bp
Bx
cm
cn
Ci
Cp
Cx
- Returns:
- VeraGridEngine.Utils.Sparse.csc_numba.csc_stack_4_by_4_ff(am, an, Ai, Ap, Ax, bm, bn, Bi, Bp, Bx, cm, cn, Ci, Cp, Cx, dm, dn, Di, Dp, Dx)[source]ο
stack csc sparse float matrices like this: | A | B | | C | D |
- Parameters:
am
an
Ai
Ap
Ax
bm
bn
Bi
Bp
Bx
cm
cn
Ci
Cp
Cx
dm
dn
Di
Dp
Dx
- Returns:
- VeraGridEngine.Utils.Sparse.csc_numba.csc_sub_matrix(Am, Annz, Ap, Ai, Ax, rows, cols)[source]ο
CSC matrix sub-matrix view :param Am: number of rows :param Annz: number of non-zero entries :param Ap: Column pointers :param Ai: Row indices :param Ax: Data :param rows: array of selected rows: must be sorted! to use the binary search :param cols: array of columns: should be sorted :return:
- VeraGridEngine.Utils.Sparse.csc_numba.csc_sub_matrix_cols(Am, Anz, Ap, Ai, Ax, cols)[source]ο
Get SCS arbitrary sub-matrix with all the rows :param Am: number of rows :param Anz: number of non-zero entries :param Ap: Column pointers :param Ai: Row indices :param Ax: Data :param cols: column indices to keep :return: CSC sub-matrix (n, new_col_ptr, new_row_ind, new_val)
- VeraGridEngine.Utils.Sparse.csc_numba.csc_sub_matrix_old(Am, Anz, Ap, Ai, Ax, rows, cols)[source]ο
Get SCS arbitrary sub-matrix :param Am: number of rows :param Anz: number of non-zero entries :param Ap: Column pointers :param Ai: Row indices :param Ax: Data :param rows: row indices to keep :param cols: column indices to keep :return: CSC sub-matrix (n, new_col_ptr, new_row_ind, new_val)
- VeraGridEngine.Utils.Sparse.csc_numba.csc_sub_matrix_rows(An, Anz, Ap, Ai, Ax, rows)[source]ο
Get SCS arbitrary sub-matrix :param An: number of rows :param Anz: number of non-zero entries :param Ap: Column pointers :param Ai: Row indices :param Ax: Data :param rows: row indices to keep :return: CSC sub-matrix (n, new_col_ptr, new_row_ind, new_val)
- VeraGridEngine.Utils.Sparse.csc_numba.csc_to_csr(m, n, Ap, Ai, Ax, Bp, Bi, Bx)[source]ο
Convert a CSC Matrix into a CSR Matrix :param m: number of rows :param n: number of columns :param Ap: indptr of the CSC matrix :param Ai: indices of the CSC matrix :param Ax: data of the CSC matrix :param Bp: indptr of the CSR matrix (to compute, size βm+1β, has to be initialized to zeros) :param Bi: indices of the CSR matrix (to compute, size nnz) :param Bx: data of the CSR matrix (to compute, size nnz)
- VeraGridEngine.Utils.Sparse.csc_numba.csc_to_dense(m, n, indptr, indices, data)[source]ο
Convert csc matrix to dense :param m: :param n: :param indptr: :param indices: :param data: :return: 2d numpy array
- VeraGridEngine.Utils.Sparse.csc_numba.csc_transpose(m, n, Ap, Ai, Ax)[source]ο
Transpose matrix :param m: A.m :param n: A.n :param Ap: A.indptr :param Ai: A.indices :param Ax: A.data :return: Cm, Cn, Cp, Ci, Cx
- VeraGridEngine.Utils.Sparse.csc_numba.dense_to_csc_numba(mat: ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]], threshold: float) Tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[int64]], ndarray[tuple[Any, ...], dtype[int64]]][source]ο
Extract the sparse matrix from a dense matrix where abs values are below a threshold :param mat: dense matrix :param threshold: threshold :return: data, indices, indptr
- VeraGridEngine.Utils.Sparse.csc_numba.diag_positions(n, Ap, Ai)[source]ο
get the positions of the diagonal in the CSC data scheme :param n: number of rows and columns (must be square) :param Ap: pointers :param Ai: indices :return: vector pos (n)
- VeraGridEngine.Utils.Sparse.csc_numba.find_islands(node_number, indptr, indices)[source]ο
Method to get the islands of a graph This is the non-recursive version :return: islands list where each element is a list of the node indices of the island
- VeraGridEngine.Utils.Sparse.csc_numba.get_sparse_array_numba(arr: ndarray[tuple[Any, ...], dtype[float64]], threshold: float) Tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[int64]]][source]ο
Extract the sparse array from a dense array where abs values are below a threshold :param arr: dense matrix :param threshold: threshold :return: data, indices
- VeraGridEngine.Utils.Sparse.csc_numba.sp_submat_c_numba(nrows, ptrs, indices, values, cols)[source]ο
slice CSC columns :param nrows: number of rows of the matrix :param ptrs: row pointers :param indices: column indices :param values: data :param cols: vector of columns to slice :return: new_indices, new_col_ptr, new_val, nrows, ncols
VeraGridEngine.Utils.Sparse.sparse_array moduleο
- class VeraGridEngine.Utils.Sparse.sparse_array.SparseArray[source]ο
Bases:
object- copy() SparseArray[source]ο
Get a deep copy of this object :return: A new SparseArray copy of this object
- create(size: int, default_value: type | DeviceType | GenericAlias, data: Dict[int, int | float | bool | complex] | None = None) SparseArray[source]ο
Build sparse from definition :param size: size :param default_value: default value :param data: data map
- create_from_array(array: ndarray[tuple[Any, ...], dtype[float64]], default_value: type | DeviceType | GenericAlias) SparseArray[source]ο
Build sparse from array :param array: NumericVec :param default_value: default value of the array
- create_from_dict(default_value: type | DeviceType | GenericAlias, size: int, map_data: Dict[int, int | float | bool | complex]) SparseArray[source]ο
Create this array from dict data :param default_value: :param size: :param map_data: :return:
- property default_valueο
Default value getter :return: numeric value
- property dtype: bool | int | float | DeviceTypeο
Get the declared type :return: type
- get_map() Dict[int, int | float | bool | complex][source]ο
Return the dictionary hosting the sparse data :return: Dict[int, Numeric]
- info()[source]ο
Return dictionary with information about the profile object and its content :return:
- insert(i: int, x: int | float | bool | complex)[source]ο
Insert an element in the data dictionary :param i: :param x: :return:
- resample(indices: ndarray[tuple[Any, ...], dtype[int64]])[source]ο
Resample this sparse array in-place :param indices: array of integer indices (not repeated)
- resize(n: int)[source]ο
Resize the array :param n:number of elements.
If n is smaller than the current container size, the content is reduced to its first n elements, removing those beyond (and destroying them)
- slice(indices: ndarray[tuple[Any, ...], dtype[int64]]) SparseArray[source]ο
Get a resampled copy of this sparse array :param indices: array of integer indices (not repeated)
- class VeraGridEngine.Utils.Sparse.sparse_array.SparseObjectArray(n: int)[source]ο
Bases:
objectSparseArray
- copy() SparseObjectArray[source]ο
Get a deep copy of this object :return: A new SparseObjectArray copy of this object
- get_map() Dict[int, object][source]ο
Return the dictionary hosting the sparse data :return: Dict[int, Numeric]
- info()[source]ο
Return dictionary with information about the profile object and its content :return:
- insert(i: int, x: object)[source]ο
Insert an element in the data dictionary :param i: :param x: :return:
- resample(indices: ndarray[tuple[Any, ...], dtype[int64]])[source]ο
Resample this sparse array in-place :param indices: array of integer indices (not repeated)
- resize(n: int)[source]ο
Resize the array :param n:number of elements.
If n is smaller than the current container size, the content is reduced to its first n elements, removing those beyond (and destroying them)
- slice(indices: ndarray[tuple[Any, ...], dtype[int64]]) SparseObjectArray[source]ο
Get a resampled copy of this sparse array :param indices: array of integer indices (not repeated)
- VeraGridEngine.Utils.Sparse.sparse_array.check_type(dtype: type | DeviceType | GenericAlias, value: Any) bool[source]ο
Checks that the type of value is the declared type in the profile :param dtype: expected type :param value: Any value :return: