Misc methods

Test matrix generation

ExtendableSparse.fdrand!Method
fdrand!(A, nx; ...)
fdrand!(A, nx, ny; ...)
fdrand!(A, nx, ny, nz; update, rand)

After setting all nonzero entries to zero, fill resp. update matrix with finite difference discretization data on a unit hypercube. See fdrand for documentation of the parameters.

It is required that size(A)==(N,N) where N=nx*ny*nz

source
ExtendableSparse.fdrandMethod
fdrand(, nx; ...)
fdrand(, nx, ny; ...)
fdrand(, nx, ny, nz; matrixtype, update, rand, symmetric)
fdrand(nx; ...)

Create matrix for a mock finite difference operator for a diffusion problem with random coefficients on a unit hypercube $\Omega\subset\mathbb R^d$. with $d=1$ if nx>1 && ny==1 && nz==1, $d=2$ if nx>1 && ny>1 && nz==1 and $d=3$ if nx>1 && ny>1 && nz>1 . In the symmetric case it corresponds to

\[ \begin{align*} -\nabla a \nabla u &= f&& \text{in}\; \Omega \\ a\nabla u\cdot \vec n + b u &=g && \text{on}\; \partial\Omega \end{align*}\]

The matrix is irreducibly diagonally dominant, has positive main diagonal entries and nonpositive off-diagonal entries, hence it has the M-Property. Therefore, its inverse will be a dense matrix with positive entries, and the spectral radius of the Jacobi iteration matrix $ho(I-D(A)^{-1}A)<1$ .

Moreover, in the symmetric case, it is positive definite.

Parameters+ default values:

Parameter + default valeDescription
nxNumber of unknowns in x direction
nyNumber of unknowns in y direction
nzNumber of unknowns in z direction
matrixtype = SparseMatrixCSCMatrix type
update = (A,v,i,j)-> A[i,j]+=vElement update function
rand =()-> rand()Random number generator
symmetric=trueWhether to create symmetric matrix or not

The sparsity structure is fixed to an orthogonal grid, resulting in a 3, 5 or 7 diagonal matrix depending on dimension. The entries are random unless e.g. rand=()->1 is passed as random number generator. Tested for Matrix, SparseMatrixCSC, ExtendableSparseMatrix, Tridiagonal, SparseMatrixLNK and :COO

source
ExtendableSparse.fdrand_cooFunction
fdrand_coo(T, nx; ...)
fdrand_coo(T, nx, ny; ...)
fdrand_coo(T, nx, ny, nz; rand)

Create SparseMatrixCSC via COO intermedite arrays. Just for benchmarking.

source
ExtendableSparse.sprand!Method
sprand!(A, xnnz)

Fill empty sparse matrix A with random nonzero elements from interval [1,2] using incremental assembly.

source
ExtendableSparse.sprand_sdd!Method
sprand_sdd!(A; nnzrow)

Fill sparse matrix with random entries such that it becomes strictly diagonally dominant and thus invertible and has a fixed number nnzrow (default: 4) of nonzeros in its rows. The matrix bandwidth is bounded by sqrt(n) in order to resemble a typical matrix of a 2D piecewise linear FEM discretization.

source

Methods for SparseMatrixCSC

Base.:*Method
*(
    d::Diagonal,
    ext::ExtendableSparse.AbstractExtendableSparseMatrixCSC
) -> Any
source
Base.:*Method
*(
    ext::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    d::Diagonal
) -> Any
source
Base.:*Method
*(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    B::ExtendableSparse.AbstractExtendableSparseMatrixCSC
) -> ExtendableSparse.GenericExtendableSparseMatrixCSC
source
Base.:+Method
+(
    ext::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    csc::SparseMatrixCSC
) -> SparseMatrixCSC
source
Base.:+Method
+(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    B::ExtendableSparse.AbstractExtendableSparseMatrixCSC
) -> ExtendableSparse.GenericExtendableSparseMatrixCSC
source
Base.:-Method
-(
    ext::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    csc::SparseMatrixCSC
) -> SparseMatrixCSC
source
Base.:-Method
-(
    csc::SparseMatrixCSC,
    ext::ExtendableSparse.AbstractExtendableSparseMatrixCSC
) -> SparseMatrixCSC
source
Base.:-Method
-(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    B::ExtendableSparse.AbstractExtendableSparseMatrixCSC
) -> ExtendableSparse.GenericExtendableSparseMatrixCSC
source
Base.:\Method
 Base.:\(::AbstractExtendableSparseMatrixCSC, b)

