Operations
GraphBLAS operations cover most of the typical linear algebra operations on arrays in Julia.
Correspondence of GraphBLAS C functions and Julia functions
| GraphBLAS | Operation | Julia |
|---|---|---|
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.
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...)::GBArrayOrTransposeMultiply 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 anAbstractSemiringfound in theSemiringssubmodule.
Keywords
mask::Union{Nothing, GBArray} = nothing: optional mask which determines the output pattern.accum::Union{Nothing, Function} = nothing: optional binary accumulator operation such thatC[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 whoseeltypeis determined byAandBor the semiring if a type specific semiring is provided.
SuiteSparseGraphBLAS.emul — Functionemul(A::GBArrayOrTranspose, B::GBArrayOrTranspose, op = *; kwargs...)::GBMatrixApply 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 thatC[i,j] = op(A[i,j], B[i,j])for alli,jpresent in bothAandB.
Keywords
mask::Union{Nothing, GBVecOrMat} = nothing: optional mask.accum::Union{Nothing} = nothing: binary accumulator operation whereC[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: OutputGBVectororGBMatrixwhose eltype is determined by theeltypeofAandBor the binary operation if a type specific operation is provided.
SuiteSparseGraphBLAS.emul! — Functionemul!(C::GBArrayOrTranspose, A::GBArrayOrTranspose, B::GBArrayOrTranspose, op = *; kwargs...)::GBArrayOrTransposeApply 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 thatC[i,j] = op(A[i,j], B[i,j])for alli,jpresent in bothAandB.
Keywords
mask::Union{Nothing, GBVecOrMat} = nothing: optional mask.accum::Union{Nothing, Function} = nothing: binary accumulator operation such thatC[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
SuiteSparseGraphBLAS.eadd — Functioneadd(A::GBArrayOrTranspose, B::GBArrayOrTranspose, op = +; kwargs...)::GBVecOrMatApply 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 thatC[i,j] = op(A[i,j], B[i,j])for alli,jpresent in eitherAandB.
Keywords
mask::Union{Nothing, GBVecOrMat} = nothing: optional mask.accum::Union{Nothing, Function} = nothing: binary accumulator operation such thatC[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
SuiteSparseGraphBLAS.eadd! — Functioneadd!(C::GBVecOrMat, A::GBArrayOrTranspose, B::GBArrayOrTranspose, op = +; kwargs...)::GBVecOrMatApply 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 thatC[i,j] = op(A[i,j], B[i,j])for alli,jpresent in eitherAandB.
Keywords
mask::Union{Nothing, GBVecOrMat} = nothing: optional mask.accum::Union{Nothing, Function} = nothing: binary accumulator operation such thatC[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
SuiteSparseGraphBLAS.eunion — Functioneunion(C::GBVecOrMat, A::GBArrayOrTranspose{T}, α::T B::GBArrayOrTranspose, β::T, op = +; kwargs...)::GBVecOrMatApply 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 forAandBrespectively.op::Union{Function, Monoid} = +: the binary operation which is applied such thatC[i,j] = op(A[i,j], B[i,j])for alli,jpresent in eitherAandB.
Keywords
mask::Union{Nothing, GBVecOrMat} = nothing: optional mask.accum::Union{Nothing, Function} = nothing: binary accumulator operation such thatC[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
SuiteSparseGraphBLAS.eunion! — Functioneunion!(C::GBVecOrMat, A::GBArrayOrTranspose{T}, α::T B::GBArrayOrTranspose, β::T, op = +; kwargs...)::GBVecOrMatApply 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 forAandBrespectively.op::Union{Function, Monoid} = +: the binary operation which is applied such thatC[i,j] = op(A[i,j], B[i,j])for alli,jpresent in eitherAandB.
Keywords
mask::Union{Nothing, GBVecOrMat} = nothing: optional mask.accum::Union{Nothing, Function} = nothing: binary accumulator operation such thatC[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
SuiteSparseGraphBLAS.extract — Functionextract(A::GBMatrixOrTranspose, I, J; kwargs...)::GBMatrix
extract(A::GBVector, I; kwargs...)::GBVectorExtract a submatrix or subvector from A
Arguments
A::GBArray: the array being indexed.IandJ: A colon, scalar, vector, or range indexing A.
Keywords
mask::Union{Nothing, GBArray} = nothing: mask wheresize(M) == (max(I), max(J)).accum::Union{Nothing} = nothing: binary accumulator operation whereC[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 submatrixA[I, J].
Throws
GrB_DIMENSION_MISMATCH: If(max(I), max(J)) != size(mask).
SuiteSparseGraphBLAS.extract! — Functionextract!(C::GBMatrix, A::GBMatrixOrTranspose, I, J; kwargs...)::GBMatrix
extract!(C::GBVector, A::GBVector, I; kwargs...)::GBVectorExtract a submatrix or subvector from A into C.
Arguments
C::Union{GBVector, GBMatrix}: the submatrix or subvector extracted fromA.A::GBArrayIandJ: A colon, scalar, vector, or range indexing A.
Keywords
mask::Union{Nothing, GBArray} = nothing: mask wheresize(M) == (max(I), max(J)).accum::Union{Nothing} = nothing: binary accumulator operation whereC[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
GBMatrixorGBVector: the modified arrayC, now containing the matrixA[I, J]orA[I]for a vector.
Throws
GrB_DIMENSION_MISMATCH: Ifsize(C) != (max(I), max(J))orsize(C) != size(mask).
SuiteSparseGraphBLAS.subassign! — Functionsubassign!(C::GBMatrix, A::GBMatrix, I, J; kwargs...)::GBMatrixAssign 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 whereC[I,J] = A.A::GBMatrix: the matrix being assigned to a submatrix ofC.IandJ: A colon, scalar, vector, or range indexing C.
Keywords
mask::Union{Nothing, GBMatrix} = nothing: mask wheresize(M) == size(A).accum::Union{Nothing, Function} = nothing: binary accumulator operation whereC[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: Ifsize(A) != (max(I), max(J))orsize(A) != size(mask).
subassign(w::GBVector, u::GBVector, I; kwargs...)::GBVectorAssign a subvector of w to u. Return u. Equivalent to the matrix definition.
SuiteSparseGraphBLAS.assign! — Functionassign!(C::GBMatrix, A::GBMatrix, I, J; kwargs...)::GBMatrixAssign 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 whereC[I,J] = A.A::GBMatrix: the matrix being assigned to a submatrix ofC.IandJ: A colon, scalar, vector, or range indexing C.
Keywords
mask::Union{Nothing, GBMatrix} = nothing: mask wheresize(M) == size(C).accum::Union{Nothing, Function} = nothing: binary accumulator operation whereC[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: Ifsize(A) != (max(I), max(J))orsize(C) != size(mask).
assign(w::GBVector, u::GBVector, I; kwargs...)::GBVectorAssign a subvector of w to u. Return u. Equivalent to the matrix definition.
SuiteSparseGraphBLAS.apply — Functionapply[!](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...)::AbstractGBArrayTransform 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::GBArrayOrTransposex: Position dependent argument to binary operators.thunk: Extra data forIndexOps.
Keywords
mask::Union{Nothing, GBVecOrMat} = nothing: optional mask.accum::Union{Nothing, Function} = nothing: binary accumulator operation whereC[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
SuiteSparseGraphBLAS.apply! — FunctionNo documentation found.
Binding SuiteSparseGraphBLAS.apply does not exist.
SuiteSparseGraphBLAS.select — Functionselect(op::Function, A::GBArrayOrTranspose; kwargs...)::GBArrayOrTranspose
select(op::Function, A::GBArrayOrTranspose, thunk; kwargs...)::GBArrayOrTransposeReturn 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::GBArrayOrTransposethunk::Union{GBScalar, nothing, valid_union}: Optional value used to evaluateop.
Keywords
mask::Union{Nothing, GBMatrix} = nothing: optional mask which determines the output pattern.accum::Union{Nothing} = nothing: optional binary accumulator operation whereC[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 whoseeltypeis determined byAandop.
SuiteSparseGraphBLAS.select! — FunctionIn place version of select.
Base.reduce — Functionreduce(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:GBVectoror optionally transposedGBMatrix.dims = :: Optional dimensions for GBMatrix, may be1,2, or:.
Keywords
typeout: Optional output type specification. Defaults toeltype(A).init: Optional initial value.mask::Union{Nothing, GBMatrix} = nothing: optional mask.accum::Union{Nothing} = nothing: binary accumulator operation whereC[i,j] = accum(C[i,j], T[i,j])where T is the result of this function before accum is applied.desc = nothing
SuiteSparseGraphBLAS.gbtranspose — Functiongbtranspose(A::GBMatrix; kwargs...)::GBMatrixEagerly evaluated matrix transpose which returns the transposed matrix.
Keywords
mask::Union{Nothing, GBMatrix} = nothing: optional mask.accum::Union{Nothing} = nothing: binary accumulator operation whereC[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.
SuiteSparseGraphBLAS.gbtranspose! — Functiongbtranspose!(C::GBMatrix, A::GBMatrix; kwargs...)::NothingEagerly 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 whereC[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
Base.kron — Functionkron(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 whereC[i,j] = accum(C[i,j], T[i,j])where T is the result of this function before accum is applied.desc = nothing
Base.kron! — Functionkron!(A::GBMatrix, B::GBMatrix, op = BinaryOps.TIMES; kwargs...)::GBMatrixIn-place version of kron.
SuiteSparseGraphBLAS.mask — Functionmask(A::GBArrayOrTranspose, mask::GBVecOrMat)Apply a mask to matrix A.
SuiteSparseGraphBLAS.mask! — Functionmask!(C::GBArrayOrTranspose, A::GBArrayOrTranspose, mask::GBVecOrMat)Apply a mask to matrix A, storing the results in C.
Order of Operations
A GraphBLAS operation semantically occurs in the following order:
- Calculate
T = <operation>(args...) - Elementwise accumulate
Z[i,j] = accum(C[i,j], T[i,j]) - 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].