LibraryLink Utilities  3.0.1
Modern C++ wrapper over LibraryLink and WSTP
SparseArray.hpp
Go to the documentation of this file.
1 
5 #ifndef LLU_CONTAINERS_GENERIC_SPARSEARRAY_HPP
6 #define LLU_CONTAINERS_GENERIC_SPARSEARRAY_HPP
7 
10 
11 namespace LLU {
12 
13  template<>
14  class MContainer<MArgumentType::SparseArray>;
15 
17  using GenericSparseArray = MContainer<MArgumentType::SparseArray>;
18 
22  template<>
23  class MContainer<MArgumentType::SparseArray> : public MContainerBase<MArgumentType::SparseArray> {
24  public:
27 
31  MContainer() = default;
32 
41  MContainer(const GenericTensor& positions, const GenericTensor& values, const GenericTensor& dimensions, const GenericTensor& implicitValue);
42 
49  MContainer(const GenericTensor& data, const GenericTensor& implicitValue);
50 
57  MContainer(const GenericSparseArray& s, const GenericTensor& implicitValue);
58 
64  MContainer clone() const {
65  return MContainer {cloneContainer(), Ownership::Library};
66  }
67 
73  GenericTensor getImplicitValueAsTensor() const;
74 
81  void setImplicitValueFromTensor(const GenericTensor& implicitValue);
82 
88  mint getRank() const {
89  return LibraryData::SparseArrayAPI()->MSparseArray_getRank(this->getContainer());
90  }
91 
97  mint const* getDimensions() const {
98  return LibraryData::SparseArrayAPI()->MSparseArray_getDimensions(this->getContainer());
99  }
100 
106  GenericTensor getExplicitValues() const;
107 
114  GenericTensor getRowPointers() const;
115 
122  GenericTensor getColumnIndices() const;
123 
130  [[nodiscard]] GenericTensor getExplicitPositions() const;
131 
137  [[nodiscard]] GenericTensor toGenericTensor() const;
138 
142  void resparsify();
143 
148  mint type() const;
149 
150  private:
151 
156  Container cloneImpl() const override;
157 
162  mint shareCountImpl() const noexcept override {
163  return LibraryData::SparseArrayAPI()->MSparseArray_shareCount(this->getContainer());
164  }
165 
167  void passImpl(MArgument& res) const noexcept override {
168  MArgument_setMSparseArray(res, this->getContainer());
169  }
170  };
171 
172 } // namespace LLU
173 
174 #endif // LLU_CONTAINERS_GENERIC_SPARSEARRAY_HPP
LLU::MContainerBase
Template of the base class for all generic containers.
Definition: Base.hpp:35
LLU
Main namespace of LibraryLink Utilities.
Definition: Queue.h:13
LLU::MContainer
MContainer is an abstract class template for generic containers. Only specializations shall be used.
Definition: Base.hpp:245
LLU::MContainer< MArgumentType::SparseArray >
MContainer specialization for MSparseArray.
Definition: SparseArray.hpp:23
LLU::LibraryData::SparseArrayAPI
static const st_WolframSparseLibrary_Functions * SparseArrayAPI()
Get a pointer to structure with function pointers to MSparseArray API.
Definition: LibraryData.cpp:37
LLU::Argument::Typed::SparseArray
MContainer< MArgumentType::SparseArray > SparseArray
SparseArray stands for a GenericSparseArray - type agnostic wrapper over MSparseArray.
Definition: TypedMArgument.h:50
LLU::MContainer< MArgumentType::SparseArray >::getRank
mint getRank() const
Get the rank (number of dimensions) of this sparse array.
Definition: SparseArray.hpp:88
LLU::MContainer< MArgumentType::SparseArray >::MContainer
MContainer()=default
Default constructor, the MContainer does not manage any instance of MSparseArray.
Tensor.hpp
GenericTensor definition and implementation.
LLU::Ownership::Library
@ Library
The library (LLU) is responsible for managing the container's memory. Used for Manual passing and con...
Base.hpp
Definitions of MContainerBase and MContainer class templates.
LLU::MArgumentType
MArgumentType
Strongly type enum with possible types of data stored in MArgument.
Definition: MArgument.h:22
LLU::MContainer< MArgumentType::Tensor >
MContainer specialization for MTensor.
Definition: Generic/Tensor.hpp:24
LLU::MContainer< MArgumentType::SparseArray >::clone
MContainer clone() const
Clone this MContainer, performs a deep copy of the underlying MSparseArray.
Definition: SparseArray.hpp:64
LLU::MContainer< MArgumentType::SparseArray >::getDimensions
mint const * getDimensions() const
Get dimensions of this sparse array.
Definition: SparseArray.hpp:97