Operations

GraphBLAS operations cover most of the typical linear algebra operations on arrays in Julia.

Correspondence of GraphBLAS C functions and Julia functions

GraphBLASOperationJulia
mxm, mxv, vxm$\bf C \langle M \rangle = C \odot AB$mul! or *
eWiseMult$\bf C \langle M \rangle = C \odot (A \otimes B)$emul[!] or . broadcasting
eWiseAdd$\bf C \langle M \rangle = C \odot (A \oplus B)$eadd[!]
extract$\bf C \langle M \rangle = C \odot A(I,J)$extract[!], getindex
subassign$\bf C (I,J) \langle M \rangle = C(I,J) \odot A$subassign[!] or setindex!
assign$\bf C \langle M \rangle (I,J) = C(I,J) \odot A$assign[!]
apply${\bf C \langle M \rangle = C \odot} f{\bf (A)}$apply[!], map[!] or . broadcasting
${\bf C \langle M \rangle = C \odot} f({\bf A},y)$
${\bf C \langle M \rangle = C \odot} f(x,{\bf A})$
select${\bf C \langle M \rangle = C \odot} f({\bf A},k)$select[!]
reduce${\bf w \langle m \rangle = w \odot} [{\oplus}_j {\bf A}(:,j)]$reduce[!]
$s = s \odot [{\oplus}_{ij} {\bf A}(i,j)]$
transpose$\bf C \langle M \rangle = C \odot A^{\sf T}$gbtranspose[!], lazy: transpose, '
kronecker$\bf C \langle M \rangle = C \odot \text{kron}(A, B)$kron[!]

where $\bf M$ is a GBArray mask, $\odot$ is a binary operator for accumulating into $\bf C$, and $\otimes$ and $\oplus$ are binary operators or monoids.

assign vs subassign

subassign is equivalent to assign except that the mask in subassign has the dimensions of $\bf C(I,J)$ vs the dimensions of $C$ for assign. Elements outside of the mask will also never be modified by subassign. See the GraphBLAS User Guide for more details.

Common arguments

The operations typically accept one of the following types in the op argument.

op - Function:

This argument determines $\oplus$, $\otimes$, or $f$ in the table above as well as the semiring used in mul. See Operators for more information.

desc - Descriptor:

The descriptor argument allows the user to modify the operation in some fashion. A new Descriptor can be created with default settings as: d = Descriptor(). The most common options are:

  • desc.[transpose_input1 | transpose_input2] == [true | false]:

Typically you should use Julia's built-in transpose functionality.

  • desc.complement_mask == [true | false]:

If complement_mask is set the presence/truth value of the mask is complemented. See SuiteSparseGraphBLAS.Complement for a wrapper that sets this flag.

  • desc.structural_mask == [true | false]:

If structural_mask is set the presence of a value in the mask determines the presence of values in the output, rather than the actual value of the mask. See SuiteSparseGraphBLAS.Structural for a wrapper that sets this flag.

  • desc.replace_output == [true | false]:

If this option is set the operation will replace all values in the output matrix after the accumulation step. If an index is found in the output matrix, but not in the results of the operation it will be set to nothing.

accum - Function:

The accum keyword argument provides a binary operation to accumulate results into the result array. The accumulation step is performed before masking.

mask - GBArray:

The mask keyword argument determines whether each index from the result of an operation appears in the output. The mask may be structural, where the presence of a value indicates the mask is true, or valued where the value of the mask indicates its truth value. mask = SuiteSparseGraphBLAS.Structural(A) will use a structural mask.

The mask may also be complemented. mask = SuiteSparseGraphBLAS.Complement(A) or mask = ~A will complement a mask. These two options may be combined, for example mask = ~SuiteSparseGraphBLAS.Structural(A).

Operation Documentation

All non-mutating operations below support a mutating form by adding an output array as the first argument as well as the ! function suffix.

Base.:*Function
*(A::GBArrayOrTranspose, B::GBArrayOrTranspose, op=(+,*); kwargs...)::GBArrayOrTranspose

Multiply two GBArrays A and B using a semiring, which defaults to the arithmetic semiring +.*.

Either operand may be transposed using ' or transpose(A) provided the dimensions match.

The mutating form, mul!(C, A, B, op; kwargs...) is identical except it stores the result in C::GBVecOrMat.