\ for ExtendableSparse. It calls the LU factorization form Sparspak.jl, unless GPL components are allowed in the Julia sysimage and the floating point type of the matrix is Float64 or Complex64. In that case, Julias standard `` is called, which is realized via UMFPACK.

source
Base.:\Method
 Base.:\(Hermitian(::AbstractExtendableSparseMatrixCSC), b)

\ for Hermitian{ExtendableSparse}

source
Base.:\Method
 Base.:\(Symmetric(::AbstractExtendableSparseMatrixCSC), b)

\ for Symmetric{ExtendableSparse}

source
Base.eltypeMethod
Base.eltype(::AbstractExtendableSparseMatrixCSC{Tv, Ti})

Return element type.

source
Base.getindexMethod
getindex(
    ext::ExtendableSparse.GenericExtendableSparseMatrixCSC,
    i::Integer,
    j::Integer
) -> Any
source
Base.getindexMethod
getindex(
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC,
    i::Integer,
    j::Integer
) -> Any
source
Base.setindex!Method
setindex!(
    ext::ExtendableSparse.GenericExtendableSparseMatrixCSC,
    v,
    i::Integer,
    j::Integer
) -> Any
source
Base.setindex!Method
setindex!(
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC,
    v,
    i::Integer,
    j::Integer
) -> AbstractVecOrMat
source
Base.showMethod
Base.show(::IO, ::MIME"text/plain", ext::AbstractExtendableSparseMatrixCSC)

flush! and use the show method of SparseMatrixCSC to show the content.

source
Base.similarMethod
similar(
    m::ExtendableSparse.GenericExtendableSparseMatrixCSC{Tm, Tv, Ti}
) -> Any
source
Base.similarMethod
similar(
    m::ExtendableSparse.GenericExtendableSparseMatrixCSC{Tm, Tv, Ti},
    _::Type{T}
) -> Any
source
Base.sizeMethod
Base.size(ext::AbstractExtendableSparseMatrixCSC)

Return size of matrix.

source
ExtendableSparse.eliminate_dirichletMethod
eliminate_dirichlet(A,dirichlet_marker)

Create a copy B of A sharing the sparsity pattern. Eliminate dirichlet nodes in B by setting

    B[:,i]=0; B[i,:]=0; B[i,i]=1

for a node i marked as Dirichlet.

Returns B.

source
ExtendableSparse.findindexMethod
findindex(csc::SparseMatrixCSC{T}, i, j) -> Int64

Return index corresponding to entry [i,j] in the array of nonzeros, if the entry exists, otherwise, return 0.

source
ExtendableSparse.flush!Method
flush!(csc::SparseMatrixCSC) -> SparseMatrixCSC

Trivial flush! method for allowing to run the code with both ExtendableSparseMatrix and SparseMatrixCSC.

source
ExtendableSparse.flush!Method
flush!(
    ext::ExtendableSparse.GenericExtendableSparseMatrixCSC{Tm, Tv, Ti}
) -> ExtendableSparse.GenericExtendableSparseMatrixCSC{Tm, Tv, Ti} where {Tm, Tv, Ti}
source
ExtendableSparse.flush!Method
flush!(
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC{Tm, Tv, Ti}
) -> ExtendableSparse.GenericMTExtendableSparseMatrixCSC{Tm, Tv, Ti} where {Tm, Tv, Ti}
source
ExtendableSparse.partitioning!Method
partitioning!(
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC{Tm, Tv, Ti},
    colparts,
    partnodes
) -> ExtendableSparse.GenericMTExtendableSparseMatrixCSC{Tm, Tv, Ti} where {Tm, Tv, Ti}

Set node partitioning.

source
ExtendableSparse.pattern_equalMethod
pattern_equal(a::SparseMatrixCSC,b::SparseMatrixCSC)

Check if sparsity patterns of two SparseMatrixCSC objects are equal. This is generally faster than comparing hashes.

