-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathDenseMatrix.h
626 lines (518 loc) · 24.1 KB
/
DenseMatrix.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
/*
* Copyright 2021 The DAPHNE Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <runtime/local/datastructures/DataObjectFactory.h>
#include <runtime/local/datastructures/Matrix.h>
#include <runtime/local/datastructures/ValueTypeUtils.h>
#include <iostream>
#include <memory>
#include <stdexcept>
#include <cstddef>
#include <cstring>
/**
* @brief A dense matrix implementation.
*
* This matrix implementation is backed by a single dense array of values. The
* values are arranged in row-major fashion. That is, the array contains all
* values in the first row, followed by all values in the second row, etc.
*
* Each instance of this class might represent a sub-matrix of another
* `DenseMatrix`. Thus, in general, the row skip (see `getRowSkip()`) needs to
* be added to a pointer to a particular cell in the `values` array in order to
* obtain a pointer to the corresponding cell in the next row.
*/
template <typename ValueType> class DenseMatrix : public Matrix<ValueType> {
// `using`, so that we do not need to prefix each occurrence of these
// fields from the super-classes.
using Matrix<ValueType>::numRows;
using Matrix<ValueType>::numCols;
const bool is_view;
size_t rowSkip;
// ToDo: handle this through MDO
std::shared_ptr<ValueType[]> values{};
size_t bufferSize;
size_t lastAppendedRowIdx;
size_t lastAppendedColIdx;
// Grant DataObjectFactory access to the private constructors and
// destructors.
template <class DataType, typename... ArgTypes> friend DataType *DataObjectFactory::create(ArgTypes...);
template <class DataType> friend void DataObjectFactory::destroy(const DataType *obj);
/**
* @brief Creates a `DenseMatrix` and allocates enough memory for the
* specified maximum size in the `values` array.
*
* @param maxNumRows The maximum number of rows.
* @param numCols The exact number of columns.
* @param zero Whether the allocated memory of the `values` array shall be
* initialized to zeros (`true`), or be left uninitialized (`false`).
*/
DenseMatrix(size_t maxNumRows, size_t numCols, bool zero, IAllocationDescriptor *allocInfo = nullptr);
/**
* @brief Creates a `DenseMatrix` around an existing array of values without
* copying the data.
*
* @param numRows The exact number of rows.
* @param numCols The exact number of columns.
* @param values A `std::shared_ptr` to an existing array of values.
*/
DenseMatrix(size_t numRows, size_t numCols, std::shared_ptr<ValueType[]> &values);
/**
* @brief Creates a `DenseMatrix` around a sub-matrix of another
* `DenseMatrix` without copying the data.
*
* @param src The other dense matrix.
* @param rowLowerIncl Inclusive lower bound for the range of rows to
* extract.
* @param rowUpperExcl Exclusive upper bound for the range of rows to
* extract.
* @param colLowerIncl Inclusive lower bound for the range of columns to
* extract.
* @param colUpperExcl Exclusive upper bound for the range of columns to
* extract.
*/
DenseMatrix(const DenseMatrix<ValueType> *src, int64_t rowLowerIncl, int64_t rowUpperExcl, int64_t colLowerIncl,
int64_t colUpperExcl);
DenseMatrix(const DenseMatrix<ValueType> *src, int64_t rowLowerIncl, int64_t rowUpperExcl)
: DenseMatrix(src, rowLowerIncl, rowUpperExcl, 0, src->numCols){};
/**
* @brief Creates a `DenseMatrix` around an existing array of values without
* copying the data.
*
* @param numRows The exact number of rows.
* @param numCols The exact number of columns.
* @param values A `std::shared_ptr` to an existing array of values.
*/
DenseMatrix(size_t numRows, size_t numCols, const DenseMatrix<ValueType> *src);
~DenseMatrix() override = default;
[[nodiscard]] size_t pos(size_t rowIdx, size_t colIdx, bool rowSkipOverride = false) const {
if (rowIdx >= numRows)
throw std::runtime_error("rowIdx is out of bounds");
if (colIdx >= numCols)
throw std::runtime_error("colIdx is out of bounds");
return rowIdx * (rowSkipOverride ? numCols : rowSkip) + colIdx;
}
void fillZeroUntil(size_t rowIdx, size_t colIdx) {
if (rowSkip == numCols || lastAppendedRowIdx == rowIdx) {
const size_t startPosIncl = pos(lastAppendedRowIdx, lastAppendedColIdx) + 1;
const size_t endPosExcl = pos(rowIdx, colIdx);
if (startPosIncl < endPosExcl)
std::fill(values.get() + startPosIncl, values.get() + endPosExcl,
ValueTypeUtils::defaultValue<ValueType>);
} else {
auto v = values.get() + lastAppendedRowIdx * rowSkip;
std::fill(v + lastAppendedColIdx + 1, v + numCols, ValueTypeUtils::defaultValue<ValueType>);
v += rowSkip;
for (size_t r = lastAppendedRowIdx + 1; r < rowIdx; r++) {
std::fill(v, v + numCols, ValueTypeUtils::defaultValue<ValueType>);
v += rowSkip;
}
if (colIdx)
std::fill(v, v + colIdx - 1, ValueTypeUtils::defaultValue<ValueType>);
}
}
void printValue(std::ostream &os, ValueType val) const;
void alloc_shared_values(std::shared_ptr<ValueType[]> src = nullptr, size_t offset = 0);
/**
* @brief The getValuesInternal method fetches a pointer to an allocation of
* values. Optionally a sub range can be specified.
*
* This method is called by the public getValues() methods either in const
* or non-const fashion. The const version returns a data pointer that is
* meant to be read-only. Read only access updates the list of up-to-date
* allocations (the latest_versions "list"). This way several copies of the
* data in various allocations can be kept without invalidating their copy.
* If the read write version of getValues() is used, the latest_versions
* list is cleared because a write to an allocation is assumed, which
* renders the other allocations of the same data out of sync.
*
* @param alloc_desc An instance of an IAllocationDescriptor derived class
* that is used to specify what type of allocation is requested. If no
* allocation descriptor is provided, a host allocation (plain main memory)
* is assumed by default.
*
* @param range An optional range describing which rows and columns of a
* matrix-like structure are requested. By default this is null and means
* all rows and columns.
* @return A tuple of three values is returned:
* 1: bool - is the returend allocation in the latest_versions list
* 2: size_t - the ID of the data placement (a structure relating an
* allocation to a range) 3: ValueType* - the pointer to the actual data
*/
auto getValuesInternal(const IAllocationDescriptor *alloc_desc = nullptr,
const Range *range = nullptr) -> std::tuple<bool, size_t, ValueType *>;
[[nodiscard]] size_t offset() const { return this->row_offset * rowSkip + this->col_offset; }
ValueType *startAddress() const { return isPartialBuffer() ? values.get() + offset() : values.get(); }
public:
template <typename NewValueType> using WithValueType = DenseMatrix<NewValueType>;
static std::string getName() { return "DenseMatrix"; }
[[nodiscard]] bool isPartialBuffer() const {
return bufferSize != this->getNumRows() * this->getRowSkip() * sizeof(ValueType);
}
void shrinkNumRows(size_t numRows) {
if (numRows > this->numRows)
throw std::runtime_error("DenseMatrix (shrinkNumRows): number of "
"rows can only be shrunk");
// TODO Here we could reduce the allocated size of the values array.
this->numRows = numRows;
}
[[nodiscard]] size_t getRowSkip() const { return rowSkip; }
[[nodiscard]] bool isView() const { return is_view; }
/**
* @brief Fetch a pointer to the data held by this structure meant for
* read-only access.
*
* A difference is made between read-only and read-write access because with
* read-only access, the data can be cached in several memory spaces at the
* same time.
*
* @param alloc_desc An allocation descriptor describing which type of
* memory is requested (e.g. main memory in the current system, memory in an
* accelerator card or memory in another host)
*
* @param range A Range object describing optionally requesting a sub range
* of a data structure.
* @return A pointer to the data in the requested memory space
*/
const ValueType *getValues(const IAllocationDescriptor *alloc_desc = nullptr, const Range *range = nullptr) const {
auto [isLatest, id, ptr] = const_cast<DenseMatrix<ValueType> *>(this)->getValuesInternal(alloc_desc, range);
if (!isLatest)
this->mdo->addLatest(id);
return ptr;
}
/**
* @brief Fetch a pointer to the data held by this structure meant for
* read-write access.
*
* A difference is made between read-only and read-write access. With
* read-write access, all copies in various memory spaces will be
* invalidated because data is assumed to change.
*
* @param alloc_desc An allocation descriptor describing which type of
* memory is requested (e.g. main memory in the current system, memory in an
* accelerator card or memory in another host)
*
* @param range A Range object describing optionally requesting a sub range
* of a data structure.
* @return A pointer to the data in the requested memory space
*/
ValueType *getValues(IAllocationDescriptor *alloc_desc = nullptr, const Range *range = nullptr) {
auto [isLatest, id, ptr] = const_cast<DenseMatrix<ValueType> *>(this)->getValuesInternal(alloc_desc, range);
if (!isLatest)
this->mdo->setLatest(id);
return ptr;
}
std::shared_ptr<ValueType[]> getValuesSharedPtr() const { return values; }
ValueType get(size_t rowIdx, size_t colIdx) const override {
return getValues()[pos(rowIdx, colIdx, isPartialBuffer())];
}
void set(size_t rowIdx, size_t colIdx, ValueType value) override {
auto vals = getValues();
vals[pos(rowIdx, colIdx)] = value;
}
void prepareAppend() override {
// The matrix might be empty.
if (numRows != 0 && numCols != 0)
values.get()[0] = ValueType(ValueTypeUtils::defaultValue<ValueType>);
lastAppendedRowIdx = 0;
lastAppendedColIdx = 0;
}
void append(size_t rowIdx, size_t colIdx, ValueType value) override {
// Set all cells since the last one that was appended to zero.
fillZeroUntil(rowIdx, colIdx);
// Set the specified cell.
values.get()[pos(rowIdx, colIdx)] = value;
// Update append state.
lastAppendedRowIdx = rowIdx;
lastAppendedColIdx = colIdx;
}
void finishAppend() override {
// The matrix might be empty.
if ((numRows != 0 && numCols != 0) &&
((lastAppendedRowIdx + 1 < numRows) || (lastAppendedColIdx + 1 < numCols)))
append(numRows - 1, numCols - 1, ValueType(ValueTypeUtils::defaultValue<ValueType>));
}
void print(std::ostream &os) const override {
os << "DenseMatrix(" << numRows << 'x' << numCols << ", " << ValueTypeUtils::cppNameFor<ValueType> << ')'
<< std::endl;
for (size_t r = 0; r < numRows; r++) {
for (size_t c = 0; c < numCols; c++) {
printValue(os, get(r, c));
if (c < numCols - 1)
os << ' ';
}
os << std::endl;
}
}
DenseMatrix<ValueType> *sliceRow(size_t rl, size_t ru) const override { return slice(rl, ru, 0, numCols); }
DenseMatrix<ValueType> *sliceCol(size_t cl, size_t cu) const override { return slice(0, numRows, cl, cu); }
DenseMatrix<ValueType> *slice(size_t rl, size_t ru, size_t cl, size_t cu) const override {
return DataObjectFactory::create<DenseMatrix<ValueType>>(this, rl, ru, cl, cu);
}
[[nodiscard]] size_t getBufferSize() const { return bufferSize; }
bool operator==(const DenseMatrix<ValueType> &rhs) const {
// Note that we do not use the generic `get` interface to matrices here
// since this operator is meant to be used for writing tests for,
// besides others, those generic interfaces.
if (this == &rhs)
return true;
const size_t numRows = this->getNumRows();
const size_t numCols = this->getNumCols();
if (numRows != rhs.getNumRows() || numCols != rhs.getNumCols())
return false;
const ValueType *valuesLhs = this->getValues();
const ValueType *valuesRhs = rhs.getValues();
const size_t rowSkipLhs = this->getRowSkip();
const size_t rowSkipRhs = rhs.getRowSkip();
if (valuesLhs == valuesRhs && rowSkipLhs == rowSkipRhs)
return true;
for (size_t r = 0; r < numRows; ++r) {
for (size_t c = 0; c < numCols; ++c) {
if (*(valuesLhs + c) != *(valuesRhs + c))
return false;
}
valuesLhs += rowSkipLhs;
valuesRhs += rowSkipRhs;
}
return true;
}
size_t serialize(std::vector<char> &buf) const override;
};
template <typename ValueType> std::ostream &operator<<(std::ostream &os, const DenseMatrix<ValueType> &obj) {
obj.print(os);
return os;
}
/*
Helper struct for DenseMatrix with strings, represents a char buffer.
Needs to keep numCells from original DenseMatrix to manage modifications
from views.
*/
struct CharBuf {
char *strings;
char *currentTop;
size_t capacity;
size_t numCells;
CharBuf(size_t capacity_, size_t numCells_) : capacity(capacity_), numCells(numCells_) {
strings = new char[capacity];
currentTop = strings;
}
~CharBuf() { delete[] strings; }
void expandStringBuffer(const size_t toFit, const char **vals, size_t numRows, size_t rowSkip,
const size_t valsSize) {
size_t strBufSize = getSize();
size_t largerStrCapacity = (capacity * 2) > toFit ? (capacity * 2) : toFit;
char *largerStrings = new char[largerStrCapacity];
memcpy(largerStrings, strings, strBufSize);
auto start = vals[0];
const size_t numCols = numCells / numRows;
for (size_t r = 0; r < numRows; r++) {
for (size_t c = 0; c < numCols; c++) {
size_t offset = vals[c] - start;
vals[c] = &largerStrings[offset];
}
vals += rowSkip;
}
delete[] strings;
strings = largerStrings;
capacity = largerStrCapacity;
currentTop = &largerStrings[strBufSize];
}
size_t getSize() { return currentTop - strings; }
};
template <> class DenseMatrix<const char *> : public Matrix<const char *> {
// `using`, so that we do not need to prefix each occurrence of these
// fields from the super-classes.
using Matrix<const char *>::numRows;
using Matrix<const char *>::numCols;
size_t rowSkip;
std::shared_ptr<const char *[]> values{};
std::shared_ptr<CharBuf> strBuf;
std::shared_ptr<const char *> cuda_ptr{};
uint32_t deleted = 0;
size_t lastAppendedRowIdx;
size_t lastAppendedColIdx;
// Grant DataObjectFactory access to the private constructors and
// destructors.
template <class DataType, typename... ArgTypes> friend DataType *DataObjectFactory::create(ArgTypes...);
template <class DataType> friend void DataObjectFactory::destroy(const DataType *obj);
DenseMatrix(size_t maxNumRows, size_t numCols, bool zero, size_t strBufCapacity = 1024,
ALLOCATION_TYPE type = ALLOCATION_TYPE::HOST);
DenseMatrix(size_t numRows, size_t numCols, std::shared_ptr<const char *[]> &strings, size_t strBufCapacity = 1024,
std::shared_ptr<const char *> cuda_ptr_ = nullptr);
DenseMatrix(const DenseMatrix<const char *> *src, int64_t rowLowerIncl, int64_t rowUpperExcl, int64_t colLowerIncl,
int64_t colUpperExcl);
~DenseMatrix() override = default;
/**
* @brief Calculates the position within linear memory given row/col indices
*
* @param rowIdx
* @param colIdx
* @param rowSkipOverride use numCols instead of rowSkip if get() is used on
* a partial buffer
* @return linearized position
*/
[[nodiscard]] size_t pos(size_t rowIdx, size_t colIdx, bool rowSkipOverride = false) const {
if (rowIdx >= numRows)
throw std::runtime_error("rowIdx is out of bounds");
if (colIdx >= numCols)
throw std::runtime_error("colIdx is out of bounds");
return rowIdx * (rowSkipOverride ? numCols : rowSkip) + colIdx;
}
void appendZerosRange(const char **valsStartPos, const size_t length) {
memset(strBuf->currentTop, '\0', length * sizeof(char));
for (size_t val = 0; val < length; val++) {
valsStartPos[val] = &strBuf->currentTop[val];
}
strBuf->currentTop += length;
}
void fillZeroUntil(size_t rowIdx, size_t colIdx) {
auto vals = values.get();
if (rowSkip == numCols || lastAppendedRowIdx == rowIdx) {
const size_t startPosIncl = pos(lastAppendedRowIdx, lastAppendedColIdx) + 1;
const size_t endPosExcl = pos(rowIdx, colIdx);
if (startPosIncl < endPosExcl) {
appendZerosRange(&vals[startPosIncl], endPosExcl - startPosIncl);
}
} else {
auto v = vals + lastAppendedRowIdx * rowSkip;
appendZerosRange(&v[lastAppendedColIdx + 1], numCols - lastAppendedColIdx - 1);
v += rowSkip;
for (size_t r = lastAppendedRowIdx + 1; r < rowIdx; r++) {
appendZerosRange(v, numCols);
v += rowSkip;
}
if (colIdx)
appendZerosRange(v, colIdx - 1);
}
}
void printValue(std::ostream &os, const char *val) const;
void alloc_shared_values(std::shared_ptr<const char *[]> src = nullptr, size_t offset = 0);
void alloc_shared_strings(std::shared_ptr<CharBuf> src = nullptr, size_t strBufferCapacity = 1024);
void alloc_shared_cuda_buffer(std::shared_ptr<const char *> src = nullptr, size_t offset = 0);
public:
void shrinkNumRows(size_t numRows) {
if (numRows > this->numRows)
throw std::runtime_error("DenseMatrix (shrinkNumRows): number of "
"rows can only be shrunk");
// TODO Here we could reduce the allocated size of the values array.
this->numRows = numRows;
}
[[nodiscard]] size_t getRowSkip() const { return rowSkip; }
const char **getValues() const {
if (!values)
const_cast<DenseMatrix *>(this)->alloc_shared_values();
return values.get();
}
const char **getValues() {
if (!values)
alloc_shared_values();
return values.get();
}
std::shared_ptr<CharBuf> getStrBufSharedPtr() const { return strBuf; }
CharBuf *getStrBuf() const {
if (!strBuf)
const_cast<DenseMatrix *>(this)->alloc_shared_strings();
return strBuf.get();
}
CharBuf *getStrBuf() {
if (!strBuf)
alloc_shared_strings();
return strBuf.get();
}
std::shared_ptr<const char *[]> getValuesSharedPtr() const { return values; }
const char *get(size_t rowIdx, size_t colIdx) const override { return getValues()[pos(rowIdx, colIdx, false)]; }
void set(size_t rowIdx, size_t colIdx, const char *value) override {
auto vals = getValues();
size_t currentPos = pos(rowIdx, colIdx);
auto currentVal = vals[currentPos];
size_t currentSize = strBuf.get()->getSize();
int32_t diff = strlen(value) - strlen(currentVal);
if (currentSize + diff > strBuf->capacity) {
strBuf.get()->expandStringBuffer(currentSize + diff, vals, numRows, rowSkip, getNumItems());
currentVal = vals[currentPos];
}
if (diff && (currentPos + 1 < getStrBuf()->numCells)) {
const char *from = values[currentPos + 1];
const char *to = from + diff;
size_t length = strBuf->currentTop - from;
memmove(const_cast<char *>(to), from, length);
}
memcpy(const_cast<char *>(currentVal), value, strlen(value) + 1);
if (diff) {
for (size_t offset = currentPos + 1; offset < getStrBuf()->numCells; offset++)
vals[offset] += diff;
}
strBuf->currentTop += diff;
}
void prepareAppend() override {
// the matrix might be empty
if (numRows != 0 && numCols != 0)
values.get()[0] = "\0";
lastAppendedRowIdx = 0;
lastAppendedColIdx = 0;
strBuf->currentTop = strBuf.get()->strings;
}
void append(size_t rowIdx, size_t colIdx, const char *value) override {
// Set all cells since the last one that was appended to zero.
fillZeroUntil(rowIdx, colIdx);
auto vals = getValues();
// Set the specified cell.
size_t length = strlen(value) + 1;
size_t currentSize = strBuf.get()->getSize();
if (currentSize + length > strBuf->capacity)
strBuf.get()->expandStringBuffer(currentSize + length, vals, numRows, rowSkip, getNumRows() * getNumCols());
memcpy(strBuf->currentTop, value, length);
vals[pos(rowIdx, colIdx)] = strBuf->currentTop;
strBuf->currentTop += length;
// Update append state.
lastAppendedRowIdx = rowIdx;
lastAppendedColIdx = colIdx;
}
void finishAppend() override {
// numRows/numCols are unsigned and can underflow
if ((numRows != 0 && numCols != 0) &&
((lastAppendedRowIdx + 1 < numRows) || (lastAppendedColIdx + 1 < numCols)))
append(numRows - 1, numCols - 1, "\0");
}
void print(std::ostream &os) const override {
os << "DenseMatrix(" << numRows << 'x' << numCols << ", " << ValueTypeUtils::cppNameFor<const char *> << ')'
<< std::endl;
for (size_t r = 0; r < numRows; r++) {
for (size_t c = 0; c < numCols; c++) {
printValue(os, get(r, c));
if (c < numCols - 1)
os << ' ';
}
os << std::endl;
}
}
DenseMatrix<const char *> *sliceRow(size_t rl, size_t ru) const override { return slice(rl, ru, 0, numCols); }
DenseMatrix<const char *> *sliceCol(size_t cl, size_t cu) const override { return slice(0, numRows, cl, cu); }
DenseMatrix<const char *> *slice(size_t rl, size_t ru, size_t cl, size_t cu) const override {
return DataObjectFactory::create<DenseMatrix<const char *>>(this, rl, ru, cl, cu);
}
float printBufferSize() const { return static_cast<float>(numRows * numCols) / (1048576); }
bool operator==(const DenseMatrix<const char *> &M) const {
if (getNumRows() == 0 || getNumCols() == 0 || !strBuf || !values)
throw std::runtime_error("DenseMatrix (operator==): invalid "
"matrix. DenseMatrix must not be empty");
for (size_t r = 0; r < getNumRows(); r++)
for (size_t c = 0; c < getNumCols(); c++)
if (strcmp(M.getValues()[M.pos(r, c)], values.get()[pos(r, c)]))
return false;
return true;
}
size_t serialize(std::vector<char> &buf) const override { throw std::runtime_error("Not implemented"); }
};