The operator syntax A * B can be used when the default semiring is desired, and *(max, +)(A, B) can be used otherwise.

Arguments

  • A, B::GBArrayOrTranspose: A GBVector or GBMatrix, possibly transposed.
  • op::Union{Tuple{Function, Function}, AbstractSemiring}: the semiring used for matrix multiplication. May be passed as a tuple of functions, or an AbstractSemiring found in the Semirings submodule.

Keywords

  • mask::Union{Nothing, GBArray} = nothing: optional mask which determines the output pattern.
  • accum::Union{Nothing, Function} = nothing: optional binary accumulator operation such that C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc::Union{Nothing, Descriptor}

Returns

  • GBArray: The output matrix whose eltype is determined by A and B or the semiring if a type specific semiring is provided.
source
SuiteSparseGraphBLAS.emulFunction
emul(A::GBArrayOrTranspose, B::GBArrayOrTranspose, op = *; kwargs...)::GBMatrix

Apply the binary operator op elementwise on the set intersection of A and B. When op = * this is equivalent to A .* B, however any binary operator may be substituted.

The pattern of the result is the set intersection of A and B. For a set union equivalent see eadd.

Arguments

  • A, B::GBArrayOrTranspose: A GBVector or GBMatrix, possibly transposed.
  • op::Union{Function, Monoid} = *: the binary operation which is applied such that C[i,j] = op(A[i,j], B[i,j]) for all i,j present in both A and B.

Keywords

  • mask::Union{Nothing, GBVecOrMat} = nothing: optional mask.
  • accum::Union{Nothing} = nothing: binary accumulator operation where C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc = nothing

Returns

  • GBVecOrMat: Output GBVector or GBMatrix whose eltype is determined by the eltype of A and B or the binary operation if a type specific operation is provided.
source
SuiteSparseGraphBLAS.emul!Function
emul!(C::GBArrayOrTranspose, A::GBArrayOrTranspose, B::GBArrayOrTranspose, op = *; kwargs...)::GBArrayOrTranspose

Apply the binary operator op elementwise on the set intersection of A and B. Store or accumulate the result into C. When op = * this is equivalent to A .* B, however any binary operator may be substituted.

The pattern of the result is the set intersection of A and B. For a set union equivalent see eadd!.

Arguments

  • C::GBArrayOrTranspose: the output vector or matrix.
  • A, B::GBArrayOrTranspose: A GBVector or GBMatrix, possibly transposed.
  • op::Union{Function, Monoid} = *: the binary operation which is applied such that C[i,j] = op(A[i,j], B[i,j]) for all i,j present in both A and B.

Keywords

  • mask::Union{Nothing, GBVecOrMat} = nothing: optional mask.
  • accum::Union{Nothing, Function} = nothing: binary accumulator operation such that C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc::Union{Nothing, Descriptor} = nothing
source
SuiteSparseGraphBLAS.eaddFunction
eadd(A::GBArrayOrTranspose, B::GBArrayOrTranspose, op = +; kwargs...)::GBVecOrMat

Apply the binary operator op elementwise on the set union of A and B. When op = + this is equivalent to A .+ B, however any binary operation may be substituted.

Note that the behavior of A[i,j] op B[i,j] may be unintuitive when one operand is an implicit zero. The explicit operand passes through the function. So A[i,j] op B[i,j] where B[i,j] is an implicit zero returns A[i,j] not A[i,j] op zero(T).

For a set intersection equivalent see emul.

Arguments

  • A, B::GBArrayOrTranspose: A GBVector or GBMatrix, possibly transposed.
  • op::Union{Function, Monoid} = +: the binary operation which is applied such that C[i,j] = op(A[i,j], B[i,j]) for all i,j present in either A and B.

Keywords

  • mask::Union{Nothing, GBVecOrMat} = nothing: optional mask.
  • accum::Union{Nothing, Function} = nothing: binary accumulator operation such that C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc::Union{Nothing, Descriptor} = nothing
source
SuiteSparseGraphBLAS.eadd!Function
eadd!(C::GBVecOrMat, A::GBArrayOrTranspose, B::GBArrayOrTranspose, op = +; kwargs...)::GBVecOrMat

Apply the binary operator op elementwise on the set union of A and B. Store or accumulate the result into C. When op = + this is equivalent to A .+ B, however any binary operation may be substituted.

