Main Content

matlab::data::SparseArray<T>

Templated C++ class to access data in MATLAB sparse arrays

Description

Use SparseArray objects to work with sparse MATLAB® arrays. To create a SparseArray, call createSparseArray in the ArrayFactory class.

Class Details

Namespace:

matlab::data

Base class:

matlab::data::Array

Include:

SparseArray.hpp

Template Parameters

T

Type of element referred to, specified as:

  • bool

  • double

  • std::complex<double>

Constructors

Copy Constructors

SparseArray(const SparseArray<T>& rhs)

SparseArray(const Array& rhs)

Description

Creates a shared data copy of a SparseArray object.

Parameters

const SparseArray<T>& rhs

Value to copy.

const Array& rhs

Value specified as Array of ArrayType::SPARSE_LOGICAL, ArrayType::SPARSE_DOUBLE, or ArrayType::SPARSE_COMPLEX_DOUBLE.

Throws

matlab::data::InvalidArrayTypeException

Type of input Array is not sparse.

Copy Assignment Operators

SparseArray& operator=(const SparseArray<T>& rhs)

SparseArray& operator=(const Array& rhs)

Description

Assigns a shared data copy to a SparseArray object.

Parameters

const SparseArray<T>& rhs

Value to copy.

const Array& rhs

Value specified as Array of type ArrayType::SPARSE_LOGICAL, ArrayType::SPARSE_DOUBLE, or ArrayType::SPARSE_COMPLEX_DOUBLE.

Returns

SparseArray&

Updated instance.

Throws

matlab::data::InvalidArrayTypeException

Type of input Array is not sparse.

Move Constructors

SparseArray(SparseArray&& rhs)

SparseArray(Array&& rhs)

Description

Moves contents of a SparseArray object to a new instance.

Parameters

const SparseArray<T>& rhs

Value to move.

const Array& rhs

Value specified as Array of type ArrayType::SPARSE_LOGICAL, ArrayType::SPARSE_DOUBLE, or ArrayType::SPARSE_COMPLEX_DOUBLE.

Throws

matlab::data::InvalidArrayTypeException

Type of input Array is not sparse.

Move Assignment Operators

SparseArray& operator=(SparseArray<T>&& rhs)

SparseArray& operator=(Array&& rhs)

Description

Assigns the input to this SparseArray object.

Parameters

const SparseArray<T>& rhs

Value to move.

const Array& rhs

Value specified as Array of type ArrayType::SPARSE_LOGICAL, ArrayType::SPARSE_DOUBLE, or ArrayType::SPARSE_COMPLEX_DOUBLE.

Returns

SparseArray&

Updated instance.

Throws

matlab::data::InvalidArrayTypeException

Type of input Array is not sparse.

Iterators

Begin Iterators

iterator begin()

const_iterator begin() const

const_iterator cbegin() const

Returns

iterator

Iterator to beginning of array, specified as TypedIterator<T>.

const_iterator

Iterator, specified as TypedIterator<typename std::add_const<T>::type>.

Throws

None

End Iterators

iterator end()

const_iterator end() const

const_iterator cend() const

Returns

iterator

Iterator to end of array, specified as TypedIterator<T>.

const_iterator

Iterator, specified as TypedIterator<typename std::add_const<T>::type>.

Throws

None

Member Functions

getNumberOfNonZeroElements

size_t getNumberOfNonZeroElements() const
Description

Returns the number of nonzero elements in the array.

Returns

size_t

Number of nonzero elements in array.

Throws

None

getIndex

SparseIndex getIndex(const TypedIterator<T>& it)
SparseIndex getIndex(const TypedIterator<T const>& it)
Description

Returns the row-column coordinates of the nonzero entry that the iterator is pointing to.

Parameters

const TypedIterator<T>& it

Iterator pointing to current entry in sparse matrix.

const TypedIterator<T const>& it

Returns

SparseIndex

Row-column coordinates of nonzero entry that iterator points to. SparseIndex is defined as std::pair<size_t, size_t>.

Throws

None

Introduced in R2017b