6 namespace honey {
namespace matrix {
namespace priv
9 template<
class Sub
class>
21 static_assert((s_rows ==
dynamic || s_rows >= 0) && (s_cols ==
dynamic || s_cols >= 0),
"Matrix size must be zero or greater");
30 assert(rows == -1 || s_rows ==
dynamic || rows == s_rows,
sout() <<
"Can't change fixed row count from " << (
sdt)s_rows <<
" to " << rows);
31 assert(cols == -1 || s_cols ==
dynamic || cols == s_cols,
sout() <<
"Can't change fixed col count from " << (
sdt)s_cols <<
" to " << cols);
38 const ElemT*
data()
const {
return subc().data(); }
42 operator ElemT*() {
return data(); }
43 operator const ElemT*()
const {
return data(); }
46 const Subclass&
subc()
const {
return static_cast<const Subclass&
>(*this); }
47 Subclass&
subc() {
return static_cast<Subclass&
>(*this); }
57 template<
class Src,
class Dst>
59 {
if (!src.
size())
return; std::copy_n(src.
data(), src.
size(), dst.
data()); }
63 {
if (!dst.
size())
return; std::copy_n(src, dst.
size(), dst.
data()); }
67 {
if (!src.
size())
return; std::copy_n(src.
data(), src.
size(), dst); }
70 template<
class Src,
class Dst,
class Func>
72 {
if (!src.
size())
return; std::transform(src.
data(), src.
data() + src.
size(), dst.
data(), forward<Func>(f)); }
77 {
if (!store.
size())
return; std::fill_n(store.
data(), store.
size(), f); }
83 template<
class T,
class T2>
87 if (!lhs.
size())
return true;
92 template<
class Real, sdt Size, szt Align>
95 Real
a[Size > 0 ? Size : 1];
98 template<
class Real, sdt Size>
101 ALIGN(16) Real
a[Size > 0 ? Size : 1];
105 template<
class Sub
class>
127 const Real*
data()
const {
return _a.a; }
135 template<
class Sub
class>
164 assert(s_rows ==
dynamic || rhs._rows == s_rows,
sout() <<
"Can't change fixed row count from " << (
sdt)s_rows <<
" to " << rhs._rows);
165 assert(s_cols ==
dynamic || rhs._cols == s_cols,
sout() <<
"Can't change fixed col count from " << (
sdt)s_cols <<
" to " << rhs._cols);
171 _alloc = move(rhs._alloc);
188 if (rows == -1) rows = _rows;
189 if (cols == -1) cols = _cols;
190 assert(rows >= 0 && cols >= 0,
"Matrix size must be zero or greater");
191 assert(s_rows ==
dynamic || rows == s_rows,
sout() <<
"Can't change fixed row count from " << (
sdt)s_rows <<
" to " << rows);
192 assert(s_cols ==
dynamic || cols == s_cols,
sout() <<
"Can't change fixed col count from " << (
sdt)s_cols <<
" to " << cols);
196 if (size == _size)
return;
199 if (_size == 0)
return;
209 const Real*
data()
const {
return _a; }
232 template<
class Sub
class>
233 struct Storage :
public std::conditional< Traits<Subclass>::rows != dynamic && Traits<Subclass>::cols != dynamic,
234 StorageAuto<Subclass>, StorageDynamic<Subclass>>::type {};
const Real * data() const
Definition: Storage.h:209
const Real * operator[](sdt row) const
Access matrix element with [row][column].
Definition: Storage.h:113
static const sdt dynamic
Definition: Traits.h:23
void storageFillZero(StorageBlock< T > &store)
Fill block storage with zeros.
Definition: Block.h:136
ElemT & operator()(sdt row, sdt col)
Definition: Storage.h:24
sdt size() const
Definition: Storage.h:124
void setAllocator(const Alloc &alloc)
Definition: Storage.h:212
~StorageDynamic()
Definition: Storage.h:153
Traits< Subclass >::Real Real
Definition: Storage.h:12
static const sdt s_cols
Definition: Storage.h:16
Traits< Subclass >::ElemT ElemT
Definition: Storage.h:14
Real & operator()(sdt i)
Definition: Storage.h:117
Real * operator[](sdt row)
Definition: Storage.h:114
sdt size() const
Definition: Storage.h:36
ptrdiff_t sdt
Size difference type, shorthand for ptrdiff_t.
Definition: Core.h:92
StorageDynamic & operator=(const StorageDynamic &rhs)
Definition: Storage.h:155
const ElemT * data() const
Definition: Storage.h:38
bool storageEqual(const StorageBlock< T > &lhs, const StorageBlock< T2 > &rhs)
Test between block storages.
Definition: Block.h:157
const Real & operator()(sdt i) const
Access matrix element at index.
Definition: Storage.h:180
static const sdt s_rows
Definition: Storage.h:15
static const int options
Definition: Storage.h:18
const ElemT & operator()(sdt row, sdt col) const
Definition: Storage.h:23
Traits< Subclass >::Alloc Alloc
Definition: Storage.h:19
sdt rows() const
Definition: Storage.h:203
Chooses storage based on traits.
Definition: Storage.h:233
Real a[Size > 0?Size:1]
Definition: Storage.h:95
sdt cols() const
Definition: Storage.h:204
const Subclass & subc() const
Get the subclass that inherited from this base class.
Definition: Storage.h:46
static const sdt s_size
Definition: Storage.h:17
sdt size() const
Definition: Storage.h:205
unsigned char uint8
Definition: Core.h:12
void assertIndex(sdt i) const
Definition: Storage.h:50
StorageDynamic()
Default is null array.
Definition: Storage.h:147
ostringstream sout()
Shorthand to create ostringstream.
Definition: Stream.h:15
const Real * operator[](sdt row) const
Access matrix element with [row][column].
Definition: Storage.h:177
void storageTransform(const StorageBlock< Src > &src, StorageBlock< Dst > &dst, Func &&f)
Transform between block and dense storages.
Definition: Block.h:120
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
StorageDynamic(const StorageDynamic &rhs)
Init to copy of rhs.
Definition: Storage.h:149
sdt rows() const
Definition: Storage.h:122
Real * operator[](sdt row)
Definition: Storage.h:178
T * alloc(szt count=1)
Allocate memory for count number of T objects. Objects are not constructed.
Definition: Allocator.h:31
void resize(sdt rows, sdt cols)
Definition: Storage.h:186
Real & operator()(sdt row, sdt col)
Definition: Storage.h:184
sdt cols() const
Definition: Storage.h:123
Real & operator()(sdt i)
Definition: Storage.h:181
Real & operator()(sdt row, sdt col)
Definition: Storage.h:120
Subclass & subc()
Definition: Storage.h:47
Automatic (stack-compatible) dense storage.
Definition: Storage.h:106
StorageDynamic(StorageDynamic &&rhs)
Init to rhs and set rhs array to null.
Definition: Storage.h:151
void storageFill(StorageBlock< T > &store, typename StorageBlock< T >::Real f)
Fill block storage with scalar.
Definition: Block.h:128
Real * data()
Get as array.
Definition: Storage.h:208
Real * data()
Definition: Storage.h:128
sdt cols() const
Definition: Storage.h:35
const Real * data() const
Get as array.
Definition: Storage.h:127
sdt rows() const
Definition: Storage.h:34
StorageDynamic & operator=(StorageDynamic &&rhs)
Definition: Storage.h:162
void assertSize(sdt size) const
Definition: Storage.h:52
void storageCopy(const StorageBlock< Src > &src, StorageBlock< Dst > &dst)
Copy between block and dense storages.
Definition: Block.h:84
void freeAligned(T *p, Alloc &&a)
Deallocate aligned memory. Allocator element type must be int8.
Definition: Allocator.h:61
const Real & operator()(sdt i) const
Access matrix element at index.
Definition: Storage.h:116
dynamic (heap) dense storage
Definition: Storage.h:136
void resize(sdt rows, sdt cols)
Default resize, just asserts that fixed dimensions match args.
Definition: Storage.h:27
const Real & operator()(sdt row, sdt col) const
Access matrix element with (row, column)
Definition: Storage.h:183
Global Honeycomb namespace.
ElemT * data()
Definition: Storage.h:39
const Real & operator()(sdt row, sdt col) const
Access matrix element with (row, column)
Definition: Storage.h:119
void assertIndex(sdt row, sdt col) const
Definition: Storage.h:51
void assertSize(sdt rows, sdt cols) const
Definition: Storage.h:53