Note that the behavior of A[i,j] op B[i,j] may be unintuitive when one operand is an implicit zero. The explicit operand passes through the function. So A[i,j] op B[i,j] where B[i,j] is an implicit zero returns A[i,j] not A[i,j] op zero(T).

For a set intersection equivalent see emul!.

Arguments

  • C::GBArrayOrTranspose: the output vector or matrix.
  • A, B::GBArrayOrTranspose: A GBVector or GBMatrix, possibly transposed.
  • op::Union{Function, Monoid} = +: the binary operation which is applied such that C[i,j] = op(A[i,j], B[i,j]) for all i,j present in either A and B.

Keywords

  • mask::Union{Nothing, GBVecOrMat} = nothing: optional mask.
  • accum::Union{Nothing, Function} = nothing: binary accumulator operation such that C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc::Union{Nothing, Descriptor} = nothing
source
SuiteSparseGraphBLAS.eunionFunction
eunion(C::GBVecOrMat, A::GBArrayOrTranspose{T}, α::T B::GBArrayOrTranspose, β::T, op = +; kwargs...)::GBVecOrMat

Apply the binary operator op elementwise on the set union of A and B. When op = + this is equivalent to A .+ B, however any binary operation may be substituted.

Unlike eadd! where an argument missing in A causes the B element to "pass-through", eunion! utilizes the α and β arguments for the missing operand elements.

Arguments

  • A, B::GBArrayOrTranspose: A GBVector or GBMatrix, possibly transposed.
  • α, β: The fill-in value for A and B respectively.
  • op::Union{Function, Monoid} = +: the binary operation which is applied such that C[i,j] = op(A[i,j], B[i,j]) for all i,j present in either A and B.

Keywords

  • mask::Union{Nothing, GBVecOrMat} = nothing: optional mask.
  • accum::Union{Nothing, Function} = nothing: binary accumulator operation such that C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc::Union{Nothing, Descriptor} = nothing
source
SuiteSparseGraphBLAS.eunion!Function
eunion!(C::GBVecOrMat, A::GBArrayOrTranspose{T}, α::T B::GBArrayOrTranspose, β::T, op = +; kwargs...)::GBVecOrMat

Apply the binary operator op elementwise on the set union of A and B. Store or accumulate the result into C. When op = + this is equivalent to A .+ B, however any binary operation may be substituted.

Unlike eadd! where an argument missing in A causes the B element to "pass-through", eunion! utilizes the α and β arguments for the missing operand elements.

Arguments

  • C::GBArrayOrTranspose: the output vector or matrix.
  • A, B::GBArrayOrTranspose: A GBVector or GBMatrix, possibly transposed.
  • α, β: The fill-in value for A and B respectively.
  • op::Union{Function, Monoid} = +: the binary operation which is applied such that C[i,j] = op(A[i,j], B[i,j]) for all i,j present in either A and B.

Keywords

  • mask::Union{Nothing, GBVecOrMat} = nothing: optional mask.
  • accum::Union{Nothing, Function} = nothing: binary accumulator operation such that C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc::Union{Nothing, Descriptor} = nothing
source
SuiteSparseGraphBLAS.extractFunction
extract(A::GBMatrixOrTranspose, I, J; kwargs...)::GBMatrix
extract(A::GBVector, I; kwargs...)::GBVector

Extract a submatrix or subvector from A

Arguments

  • A::GBArray: the array being indexed.
  • I and J: A colon, scalar, vector, or range indexing A.

Keywords

  • mask::Union{Nothing, GBArray} = nothing: mask where size(M) == (max(I), max(J)).
  • accum::Union{Nothing} = nothing: binary accumulator operation where C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc::Descriptor = nothing

Returns

  • GBMatrix: the submatrix A[I, J].

Throws

  • GrB_DIMENSION_MISMATCH: If (max(I), max(J)) != size(mask).
source
SuiteSparseGraphBLAS.extract!Function
extract!(C::GBMatrix, A::GBMatrixOrTranspose, I, J; kwargs...)::GBMatrix
extract!(C::GBVector, A::GBVector, I; kwargs...)::GBVector

Extract a submatrix or subvector from A into C.

Arguments

  • C::Union{GBVector, GBMatrix}: the submatrix or subvector extracted from A.
  • A::GBArray
  • I and J: A colon, scalar, vector, or range indexing A.