source
ExtendableSparse.rawupdateindex!Function
rawupdateindex!(A::AbstractExtendableSparseMatrixCSC,op,v,i,j,part = 1)

Add or update entry of A: A[i,j]=op(A[i,j],v) without checking if a zero is inserted. The optional parameter part denotes the partition.

source
ExtendableSparse.rawupdateindex!Function
rawupdateindex!(
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC,
    op,
    v,
    i,
    j
) -> Any
rawupdateindex!(
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC,
    op,
    v,
    i,
    j,
    tid
) -> Any
source
ExtendableSparse.rawupdateindex!Function
rawupdateindex!(
    ext::ExtendableSparse.GenericExtendableSparseMatrixCSC,
    op,
    v,
    i,
    j
) -> Any
rawupdateindex!(
    ext::ExtendableSparse.GenericExtendableSparseMatrixCSC,
    op,
    v,
    i,
    j,
    part
) -> Any
source
ExtendableSparse.reset!Method
reset!(
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC
) -> ExtendableSparse.GenericMTExtendableSparseMatrixCSC
source
ExtendableSparse.reset!Method
reset!(
    ext::ExtendableSparse.GenericExtendableSparseMatrixCSC{Tm, Tv, Ti}
) -> ExtendableSparse.GenericExtendableSparseMatrixCSC{Tm, Tv, Ti} where {Tm, Tv, Ti}
source
ExtendableSparse.reset!Method
reset!(
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC{Tm, Tv, Ti},
    p::Integer
) -> ExtendableSparse.GenericMTExtendableSparseMatrixCSC{Tm, Tv, Ti} where {Tm, Tv, Ti}
source
ExtendableSparse.updateindex!Function
updateindex!(
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC,
    op,
    v,
    i,
    j
) -> Any
updateindex!(
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC,
    op,
    v,
    i,
    j,
    tid
) -> Any
source
ExtendableSparse.updateindex!Method
updateindex!(
    csc::SparseMatrixCSC{Tv, Ti<:Integer},
    op,
    v,
    i,
    j
) -> SparseMatrixCSC

Update element of the matrix with operation op without introducing new nonzero elements.

This can replace the following code and save one index search during access:

using ExtendableSparse # hide
using SparseArrays # hide
A=spzeros(3,3)
A[1,2]+=0.1
A
using ExtendableSparse # hide
using SparseArrays # hide
A=spzeros(3,3)
updateindex!(A,+,0.1,1,2)
A
source
LinearAlgebra.condFunction
cond(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC
) -> Any
cond(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    p::Real
) -> Any

flush! and calculate cond from cscmatrix

source
LinearAlgebra.ldiv!Method
ldiv!(
    r::AbstractArray,
    ext::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    x::AbstractArray
) -> SparseMatrixCSC

flush! and ldiv! with ext.cscmatrix

source
LinearAlgebra.mul!Method
mul!(
    r::AbstractVecOrMat,
    ext::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    x::AbstractVecOrMat
)

flush! and multiply with ext.cscmatrix

source
LinearAlgebra.mul!Method
mul!(
    r::AbstractVecOrMat,
    ext::ExtendableSparse.GenericMTExtendableSparseMatrixCSC,
    x::AbstractVecOrMat
)
source
LinearAlgebra.normFunction
norm(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC
) -> Any
norm(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    p::Real
) -> Any

flush! and calculate norm from cscmatrix

source
LinearAlgebra.opnormFunction
opnorm(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC
) -> Any
opnorm(
    A::ExtendableSparse.AbstractExtendableSparseMatrixCSC,
    p::Real
) -> Any

flush! and calculate opnorm from cscmatrix

source
SparseArrays.nnzMethod
SparseArrays.nnz(ext::AbstractExtendableSparseMatrixCSC)

flush! and return number of nonzeros in ext.cscmatrix.

source
SparseArrays.nonzerosMethod
SparseArrays.nonzeros(ext::AbstractExtendableSparseMatrixCSC) = nonzeros(sparse(ext))

flush! and return nonzeros in ext.cscmatrix.

source
SparseArrays.sparseMethod
SparseArrays.sparse(A::AbstractExtendableSparseMatrixCSC)

Return SparseMatrixCSC which contains all matrix entries introduced so far.

source