Tensor¶
Defined in coo.hpp
-
template<class Label = uint32_t, class Ordinal = Label, class Storage = Label*, bool weighted = true, class Weight = float, class WeightStorage = Weight*>
class pigo::Tensor¶ Holds coordinate-addressed tensors.
A Tensor is designed to read sparse tensor files and expose the resulting file as a coordinate list with weights.
- tparam Label
the label data type. This type needs to be able to support the largest coordinate value read inside of the Tensor.
- tparam Ordinal
the ordinal data type. This type needs to support large enough values to hold the number of entries or rows in the Tensor. It defaults to the same type as the label type.
- tparam Storage
the storage type of the Tensor. This can either be vector (std::vector<Label>), a pointer (Label*), or a shared_ptr (std::shared_ptr<Label>).
- tparam weighted
if true, support and use weights
- tparam Weight
the weight data type.
- tparam WeightStorage
the storage type for the weights. This can be a raw pointer (Weight*), a std::vector (std::vector<Weight>), or a std::shared_ptr<Weight>.
Public Functions
-
Tensor(std::string fn)¶
Initialize a Tensor from a file.
The file type will attempt to be determined automatically.
- Parameters
fn – the filename to open
-
Tensor(std::string fn, FileType ft)¶
Initialize a Tensor from a file with a specific type.
- Parameters
fn – the filename to open
ft – the FileType to use
-
Tensor(File &f, FileType ft)¶
Initialize a Tensor from an open File with a specific type.
- Parameters
f – the File to use
ft – the FileType to use
-
inline Storage &c()¶
Retrieve the coordinate array.
- Returns
the coordinate array in the format Storage
-
inline WeightStorage &w()¶
Retrieve the weight array.
- Returns
the weight array in the format WeightStorage
-
inline Ordinal m() const¶
Retrieves the number of entries in the Tensor.
- Returns
the count of entries
-
inline void free()¶
Free consumed memory.
Public Static Attributes
-
static constexpr const char *tensor_file_header = "PIGO-Tensor-v1"¶
The output file header for reading/writing