Keywords

  • mask::Union{Nothing, GBArray} = nothing: mask where size(M) == (max(I), max(J)).
  • accum::Union{Nothing} = nothing: binary accumulator operation where C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc::Union{Nothing, Descriptor} = nothing

Returns

  • GBMatrix or GBVector: the modified array C, now containing the matrix A[I, J] or A[I] for a vector.

Throws

  • GrB_DIMENSION_MISMATCH: If size(C) != (max(I), max(J)) or size(C) != size(mask).
source
SuiteSparseGraphBLAS.subassign!Function
subassign!(C::GBMatrix, A::GBMatrix, I, J; kwargs...)::GBMatrix

Assign a submatrix of A to C. Equivalent to assign! except that size(mask) == size(A), whereas size(mask) == size(C) in assign!.

Arguments

  • C::GBMatrix: the matrix being subassigned to where C[I,J] = A.
  • A::GBMatrix: the matrix being assigned to a submatrix of C.
  • I and J: A colon, scalar, vector, or range indexing C.

Keywords

  • mask::Union{Nothing, GBMatrix} = nothing: mask where size(M) == size(A).
  • accum::Union{Nothing, Function} = nothing: binary accumulator operation where C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc::Union{Nothing, Descriptor} = nothing

Returns

  • GBMatrix: The input matrix A.

Throws

  • GrB_DIMENSION_MISMATCH: If size(A) != (max(I), max(J)) or size(A) != size(mask).
source
subassign(w::GBVector, u::GBVector, I; kwargs...)::GBVector

Assign a subvector of w to u. Return u. Equivalent to the matrix definition.

source
SuiteSparseGraphBLAS.assign!Function
assign!(C::GBMatrix, A::GBMatrix, I, J; kwargs...)::GBMatrix

Assign a submatrix of A to C. Equivalent to subassign! except that size(mask) == size(C), whereas size(mask) == size(A) insubassign!`.

Arguments

  • C::GBMatrix: the matrix being subassigned to where C[I,J] = A.
  • A::GBMatrix: the matrix being assigned to a submatrix of C.
  • I and J: A colon, scalar, vector, or range indexing C.

Keywords

  • mask::Union{Nothing, GBMatrix} = nothing: mask where size(M) == size(C).
  • accum::Union{Nothing, Function} = nothing: binary accumulator operation where C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc::Union{Nothing, Descriptor} = nothing

Returns

  • GBMatrix: The input matrix A.

Throws

  • GrB_DIMENSION_MISMATCH: If size(A) != (max(I), max(J)) or size(C) != size(mask).
source
assign(w::GBVector, u::GBVector, I; kwargs...)::GBVector

Assign a subvector of w to u. Return u. Equivalent to the matrix definition.

source
SuiteSparseGraphBLAS.applyFunction
apply[!](op::Function, [C::GBArray], A::GBArrayOrTranspose; kwargs...)::AbstractGBArray
apply[!](op::Function, [C::GBArray], A::GBArrayOrTranspose, x; kwargs...)::AbstractGBArray
apply[!](op::Function, [C::GBArray], x, A::GBArrayOrTranspose; kwargs...)::AbstractGBArray
apply[!](op::IndexOp{<:Function}, [C::GBArray], A::GBArrayOrTranspose{T}, thunk = defaultthunk(op, T); kwargs...)::AbstractGBArray

Transform a GBArray by applying op to each element. Equivalent to Base.map except for the additional x argument for mapping with a scalar.

Unary operators apply elementwise in the usual fashion. IndexOps, and operators that set isindexop(::F) = true operate elementwise with additional arguments for the indices and an additional data argument thunk. Binary operators require the additional argument x which is substituted as the first or second operand of op depending on its position in the apply signature.

Arguments

  • `op::Union{Function, IndexOp}
  • A::GBArrayOrTranspose
  • x: Position dependent argument to binary operators.
  • thunk: Extra data for IndexOps.

Keywords

  • mask::Union{Nothing, GBVecOrMat} = nothing: optional mask.
  • accum::Union{Nothing, Function} = nothing: binary accumulator operation where C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc::Union{Nothing, Descriptor} = nothing
source
SuiteSparseGraphBLAS.selectFunction
select(op::Function, A::GBArrayOrTranspose; kwargs...)::GBArrayOrTranspose
select(op::Function, A::GBArrayOrTranspose, thunk; kwargs...)::GBArrayOrTranspose

