1#ifndef UTIL_D_RAGGED_MATRIX_H
2#define UTIL_D_RAGGED_MATRIX_H
11#include <util/containers/RaggedMatrix.h>
12#include <util/containers/DArray.h>
23 template <
typename Data>
64 template <
typename Data>
72 template <
typename Data>
76 Memory::deallocate<Data>(data_, capacity_);
79 Memory::deallocate<Data*>(rows_, capacity1_);
82 Memory::deallocate<int>(capacity2_, capacity1_);
89 template <
typename Data>
93 UTIL_THROW(
"Attempt to re-allocate a RaggedMatrix");
96 UTIL_THROW(
"rowSizes.capacity() must be positive");
100 for (
int i = 0; i < rowSizes.
capacity(); ++i) {
102 UTIL_THROW(
"rowSizes must all be nonnegative");
103 capacity_ += rowSizes[i];
107 UTIL_THROW(
"Sum of row sizes must be positive");
111 Memory::allocate<int>(capacity2_, capacity1_);
112 Memory::allocate<Data*>(rows_, capacity1_);
113 Memory::allocate<Data>(data_, capacity_);
117 for (
int i = 0; i < capacity1_; ++i) {
118 capacity2_[i] = rowSizes[i];
128 template <
class Data>
130 {
return !(data_ == 0); }
int capacity() const
Return allocated size.
Dynamically allocatable contiguous array template.
Dynamically allocated RaggedMatrix.
bool isAllocated() const
Return true iff this DRaggedMatrix has been allocated.
void allocate(DArray< int > const &rowSizes)
Allocate memory for a ragged matrix.
~DRaggedMatrix()
Destructor.
DRaggedMatrix()
Constructor.
A 2D array in which different rows can have different lengths.
int capacity1_
Number of rows (range of first index).
int * capacity2_
Array containing number of elements in each row.
Data ** rows_
Array of pointers to rows.
int capacity_
Total number of elements.
Data * data_
One-dimensional C array of all elements.
File containing preprocessor macros for error handling.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Utility classes for scientific computation.