SuiteSparseGraphBLAS.from_type
— Methodfrom_type(type, m, n)
Create an empty GBMatrix
of size m
×n
from the given type type
.
SuiteSparseGraphBLAS.from_lists
— Methodfrom_lists(I, J, V; m = nothing, n = nothing, type = nothing, combine = Binaryop.FIRST)
Create a new GBMatrix
from the given lists of row indices, column indices and values. If m
and n
are not provided, they are computed from the max values of the row and column indices lists, respectively. If type
is not provided, it is inferred from the values list. A combiner Binary Operator
can be provided to manage duplicates values. If it is not provided, the default BinaryOp.FIRST
is used.
Arguments
I
: the list of row indices.J
: the list of column indices.V
: the list of values.[m]
: the number of rows.[n]
: the number of columns.[type]
: the type of the elements of the matrix.[combine]
: theBinaryOperator
which assembles any duplicate entries with identical indices.
Examples
julia> from_lists([1,1,2,3], [1,2,2,2], [5,2,7,4])
3x2 GBMatrix{Int64} with 4 stored entries:
[1, 1] = 5
[1, 2] = 2
[2, 2] = 7
[3, 2] = 4
julia> from_lists([1,1,2,3], [1,2,2,2], [5,2,7,4], type=Float64)
3x2 GBMatrix{Float64} with 4 stored entries:
[1, 1] = 5.0
[1, 2] = 2.0
[2, 2] = 7.0
[3, 2] = 4.0
julia> from_lists([1,1,2,3], [1,2,2,2], [5,2,7,4], m=10, n=4)
10x4 GBMatrix{Int64} with 4 stored entries:
[1, 1] = 5
[1, 2] = 2
[2, 2] = 7
[3, 2] = 4
julia> A = from_lists([1,1,2,3], [1,1,2,2], [5,2,7,4], combine=Binaryop.PLUS)
3x2 GBMatrix{Int64} with 3 stored entries:
[1, 1] = 7
[2, 2] = 7
[3, 2] = 4
SuiteSparseGraphBLAS.from_matrix
— Functionfrom_matrix(m)
Create a GBMatrix
from the given Matrix
m
.
Examples
julia> from_matrix([1 0 2; 0 0 3; 0 1 0])
3x3 GBMatrix{Int64} with 4 stored entries:
[1, 1] = 1
[1, 3] = 2
[2, 3] = 3
[3, 2] = 1
Base.identity
— Functionidentity(type, n)
Create an identity GBMatrix
of size n
×n
with the given type type
.
Examples
julia> identity(Bool, 4)
4x4 GBMatrix{Bool} with 4 stored entries:
[1, 1] = true
[2, 2] = true
[3, 3] = true
[4, 4] = true
Base.Matrix
— MethodMatrix(A::GBMatrix{T}) -> Matrix{T}
Construct a Matrix{T}
from a GBMatrix{T}
A.
SuiteSparseGraphBLAS.square
— Functionsquare(m::GBMatrix)
Return true if m
is a square matrix.
Examples
julia> A = from_matrix([1 2; 4 5]);
julia> square(A)
true
Base.size
— Methodsize(m::GBMatrix, [dim])
Return a tuple containing the dimensions of m. Optionally you can specify a dimension to just get the length of that dimension.
Examples
julia> A = from_matrix([1 2 3; 4 5 6]);
julia> size(A)
(2, 3)
julia> size(A, 1)
2
SuiteSparseGraphBLAS.findnz
— Methodfindnz(m::GBMatrix)
Return a tuple (I, J, V)
where I
and J
are the row and column lists of the "non-zero" values in m
, and V
is a list of "non-zero" values.
Examples
julia> A = from_matrix([1 2 0; 0 0 1]);
julia> findnz(A)
([1, 1, 2], [1, 2, 3], [1, 2, 1])
Base.:==
— Method==(A, B)
Check if two matrices A
and B
are equal.
SuiteSparseGraphBLAS.nnz
— Methodnnz(m::GBMatrix)
Return the number of entries in a matrix m
.
Examples
julia> A = from_matrix([1 2 0; 0 0 1]);
julia> nnz(A)
3
SuiteSparseGraphBLAS.clear!
— Methodclear!(m::GBMatrix)
Clear all entries from a matrix m
.
Base.copy
— Methodcopy(v::GBVector)
Create a copy of v
.
Examples
julia> v = from_vector([1, 0, 0, 1, 2, 0]);
julia> u = copy(v)
6-element GBVector{Int64} with 3 stored entries:
[1] = 1
[4] = 1
[5] = 2
julia> u == v
true
julia> u === v
false
copy(m::GBMatrix)
Create a copy of m
.
Examples
julia> A = from_matrix([1 0 1; 0 0 2; 2 0 1]);
julia> B = copy(A)
3x3 GBMatrix{Int64} with 5 stored entries:
[1, 1] = 1
[1, 3] = 1
[2, 3] = 2
[3, 1] = 2
[3, 3] = 1
julia> A == B
true
julia> A === B
false
Base.lastindex
— Methodlastindex(m::GBMatrix, [d])
Return the last index of a matrix m
. If d
is given, return the last index of m
along dimension d
.
Examples
julia> A = from_matrix([1 2 0; 0 0 1]);
julia> lastindex(A)
(2, 3)
julia> lastindex(A, 2)
3
SuiteSparseGraphBLAS.mxm
— Functionmxm(A::GBMatrix, B::GBMatrix; kwargs...)
Multiply two sparse matrix A
and B
using the semiring
. If a semiring
is not provided, it uses the default semiring.
Arguments
A
: the first matrix.B
: the second matrix.[out]
: the output matrix for result.[semiring]
: the semiring to use.[accum]
: optional accumulator.[mask]
: optional mask.[desc]
: descriptor forout
,mask
,A
andB
.
Examples
julia> A = from_matrix([1 2; 3 4]);
julia> B = copy(A);
julia> mxm(A, B, semiring = Semirings.PLUS_TIMES)
2x2 GBMatrix{Int64} with 4 stored entries:
[1, 1] = 7
[1, 2] = 10
[2, 1] = 15
[2, 2] = 22
SuiteSparseGraphBLAS.mxv
— Functionmxv(A::GBMatrix, u::GBVector; kwargs...) -> GBVector
Multiply a sparse matrix A
times a column vector u
.
Arguments
A
: the sparse matrix.u
: the column vector.[out]
: the output vector for result.[semiring]
: the semiring to use.[accum]
: optional accumulator.[mask]
: optional mask.[desc]
: descriptor forout
,mask
,A
andB
.
Examples
julia> A = from_matrix([1 2; 3 4]);
julia> u = from_vector([1, 2]);
julia> mxv(A, u, semiring = Semirings.PLUS_TIMES)
2-element GBVector{Int64} with 2 stored entries:
[1] = 5
[2] = 11
SuiteSparseGraphBLAS.emult
— Methodemult(A::GBMatrix, B::GBMatrix; kwargs...)
Compute the element-wise "multiplication" of two matrices A
and B
, using a Binary Operator
, a Monoid
or a Semiring
. If given a Monoid
, the additive operator of the monoid is used as the multiply binary operator. If given a Semiring
, the multiply operator of the semiring is used as the multiply binary operator.
Arguments
A
: the first matrix.B
: the second matrix.[out]
: the output matrix for result.[operator]
: the operator to use. Can be either aBinary Operator
, or aMonoid
or aSemiring
.[accum]
: optional accumulator.[mask]
: optional mask.[desc]
: descriptor forout
,mask
,A
andB
.
Examples
julia> A = from_matrix([1 2; 3 4]);
julia> B = copy(A);
julia> emult(A, B, operator = Binaryop.PLUS)
2x2 GBMatrix{Int64} with 4 stored entries:
[1, 1] = 2
[1, 2] = 4
[2, 1] = 6
[2, 2] = 8
SuiteSparseGraphBLAS.eadd
— Methodeadd(A::GBMatrix, B::GBMatrix; kwargs...)
Compute the element-wise "addition" of two matrices A
and B
, using a Binary Operator
, a Monoid
or a Semiring
. If given a Monoid
, the additive operator of the monoid is used as the add binary operator. If given a Semiring
, the additive operator of the semiring is used as the add binary operator.
Arguments
A
: the first matrix.B
: the second matrix.[out]
: the output matrix for result.[operator]
: the operator to use. Can be either a Binary Operator, or a Monoid or a Semiring.[accum]
: optional accumulator.[mask]
: optional mask.[desc]
: descriptor forout
,mask
,A
andB
.
Examples
julia> A = from_matrix([1 2; 3 4]);
julia> B = copy(A);
julia> eadd(A, B, operator = Binaryop.TIMES)
2x2 GBMatrix{Int64} with 4 stored entries:
[1, 1] = 1
[1, 2] = 4
[2, 1] = 9
[2, 2] = 16
SuiteSparseGraphBLAS.apply
— Methodapply(u::GBVector; kwargs...) -> GBVector
Apply a Unary Operator
to the entries of a vector u
, creating a new vector.
Arguments
u
: the sparse vector.[out]
: the output vector for result.[unaryop]
: the unary operator to use.[accum]
: optional accumulator.[mask]
: optional mask.[desc]
: descriptor forout
andmask
.
Examples
julia> u = from_vector([-1, 2, -3]);
julia> apply(u, unaryop = Unaryop.ABS)
3-element GBVector{Int64} with 3 stored entries:
[1] = 1
[2] = 2
[3] = 3
apply(A::GBMatrix; kwargs...)
Apply a Unary Operator
to the entries of a matrix A
, creating a new matrix.
Arguments
A
: the sparse matrix.[out]
: the output matrix for result.[unaryop]
: the Unary Operator to use.[accum]
: optional accumulator.[mask]
: optional mask.[desc]
: descriptor forout
,mask
andA
.
Examples
julia> A = from_matrix([-1 2; -3 -4]);
julia> apply(A, unaryop = Unaryop.ABS)
2x2 GBMatrix{Int64} with 4 stored entries:
[1, 1] = 1
[1, 2] = 2
[2, 1] = 3
[2, 2] = 4
SuiteSparseGraphBLAS.apply!
— Methodapply!(A::GBMatrix; kwargs...)
Apply a Unary Operator
to the entries of a matrix A
.
Arguments
A
: the sparse matrix.[unaryop]
: the Unary Operator to use.[accum]
: optional accumulator.[mask]
: optional mask.[desc]
: descriptor for maskand
A`.
Examples
julia> A = from_matrix([-1 2; -3 -4]);
julia> apply!(A, unaryop = Unaryop.ABS);
julia> A
2x2 GBMatrix{Int64} with 4 stored entries:
[1, 1] = 1
[1, 2] = 2
[2, 1] = 3
[2, 2] = 4
SuiteSparseGraphBLAS.select
— Methodselect(A::GBMatrix, op::SelectOperator; kwargs...)
Apply a Select Operator
to the entries of a matrix A
.
Arguments
A
: the sparse matrix.op
: theSelect Operator
to use.[out]
: the output matrix for result.[thunk]
: optional input for theSelect Operator
.[accum]
: optional accumulator.[mask]
: optional mask.[desc]
: descriptor forout
,mask
andA
.
Examples
julia> A = from_matrix([1 2; 3 4]);
# TODO: insert example
SuiteSparseGraphBLAS.reduce_vector
— Functionreduce_vector(A::GBMatrix; kwargs...)
Reduce a matrix A
to a column vector using an operator. Normally the operator is a Binary Operator
, in which all the three domains must be the same. It can be used a Monoid
as an operator. In both cases the reduction operator must be commutative and associative.
Arguments
A
: the sparse matrix.[out]
: the output matrix for result.[operator]
: reduce operator.[accum]
: optional accumulator.[mask]
: optional mask.[desc]
: descriptor forout
,mask
andA
.
Examples
julia> A = from_matrix([1 2; 3 4]);
julia> reduce_vector(A, operator = Binaryop.PLUS)
2-element GBVector{Int64} with 2 stored entries:
[1] = 3
[2] = 7
SuiteSparseGraphBLAS.reduce_scalar
— Functionreduce_scalar(A::GBMatrix{T}; kwargs...) -> T
Reduce a matrix A
to a scalar, using the given Monoid
.
Arguments
A
: the sparse matrix to reduce.[monoid]
: monoid to do the reduction.[accum]
: optional accumulator.[desc]
: descriptor forA
.
Examples
julia> A = from_matrix([1 2; 3 4]);
julia> reduce_scalar(A, monoid = Monoids.PLUS)
10
Base.transpose
— Functiontranspose(A::GBMatrix; kwargs...)
Transpose a matrix A
.
Arguments
A
: the sparse matrix to transpose.[out]
: the output matrix for result.[mask]
: optional mask.[accum]
: optional accumulator.[desc]
: descriptor forout
,mask
andA
.
Examples
julia> A = from_matrix([1 2 3; 4 5 6]);
julia> transpose(A)
3x2 GBMatrix{Int64} with 6 stored entries:
[1, 1] = 1
[1, 2] = 4
[2, 1] = 2
[2, 2] = 5
[3, 1] = 3
[3, 2] = 6
Base.kron
— Functionkron(A::GBMatrix, B::GBMatrix; kwargs...)
Compute the Kronecker product, using the given Binary Operator
.
Arguments
A
: the first matrix.B
: the second matrix.[out]
: the output matrix for result.[binaryop]
: theBinary Operator
to use.[mask]
: optional mask.[accum]
: optional accumulator.[desc]
: descriptor forout
,mask
andA
.
Examples
julia> A = from_matrix[1 2; 3 4]);
julia> B = copy(A)
julia> Matrix(kron(A, B, binaryop = Binaryop.TIMES))
4×4 Array{Int64,2}:
1 2 2 4
3 4 6 8
3 6 4 8
9 12 12 16