Sparse Tensors

Work-in-progress

This page of the docs is still a work-in-progress. Check back later!

GCPDecompositions.SparseArrayCOOs.SparseArrayCOOType
SparseArrayCOO{Tv,Ti<:Integer,N} <: AbstractArray{Tv,N}

N-dimensional sparse array stored in the COOrdinate format. Elements are stored as a vector of indices (using type Ti) and a vector of values (of type Tv). Values for duplicate indices are summed.

Fields:

  • dims::Dims{N} : tuple of dimensions
  • inds::Vector{NTuple{N,Ti}} : vector of indices
  • vals::Vector{Tv} : vector of values
source
GCPDecompositions.SparseArrayCOOs.SparseArrayCOOMethod
SparseArrayCOO([Ti=Int], A::AbstractArray)

Convert an AbstractArray A into a SparseArrayCOO with indices using type Ti.

Examples

julia> A = SparseArrayCOO(Int8, Float16[1.1 0.0 0.0; 2.1 0.0 2.3])
2×3 SparseArrayCOO{Float16, Int8, 2} with 3 stored entries:
  [1, 1]  =  1.1
  [2, 1]  =  2.1
  [2, 3]  =  2.3

julia> B = SparseArrayCOO(Int16, Float16[1.1 0.0 0.0; 2.1 0.0 2.3])
2×3 SparseArrayCOO{Float16, Int16, 2} with 3 stored entries:
  [1, 1]  =  1.1
  [2, 1]  =  2.1
  [2, 3]  =  2.3

julia> C = SparseArrayCOO(Float16[1.1 0.0 0.0; 2.1 0.0 2.3])
2×3 SparseArrayCOO{Float16, Int64, 2} with 3 stored entries:
  [1, 1]  =  1.1
  [2, 1]  =  2.1
  [2, 3]  =  2.3
source
GCPDecompositions.SparseArrayCOOs.SparseArrayCOOMethod
SparseArrayCOO{Tv,Ti<:Integer}(undef, dims)
SparseArrayCOO{Tv,Ti<:Integer,N}(undef, dims)

Construct an uninitialized N-dimensional SparseArrayCOO with indices using type Ti and elements of type Tv. Here uninitialized means it has no stored entries.

Here undef is the UndefInitializer. If N is supplied, then it must match the length of dims.

Examples

julia> A = SparseArrayCOO{Float64, Int8, 3}(undef, (2, 3, 4)) # N given explicitly
2×3×4 SparseArrayCOO{Float64, Int8, 3} with 0 stored entries

julia> B = SparseArrayCOO{Float64, Int8}(undef, (4,)) # N determined by the input
4-element SparseArrayCOO{Float64, Int8, 1} with 0 stored entries

julia> similar(B, 2, 4, 1) # use typeof(B), and the given size
2×4×1 SparseArrayCOO{Float64, Int8, 3} with 0 stored entries
source
GCPDecompositions.SparseArrayCOOs.check_TiMethod
check_Ti(dims, Ti)

Check that the dims tuple and Ti index type are valid:

  • dims are nonnegative and fit in Ti (0 ≤ dims[k] ≤ typemax(Ti))
  • corresponding length fits in Int (prod(dims) ≤ typemax(Int))

If not, throw an ArgumentError.

source