Return a GBArray whose elements satisfy the predicate defined by op. Some SelectOps or functions may require an additional argument thunk, for use in comparison operations such as C[i,j] = A[i,j] >= thunk ? A[i,j] : nothing, which is performed by select(>, A, thunk).

Arguments

  • op::Function: A select operator from the SelectOps submodule.
  • A::GBArrayOrTranspose
  • thunk::Union{GBScalar, nothing, valid_union}: Optional value used to evaluate op.

Keywords

  • mask::Union{Nothing, GBMatrix} = nothing: optional mask which determines the output pattern.
  • accum::Union{Nothing} = nothing: optional binary accumulator operation where C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc = nothing

Returns

  • GBArray: The output matrix whose eltype is determined by A and op.
source
Base.reduceFunction
reduce(op::Union{Function, AbstractMonoid}, A::GBMatrix, dims=:; kwargs...)
reduce(op::Union{Function, AbstractMonoid}, v::GBVector; kwargs...)

Reduce A along dimensions of A with monoid op.

Arguments

  • op: the reducer. This must map to an AbstractMonoid, not a binary op.
  • A::GBArrayOrTranspose: GBVector or optionally transposed GBMatrix.
  • dims = :: Optional dimensions for GBMatrix, may be 1, 2, or :.

Keywords

  • typeout: Optional output type specification. Defaults to eltype(A).
  • init: Optional initial value.
  • mask::Union{Nothing, GBMatrix} = nothing: optional mask.
  • accum::Union{Nothing} = nothing: binary accumulator operation where C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc = nothing
source
SuiteSparseGraphBLAS.gbtransposeFunction
gbtranspose(A::GBMatrix; kwargs...)::GBMatrix

Eagerly evaluated matrix transpose which returns the transposed matrix.

Keywords

  • mask::Union{Nothing, GBMatrix} = nothing: optional mask.
  • accum::Union{Nothing} = nothing: binary accumulator operation where C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc::Union{Nothing, Descriptor} = nothing

Returns

  • C::GBMatrix: output matrix.
source
SuiteSparseGraphBLAS.gbtranspose!Function
gbtranspose!(C::GBMatrix, A::GBMatrix; kwargs...)::Nothing

Eagerly evaluated matrix transpose, storing the output in C.

Arguments

  • C::GBMatrix: output matrix.
  • A::GBMatrix: input matrix.

Keywords

  • mask::Union{Nothing, GBMatrix} = nothing: optional mask.
  • accum::Union{Nothing} = nothing: binary accumulator operation where C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc::Union{Nothing, Descriptor} = DEFAULTDESC
source
Base.kronFunction

kron(A::GBMatrix, B::GBMatrix, op = BinaryOps.TIMES; kwargs...)::GBMatrix

Kronecker product of two matrices using op as the multiplication operator. Does not support GBVectors at this time.

Arguments

  • A::GBMatrix: optionally transposed.
  • B::GBMatrix: optionally transposed.
  • op::MonoidBinaryOrRig = BinaryOps.TIMES: the binary operation which replaces the arithmetic multiplication operation from the usual kron function.

Keywords

  • mask::Union{Nothing, GBMatrix} = nothing: optional mask.
  • accum::Union{Nothing} = nothing: binary accumulator operation where C[i,j] = accum(C[i,j], T[i,j]) where T is the result of this function before accum is applied.
  • desc = nothing
source
Base.kron!Function
kron!(A::GBMatrix, B::GBMatrix, op = BinaryOps.TIMES; kwargs...)::GBMatrix

In-place version of kron.

source
SuiteSparseGraphBLAS.mask!Function
mask!(C::GBArrayOrTranspose, A::GBArrayOrTranspose, mask::GBVecOrMat)

Apply a mask to matrix A, storing the results in C.

source

Order of Operations

A GraphBLAS operation semantically occurs in the following order:

  1. Calculate T = <operation>(args...)
  2. Elementwise accumulate Z[i,j] = accum(C[i,j], T[i,j])
  3. Optionally masked assignment C[i,j] = mask[i,j] ? Z[i,j] : [nothing | C[i,j]]

If replace_output is set the option in step 3. is nothing, otherwise it is C[i,j].