COO

Defined in coo.hpp

template<class Label = uint32_t, class Ordinal = Label, class Storage = Label*, bool symmetric = false, bool keep_upper_triangle_only = false, bool remove_self_loops = false, bool weighted = false, class Weight = float, class WeightStorage = Weight*>
class pigo::COO

Holds coordinate-addressed matrices or graphs.

A COO is a fundamental object in PIGO. It is able to read a variety of input formats (e.g., matrix market) and exposes the read data as an edge list.

The edge list is stored as multiple arrays, one for the x elements and one for the y elements (e.g., src and dst in graphs.) The storage method is a template parameter.

tparam Label

the label data type. This type needs to be able to support the largest value read inside of the COO. In a graph this is the largest vertex ID.

tparam Ordinal

the ordinal data type. This type needs to support large enough values to hold the number of entries or rows in the COO. It defaults to the same type as the label type.

tparam Storage

the storage type of the COO. This can either be vector (std::vector<Label>), a pointer (Label*), or a shared_ptr (std::shared_ptr<Label>).

tparam symmetric

Ensure that the COO is symmetric, that is ensure that for every coordinate there is a corresponding symmetric coordinate with the same value. If true, this will always be the case. If false, any symmetry will be based on whether the input is.

tparam keep_upper_triangle_only

Only keep values that are in the upper triangle (if the coordinate is (x,y,val), only keep it in the coo if x <= y) If this is used with symmetric, then the COO will first symmetrize and then remove any value out of the upper triangle. If this is used without symmetric, then any edges with (y > x) will not be included in the COO.

tparam remove_self_loops

remove any self loops. If set to true, this will detect and remove any self loops (if the coordinate is (x,y,val) and (x==y), the entry will not be included in the COO.

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

COO(std::string fn)

Initialize a COO from a file.

The file type will attempt to be determined automatically.

Parameters

fn – the filename to open

COO(std::string fn, FileType ft)

Initialize a COO from a file with a specific type.

Parameters
  • fn – the filename to open

  • ft – the FileType to use

COO(File &f, FileType ft)

Initialize a COO from an open File with a specific type.

Parameters
  • f – the File to use

  • ft – the FileType to use

template<class CL, class CO, typename LabelStorage, typename OrdinalStorage, class CW, class CWS>
COO(CSR<CL, CO, LabelStorage, OrdinalStorage, weighted, CW, CWS> &csr)

Initialize from a CSR.

Parameters

csr – the CSR to convert from

inline COO()

Initialize an empty COO.

inline COO(Label n, Label nrows, Label ncols, Ordinal m)

Provide space for copying in existing, out-of-band data.

inline Storage &x()

Retrieve the X coordinate array.

Returns

the X array in the format Storage

inline Storage &y()

Retrieve the Y coordinate array.

Returns

the Y 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 COO.

Returns

the count of entries

inline Label n() const

Retrieves the number of labels the COO contains.

Note: This will include any zero entry-labels. So, the count is the largest seen label+1.

Returns

the number of labels

inline void set_n(Label new_n)

Update the largest label.

inline void set_nrows(Label new_nrows)

Update the number of rows in the matrix.

inline void set_ncols(Label new_ncols)

Update the number of cols in the matrix.

inline Label nrows() const

Retrieves the number of rows in the COO.

Returns

the number of rows

inline Label ncols() const

Retrieves the number of columns in the COO.

Returns

the number of columns

void save(std::string fn)

Saves the COO to a binary PIGO file.

void write(std::string fn)

Write the COO out to an ASCII file.

inline void free()

Utility to free consumed memory.

As an IO library, PIGO generally leaves memory cleanup to downstream applications and does not always deallocate in destructors. In some cases it is helpful for PIGO to cleanup directly and then this can be used.

inline COO(const COO &other)

The copy constructor for creating a new COO.

inline COO &operator=(const COO &other)

The copy assignment operator.

inline COO &transpose()

Transpose the COO, swapping x and y.

Public Static Attributes

static constexpr const char *coo_file_header = "PIGO-COO-v1"

The output file header for reading/writing

type pigo::WCOO
type pigo::WCOOPtr