33 #include <forward_list>
35 #include <initializer_list>
43 #include <type_traits>
70 template<
typename dtype,
class Allocator = std::allocator<dtype>>
74 STATIC_ASSERT_VALID_DTYPE(dtype);
75 static_assert(is_same_v<dtype, typename Allocator::value_type>,
76 "value_type and Allocator::value_type must match");
78 using AllocType =
typename std::allocator_traits<Allocator>::template rebind_alloc<dtype>;
79 using AllocTraits = std::allocator_traits<AllocType>;
84 using pointer =
typename AllocTraits::pointer;
114 shape_(inSquareSize, inSquareSize),
115 size_(inSquareSize * inSquareSize)
128 shape_(inNumRows, inNumCols),
129 size_(inNumRows * inNumCols)
153 NdArray(std::initializer_list<dtype> inList) :
154 shape_(1, static_cast<
uint32>(inList.
size())),
170 NdArray(
const std::initializer_list<std::initializer_list<dtype>>& inList) :
173 for (
const auto& list : inList)
175 if (shape_.
cols == 0)
177 shape_.
cols =
static_cast<uint32>(list.size());
179 else if (list.size() != shape_.
cols)
182 "All rows of the initializer list needs to have the same number of elements");
186 size_ = shape_.
size();
189 for (
const auto& list : inList)
205 template<
size_t ArraySize, std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
206 NdArray(std::array<dtype, ArraySize>& inArray,
bool copy =
true) :
207 shape_(1, static_cast<
uint32>(ArraySize)),
220 array_ = inArray.data();
233 template<
size_t Dim0Size,
size_t Dim1Size>
234 NdArray(std::array<std::array<dtype, Dim1Size>, Dim0Size>& in2dArray,
bool copy =
true) :
235 shape_(static_cast<
uint32>(Dim0Size), static_cast<
uint32>(Dim1Size)),
243 const auto start = in2dArray.front().begin();
249 array_ = in2dArray.front().data();
262 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
264 shape_(1, static_cast<
uint32>(inVector.
size())),
277 array_ = inVector.data();
288 explicit NdArray(
const std::vector<std::vector<dtype>>& in2dVector) :
289 shape_(static_cast<
uint32>(in2dVector.
size()), 0)
291 for (
const auto&
row : in2dVector)
293 if (shape_.
cols == 0)
297 else if (
row.size() != shape_.
cols)
303 size_ = shape_.
size();
306 auto currentPosition =
begin();
307 for (
const auto&
row : in2dVector)
310 currentPosition += shape_.
cols;
322 template<
size_t Dim1Size>
323 NdArray(std::vector<std::array<dtype, Dim1Size>>& in2dArray,
bool copy =
true) :
324 shape_(static_cast<
uint32>(in2dArray.
size()), static_cast<
uint32>(Dim1Size)),
332 const auto start = in2dArray.front().begin();
338 array_ = in2dArray.front().data();
349 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
350 explicit NdArray(
const std::deque<dtype>& inDeque) :
351 shape_(1, static_cast<
uint32>(inDeque.
size())),
367 explicit NdArray(
const std::deque<std::deque<dtype>>& in2dDeque) :
368 shape_(static_cast<
uint32>(in2dDeque.
size()), 0)
370 for (
const auto&
row : in2dDeque)
372 if (shape_.
cols == 0)
376 else if (
row.size() != shape_.
cols)
382 size_ = shape_.
size();
385 auto currentPosition =
begin();
386 for (
const auto&
row : in2dDeque)
389 currentPosition += shape_.
cols;
399 explicit NdArray(
const std::list<dtype>& inList) :
400 shape_(1, static_cast<
uint32>(inList.
size())),
417 template<
typename Iterator,
418 std::enable_if_t<is_same_v<typename std::iterator_traits<Iterator>::value_type, dtype>,
int> = 0>
420 shape_(1, static_cast<
uint32>(std::distance(inFirst, inLast))),
443 if (inPtr !=
nullptr && size_ > 0)
458 template<
typename UIntType1,
460 std::enable_if_t<!is_same_v<UIntType1, bool>,
int> = 0,
461 std::enable_if_t<!is_same_v<UIntType2, bool>,
int> = 0>
467 if (inPtr !=
nullptr && size_ > 0)
483 template<
typename BoolType, std::enable_if_t<is_same_v<BoolType,
bool>,
int> = 0>
488 ownsPtr_(takeOwnership)
503 template<
typename BoolType, std::enable_if_t<is_same_v<BoolType,
bool>,
int> = 0>
508 ownsPtr_(takeOwnership)
519 shape_(inOtherArray.shape_),
520 size_(inOtherArray.size_),
521 endianess_(inOtherArray.endianess_)
537 shape_(inOtherArray.shape_),
538 size_(inOtherArray.size_),
539 endianess_(inOtherArray.endianess_),
540 array_(inOtherArray.array_),
541 ownsPtr_(inOtherArray.ownsPtr_)
543 inOtherArray.shape_.rows = inOtherArray.shape_.cols = 0;
544 inOtherArray.size_ = 0;
545 inOtherArray.ownsPtr_ =
false;
546 inOtherArray.array_ =
nullptr;
571 newArray(rhs.shape_);
572 endianess_ = rhs.endianess_;
591 if (array_ !=
nullptr)
613 endianess_ = rhs.endianess_;
615 ownsPtr_ = rhs.ownsPtr_;
617 rhs.shape_.rows = rhs.shape_.cols = rhs.size_ = 0;
618 rhs.array_ =
nullptr;
619 rhs.ownsPtr_ =
false;
639 return array_[inIndex];
656 return array_[inIndex];
671 inRowIndex += shape_.
rows;
676 inColIndex += shape_.
cols;
679 return array_[inRowIndex * shape_.
cols + inColIndex];
694 inRowIndex += shape_.
rows;
699 inColIndex += shape_.
cols;
702 return array_[inRowIndex * shape_.
cols + inColIndex];
715 Slice inSliceCopy(inSlice);
721 returnArray[counter++] =
at(i);
736 if (inMask.
shape() != shape_)
739 "input inMask must have the same shape as the NdArray it will be masking.");
744 for (
size_type i = 0; i < indices.size(); ++i)
760 template<
typename Indices, enable_if_t<is_same_v<Indices, NdArray<
size_type>>,
int> = 0>
763 if (inIndices.max().item() > size_ - 1)
770 for (
auto& index : inIndices)
797 returnArray(rowCounter, colCounter++) =
at(
row, col);
822 returnArray(rowCounter++, 0) =
at(
row, inColIndex);
844 returnArray(0, colCounter++) =
at(inRowIndex, col);
859 template<
typename Indices,
876 template<
typename Indices,
892 template<
typename Indices,
909 template<
typename Indices,
925 template<
typename RowIndices,
934 std::vector<int32> rowIndicesUnique(rowIndices.size());
935 std::vector<int32> colIndicesUnique(colIndices.size());
943 static_cast<uint32>(lastCol - colIndicesUnique.begin()));
946 for (
auto rowIter = rowIndicesUnique.begin(); rowIter != lastRow; ++rowIter)
949 for (
auto colIter = colIndicesUnique.begin(); colIter != lastCol; ++colIter)
951 returnArray(rowCounter, colCounter++) =
at(*rowIter, *colIter);
971 return Slice(inStartIdx, shape_.
cols, inStepSize);
985 return Slice(inStartIdx, shape_.
rows, inStepSize);
1002 errStr +=
" is out of bounds for array of size " +
utils::num2str(size_) +
".";
1023 errStr +=
" is out of bounds for array of size " +
utils::num2str(size_) +
".";
1045 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
rows) +
".";
1053 std::string errStr =
"Column index " +
utils::num2str(inColIndex);
1054 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
cols) +
".";
1076 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
rows) +
".";
1084 std::string errStr =
"Column index " +
utils::num2str(inColIndex);
1085 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
cols) +
".";
1185 if (inRow >= shape_.
rows)
1190 return begin() += (inRow * shape_.
cols);
1235 if (inRow >= shape_.
rows)
1262 if (inCol >= shape_.
cols)
1312 if (inCol >= shape_.
cols)
1339 if (inRow >= shape_.
rows)
1389 if (inRow >= shape_.
rows)
1416 if (inCol >= shape_.
cols)
1466 if (inCol >= shape_.
cols)
1481 return begin() += size_;
1493 if (inRow >= shape_.
rows)
1531 return cbegin() += size_;
1543 if (inRow >= shape_.
rows)
1558 return rbegin() += size_;
1570 if (inRow >= shape_.
rows)
1597 return crend(inRow);
1620 if (inRow >= shape_.
rows)
1647 if (inCol >= shape_.
cols)
1697 if (inCol >= shape_.
cols)
1724 if (inCol >= shape_.
cols)
1774 if (inCol >= shape_.
cols)
1795 const auto function = [](dtype i) ->
bool {
return i != dtype{ 0 }; };
1820 returnArray(0,
row) =
1847 const auto function = [](dtype i) ->
bool {
return i != dtype{ 0 }; };
1872 returnArray(0,
row) =
1900 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
1915 returnArray(0,
row) =
static_cast<uint32>(
1927 returnArray(0,
row) =
1958 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
1973 returnArray(0,
row) =
static_cast<uint32>(
1985 returnArray(0,
row) =
2019 std::vector<uint32> idx(size_);
2020 std::iota(idx.begin(), idx.end(), 0);
2022 const auto function = [
this](
uint32 i1,
uint32 i2) noexcept ->
bool
2023 {
return (*
this)[i1] < (*this)[i2]; };
2031 std::vector<uint32> idx(shape_.
cols);
2035 std::iota(idx.begin(), idx.end(), 0);
2037 const auto function = [
this,
row](
uint32 i1,
uint32 i2) noexcept ->
bool
2042 for (
uint32 col = 0; col < shape_.
cols; ++col)
2044 returnArray(
row, col) = idx[col];
2053 std::vector<uint32> idx(arrayTransposed.shape_.
cols);
2057 std::iota(idx.begin(), idx.end(), 0);
2059 const auto function = [&arrayTransposed,
row](
uint32 i1,
uint32 i2) noexcept ->
bool
2060 {
return arrayTransposed(
row, i1) < arrayTransposed(
row, i2); };
2064 for (
uint32 col = 0; col < arrayTransposed.shape_.
cols; ++col)
2066 returnArray(
row, col) = idx[col];
2088 template<
typename dtypeOut,
2089 typename dtype_ = dtype,
2099 [](dtype value) -> dtypeOut { return static_cast<dtypeOut>(value); });
2113 template<
typename dtypeOut,
2114 typename dtype_ = dtype,
2123 {
return std::complex<typename dtypeOut::value_type>(value); };
2139 template<
typename dtypeOut,
2140 typename dtype_ = dtype,
2148 if (is_same_v<dtypeOut, dtype>)
2155 {
return complex_cast<typename dtypeOut::value_type>(value); };
2172 template<
typename dtypeOut,
2173 typename dtype_ = dtype,
2181 const auto function = [](
const_reference value) -> dtypeOut {
return static_cast<dtypeOut
>(value.real()); };
2196 return *(
cend() - 1);
2207 return *(
end() - 1);
2288 [inMin, inMax](dtype value) noexcept -> dtype
2290 #ifdef __cpp_lib_clamp
2291 const auto comparitor = [](dtype lhs, dtype rhs) noexcept -> bool
2292 { return lhs < rhs; };
2294 return std::clamp(value, inMin, inMax, comparitor);
2300 else if (value > inMax)
2321 return operator()(rSlice(), inColumn);
2346 for (
uint32 row = 0; row < shape_.rows; ++row)
2357 for (
uint32 row = 0; row < transArray.shape_.
rows; ++row)
2359 returnArray(0, row) =
2361 transArray.
cend(row);
2405 returnArray[0] = front();
2406 for (
uint32 i = 1; i < size_; ++i)
2408 returnArray[i] = returnArray[i - 1] * array_[i];
2416 for (
uint32 row = 0; row < shape_.rows; ++row)
2418 returnArray(row, 0) = operator()(row, 0);
2419 for (
uint32 col = 1; col < shape_.cols; ++col)
2421 returnArray(row, col) = returnArray(row, col - 1) * operator()(row, col);
2430 for (
uint32 col = 0; col < shape_.cols; ++col)
2432 returnArray(0, col) = operator()(0, col);
2433 for (
uint32 row = 1; row < shape_.rows; ++row)
2435 returnArray(row, col) = returnArray(row - 1, col) * operator()(row, col);
2467 returnArray[0] = front();
2468 for (
uint32 i = 1; i < size_; ++i)
2470 returnArray[i] = returnArray[i - 1] + array_[i];
2478 for (
uint32 row = 0; row < shape_.rows; ++row)
2480 returnArray(row, 0) = operator()(row, 0);
2481 for (
uint32 col = 1; col < shape_.cols; ++col)
2483 returnArray(row, col) = returnArray(row, col - 1) + operator()(row, col);
2492 for (
uint32 col = 0; col < shape_.cols; ++col)
2494 returnArray(0, col) = operator()(0, col);
2495 for (
uint32 row = 1; row < shape_.rows; ++row)
2497 returnArray(row, col) = returnArray(row - 1, col) + operator()(row, col);
2561 std::vector<dtype> diagnolValues;
2562 int32 col = inOffset;
2563 for (
uint32 row = 0; row < shape_.rows; ++row)
2570 if (col >=
static_cast<int32>(shape_.cols))
2575 diagnolValues.push_back(
operator()(row,
static_cast<uint32>(col)));
2583 std::vector<dtype> diagnolValues;
2585 for (
int32 row = inOffset; row < static_cast<int32>(shape_.rows); ++row)
2592 if (col >= shape_.cols)
2597 diagnolValues.push_back(
operator()(
static_cast<uint32>(row), col));
2627 if (shape_ == inOtherArray.shape_ && (shape_.rows == 1 || shape_.cols == 1))
2629 dtype dotProduct = std::inner_product(cbegin(), cend(), inOtherArray.
cbegin(), dtype{ 0 });
2633 if (shape_.cols == inOtherArray.shape_.
rows)
2637 auto otherArrayT = inOtherArray.
transpose();
2639 for (
uint32 i = 0; i < shape_.rows; ++i)
2641 for (
uint32 j = 0;
j < otherArrayT.shape_.rows; ++
j)
2644 std::inner_product(otherArrayT.cbegin(
j), otherArrayT.cend(
j), cbegin(i), dtype{ 0 });
2654 errStr +=
" are not consistent.";
2669 void dump(
const std::string& inFilename)
const
2677 std::ofstream ofile(
f.fullName().c_str(), std::ios::binary);
2683 if (array_ !=
nullptr)
2685 ofile.write(
reinterpret_cast<const char*
>(array_), size_ *
sizeof(dtype));
2729 std::vector<uint32> indices;
2731 for (
auto value : *
this)
2733 if (value != dtype{ 0 })
2735 indices.push_back(idx);
2788 return *cbegin(row);
2811 return operator[](inIndices);
2825 return operator[](inMask);
2849 return shape_.rows == 1 || shape_.cols == 1;
2863 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
2875 for (
uint32 row = 0; row < transposedArray.shape_.rows; ++row)
2878 transposedArray.cend(row),
2887 for (
uint32 row = 0; row < shape_.rows; ++row)
2910 return shape_.issquare();
2944 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
2956 for (
uint32 row = 0; row < shape_.rows; ++row)
2967 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
2970 transposedArray.
cend(row),
2997 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
3009 for (
uint32 row = 0; row < shape_.rows; ++row)
3020 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3023 transposedArray.
cend(row),
3052 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
3065 const uint32 middleIdx = size_ / 2;
3067 copyArray.
begin() + middleIdx,
3071 dtype medianValue = copyArray.array_[middleIdx];
3074 const uint32 lhsIndex = middleIdx - 1;
3076 copyArray.
begin() + lhsIndex,
3080 (medianValue + copyArray.array_[lhsIndex]) / dtype{ 2 };
3083 return { medianValue };
3090 const bool isEven = shape_.cols % 2 == 0;
3091 for (
uint32 row = 0; row < shape_.rows; ++row)
3093 const uint32 middleIdx = shape_.cols / 2;
3095 copyArray.
begin(row) + middleIdx,
3099 dtype medianValue = copyArray(row, middleIdx);
3102 const uint32 lhsIndex = middleIdx - 1;
3104 copyArray.
begin(row) + lhsIndex,
3107 medianValue = (medianValue + copyArray(row, lhsIndex)) /
3111 returnArray(0, row) = medianValue;
3121 const bool isEven = shape_.rows % 2 == 0;
3122 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3124 const uint32 middleIdx = transposedArray.shape_.
cols / 2;
3126 transposedArray.
begin(row) + middleIdx,
3127 transposedArray.
end(row),
3130 dtype medianValue = transposedArray(row, middleIdx);
3133 const uint32 lhsIndex = middleIdx - 1;
3135 transposedArray.
begin(row) + lhsIndex,
3136 transposedArray.
end(row),
3138 medianValue = (medianValue + transposedArray(row, lhsIndex)) /
3142 returnArray(0, row) = medianValue;
3178 return static_cast<uint64>(
sizeof(dtype) * size_);
3201 switch (inEndianess)
3220 auto outArray =
NdArray(*
this);
3229 auto outArray =
NdArray(*
this);
3253 switch (inEndianess)
3268 auto outArray =
NdArray(*
this);
3296 switch (inEndianess)
3302 auto outArray =
NdArray(*
this);
3358 const auto function = [](dtype i) ->
bool {
return i != dtype{ 0 }; };
3370 for (
uint32 row = 0; row < shape_.rows; ++row)
3381 for (
uint32 row = 0; row < arrayTransposed.shape_.
rows; ++row)
3383 returnArray(0, row) =
3476 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
3494 if (inKth >= shape_.cols)
3497 errStr +=
") out of bounds (" +
utils::num2str(shape_.cols) +
")";
3501 for (
uint32 row = 0; row < shape_.rows; ++row)
3509 if (inKth >= shape_.rows)
3512 errStr +=
") out of bounds (" +
utils::num2str(shape_.rows) +
")";
3517 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3520 transposedArray.
begin(row) + inKth,
3521 transposedArray.
end(row),
3561 dtype product = std::accumulate(cbegin(), cend(), dtype{ 1 }, std::multiplies<dtype>());
3568 for (
uint32 row = 0; row < shape_.rows; ++row)
3570 returnArray(0, row) =
3571 std::accumulate(cbegin(row), cend(row), dtype{ 1 }, std::multiplies<dtype>());
3580 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3582 returnArray(0, row) = std::accumulate(transposedArray.
cbegin(row),
3583 transposedArray.
cend(row),
3585 std::multiplies<dtype>());
3611 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
3624 for (
uint32 row = 0; row < shape_.rows; ++row)
3627 returnArray(0, row) = *result.second - *result.first;
3636 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3639 transposedArray.
cend(row),
3641 returnArray(0, row) = *result.second - *result.first;
3665 at(inIndex) = inValue;
3682 at(inRow, inCol) = inValue;
3698 for (
auto index : inIndices)
3700 put(index, inValue);
3717 if (inIndices.
size() != inValues.
size())
3723 for (
auto index : inIndices)
3725 put(index, inValues[counter++]);
3742 Slice inSliceCopy(inSlice);
3764 Slice inSliceCopy(inSlice);
3767 std::vector<uint32> indices;
3770 indices.push_back(i);
3788 Slice inRowSliceCopy(inRowSlice);
3789 Slice inColSliceCopy(inColSlice);
3794 std::vector<uint32> indices;
3795 for (
int32 row = inRowSliceCopy.
start; row < inRowSliceCopy.
stop; row += inRowSliceCopy.
step)
3797 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3799 put(row, col, inValue);
3818 Slice inRowSliceCopy(inRowSlice);
3821 std::vector<uint32> indices;
3822 for (
int32 row = inRowSliceCopy.
start; row < inRowSliceCopy.
stop; row += inRowSliceCopy.
step)
3824 put(row, inColIndex, inValue);
3842 Slice inColSliceCopy(inColSlice);
3845 std::vector<uint32> indices;
3846 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3848 put(inRowIndex, col, inValue);
3866 Slice inRowSliceCopy(inRowSlice);
3867 Slice inColSliceCopy(inColSlice);
3872 std::vector<uint32> indices;
3873 for (
int32 row = inRowSliceCopy.
start; row < inRowSliceCopy.
stop; row += inRowSliceCopy.
step)
3875 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3877 const uint32 index = row * shape_.cols + col;
3878 indices.push_back(index);
3897 Slice inRowSliceCopy(inRowSlice);
3900 std::vector<uint32> indices;
3901 for (
int32 row = inRowSliceCopy.
start; row < inRowSliceCopy.
stop; row += inRowSliceCopy.
step)
3903 const uint32 index = row * shape_.cols + inColIndex;
3904 indices.push_back(index);
3922 Slice inColSliceCopy(inColSlice);
3925 std::vector<uint32> indices;
3926 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3928 const uint32 index = inRowIndex * shape_.cols + col;
3929 indices.push_back(index);
3944 if (inMask.
shape() != shape_)
3961 if (inMask.
shape() != shape_)
3995 NdArray<dtype> returnArray(shape_.rows * inNumRows, shape_.cols * inNumCols);
3997 for (
uint32 row = 0; row < inNumRows; ++row)
3999 for (
uint32 col = 0; col < inNumCols; ++col)
4001 std::vector<uint32> indices(shape_.size());
4003 const uint32 rowStart = row * shape_.rows;
4004 const uint32 colStart = col * shape_.cols;
4006 const uint32 rowEnd = (row + 1) * shape_.rows;
4007 const uint32 colEnd = (col + 1) * shape_.cols;
4010 for (
uint32 rowIdx = rowStart; rowIdx < rowEnd; ++rowIdx)
4012 for (
uint32 colIdx = colStart; colIdx < colEnd; ++colIdx)
4014 indices[counter++] = rowIdx * returnArray.shape_.
cols + colIdx;
4066 if (inSize != size_)
4068 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4074 shape_.cols = inSize;
4095 if (size_ % inNumCols == 0)
4097 return reshape(size_ / inNumCols, inNumCols);
4100 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4107 if (size_ % inNumRows == 0)
4109 return reshape(inNumRows, size_ / inNumRows);
4112 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4117 if (
static_cast<uint32>(inNumRows * inNumCols) != size_)
4119 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4124 shape_.rows =
static_cast<uint32>(inNumRows);
4125 shape_.cols =
static_cast<uint32>(inNumCols);
4158 newArray(
Shape(inNumRows, inNumCols));
4190 std::vector<dtype> oldData(size_);
4193 const Shape inShape(inNumRows, inNumCols);
4194 const Shape oldShape = shape_;
4198 for (
uint32 row = 0; row < inShape.
rows; ++row)
4200 for (
uint32 col = 0; col < inShape.
cols; ++col)
4202 if (row >= oldShape.
rows || col >= oldShape.
cols)
4204 operator()(row, col) = dtype{ 0 };
4208 operator()(row, col) = oldData[row * oldShape.
cols + col];
4247 const double multFactor =
utils::power(10.0, inNumDecimals);
4248 const auto function = [multFactor](dtype value) noexcept -> dtype
4249 {
return static_cast<dtype
>(std::nearbyint(
static_cast<double>(value) * multFactor) / multFactor); };
4307 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
4318 for (
uint32 row = 0; row < shape_.rows; ++row)
4327 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
4352 for (
uint32 row = 0; row < shape_.rows; ++row)
4355 for (
uint32 col = 0; col < shape_.cols; ++col)
4360 if (row == shape_.rows - 1)
4390 NdArray<dtype> returnArray = { std::accumulate(cbegin(), cend(), dtype{ 0 }) };
4396 for (
uint32 row = 0; row < shape_.rows; ++row)
4398 returnArray(0, row) = std::accumulate(cbegin(row), cend(row), dtype{ 0 });
4406 const Shape transShape = transposedArray.
shape();
4408 for (
uint32 row = 0; row < transShape.
rows; ++row)
4410 returnArray(0, row) =
4411 std::accumulate(transposedArray.
cbegin(row), transposedArray.
cend(row), dtype{ 0 });
4446 for (
int32 row = 0; row < static_cast<int32>(shape_.rows); ++row)
4448 std::swap(
operator()(row, colIdx1),
operator()(row, colIdx2));
4461 for (
int32 col = 0; col < static_cast<int32>(shape_.cols); ++col)
4463 std::swap(
operator()(rowIdx1, col),
operator()(rowIdx2, col));
4478 void tofile(
const std::string& inFilename)
const
4495 void tofile(
const std::string& inFilename,
const char inSep)
const
4505 std::ofstream ofile(
f.fullName().c_str());
4512 for (
auto value : *
this)
4515 if (counter++ != size_ - 1)
4559 if (numElements == 0)
4565 indices[0] = inSlice.
start;
4568 indices[i] =
static_cast<uint32>(indices[i - 1] + inSlice.
step);
4582 return std::vector<dtype>(cbegin(), cend());
4607 rowStart += inOffset;
4612 colStart += inOffset;
4623 if (rowStart >= shape_.rows || colStart >= shape_.cols)
4630 for (
uint32 row = rowStart; row < shape_.rows; ++row)
4632 if (col >= shape_.cols)
4636 sum += operator()(row, col++);
4653 for (
uint32 row = 0; row < shape_.rows; ++row)
4655 for (
uint32 col = 0; col < shape_.cols; ++col)
4657 transArray(col, row) = operator()(row, col);
4678 allocator_type allocator_{};
4679 Shape shape_{ 0, 0 };
4680 size_type size_{ 0 };
4682 pointer array_{
nullptr };
4683 bool ownsPtr_{
false };
4689 void deleteArray() noexcept
4691 if (ownsPtr_ && array_ !=
nullptr)
4693 allocator_.deallocate(array_, size_);
4697 shape_.rows = shape_.cols = 0;
4711 array_ = allocator_.allocate(size_);
4722 void newArray(
const Shape& inShape)
4727 size_ = inShape.size();
4734 template<
typename dtype,
class _Alloc>
4739 std::vector<uint32> rowIndices;
4740 std::vector<uint32> colIndices;
4742 for (
uint32 row = 0; row < shape_.rows; ++row)
4744 for (
uint32 col = 0; col < shape_.cols; ++col)
4746 if (
operator()(row, col) != dtype{ 0 })
4748 rowIndices.push_back(row);
4749 colIndices.push_back(col);
#define THROW_RUNTIME_ERROR(msg)
Definition: Error.hpp:38
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:45
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:49
#define STATIC_ASSERT_INTEGER(dtype)
Definition: StaticAsserts.hpp:40
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
Custom column iterator for NdArray.
Definition: NdArrayIterators.hpp:818
Custom column const_iterator for NdArray.
Definition: NdArrayIterators.hpp:492
Custom const_iterator for NdArray.
Definition: NdArrayIterators.hpp:42
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
uint32 numCols() const noexcept
Definition: NdArrayCore.hpp:3416
NdArray(std::vector< std::array< dtype, Dim1Size >> &in2dArray, bool copy=true)
Definition: NdArrayCore.hpp:323
const_reverse_column_iterator rcolbegin() const noexcept
Definition: NdArrayCore.hpp:1429
NdArray< dtype > at(const NdArray< int32 > &rowIndices, const NdArray< int32 > &colIndices) const
Definition: NdArrayCore.hpp:1159
NdArray< dtypeOut > astype() const
Definition: NdArrayCore.hpp:2093
NdArray< dtype > & put(int32 inIndex, value_type inValue)
Definition: NdArrayCore.hpp:3663
size_type size() const noexcept
Definition: NdArrayCore.hpp:4289
reverse_iterator rbegin() noexcept
Definition: NdArrayCore.hpp:1325
NdArray< dtype > & resizeSlow(uint32 inNumRows, uint32 inNumCols)
Definition: NdArrayCore.hpp:4188
NdArray< dtype > & put(const Slice &inRowSlice, const Slice &inColSlice, value_type inValue)
Definition: NdArrayCore.hpp:3786
NdArray< bool > issorted(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2859
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1221
NdArray< dtype > operator[](const Indices &inIndices) const
Definition: NdArrayCore.hpp:761
const_reference at(int32 inIndex) const
Definition: NdArrayCore.hpp:1016
const_column_iterator ccolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1310
NdArrayConstColumnIterator< dtype, size_type, const_pointer, difference_type > const_column_iterator
Definition: NdArrayCore.hpp:97
NdArray< dtype > round(uint8 inNumDecimals=0) const
Definition: NdArrayCore.hpp:4242
NdArray< bool > any(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1843
const_pointer data() const noexcept
Definition: NdArrayCore.hpp:2526
NdArray< uint32 > toIndices(Slice inSlice, Axis inAxis=Axis::ROW) const
Definition: NdArrayCore.hpp:4532
NdArray< dtype > at(const Slice &inRowSlice, int32 inColIndex) const
Definition: NdArrayCore.hpp:1129
iterator end() noexcept
Definition: NdArrayCore.hpp:1479
NdArray< dtype > operator()(Slice inRowSlice, int32 inColIndex) const
Definition: NdArrayCore.hpp:815
NdArray< dtype > & put(const Slice &inRowSlice, const Slice &inColSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3864
NdArray(std::vector< dtype > &inVector, bool copy=true)
Definition: NdArrayCore.hpp:263
NdArray< dtype > prod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3553
NdArray< dtype > copy() const
Definition: NdArrayCore.hpp:2382
NdArray< dtype > & resizeFast(const Shape &inShape)
Definition: NdArrayCore.hpp:4171
std::vector< dtype > toStlVector() const
Definition: NdArrayCore.hpp:4580
reference back(size_type row)
Definition: NdArrayCore.hpp:2227
iterator end(size_type inRow)
Definition: NdArrayCore.hpp:1491
NdArray< dtype > flatten() const
Definition: NdArrayCore.hpp:2751
NdArray(const std::initializer_list< std::initializer_list< dtype >> &inList)
Definition: NdArrayCore.hpp:170
void tofile(const std::string &inFilename, const char inSep) const
Definition: NdArrayCore.hpp:4495
const_column_iterator ccolbegin() const noexcept
Definition: NdArrayCore.hpp:1298
typename AllocTraits::pointer pointer
Definition: NdArrayCore.hpp:84
Slice cSlice(int32 inStartIdx=0, uint32 inStepSize=1) const noexcept
Definition: NdArrayCore.hpp:969
reverse_iterator rbegin(size_type inRow)
Definition: NdArrayCore.hpp:1337
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4276
NdArray< dtype > & byteswap() noexcept
Definition: NdArrayCore.hpp:2240
const_reverse_column_iterator rcolend() const noexcept
Definition: NdArrayCore.hpp:1737
uint32 numRows() const noexcept
Definition: NdArrayCore.hpp:3428
const dtype & const_reference
Definition: NdArrayCore.hpp:87
NdArray< dtype > & put(const Slice &inRowSlice, int32 inColIndex, value_type inValue)
Definition: NdArrayCore.hpp:3816
NdArray< dtype > & partition(uint32 inKth, Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:3472
bool issquare() const noexcept
Definition: NdArrayCore.hpp:2908
NdArrayIterator< dtype, pointer, difference_type > iterator
Definition: NdArrayCore.hpp:91
bool isflat() const noexcept
Definition: NdArrayCore.hpp:2847
Endian endianess() const noexcept
Definition: NdArrayCore.hpp:2696
void tofile(const std::string &inFilename) const
Definition: NdArrayCore.hpp:4478
const_reverse_column_iterator crcolbegin() const noexcept
Definition: NdArrayCore.hpp:1452
const_reverse_column_iterator crcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1772
column_iterator colbegin(size_type inCol)
Definition: NdArrayCore.hpp:1260
NdArrayColumnIterator< dtype, size_type, pointer, difference_type > column_iterator
Definition: NdArrayCore.hpp:96
NdArray< bool > none(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3354
NdArray< dtype > at(const Slice &inSlice) const
Definition: NdArrayCore.hpp:1099
reference at(int32 inIndex)
Definition: NdArrayCore.hpp:995
NdArray< dtype > & sort(Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:4303
pointer data() noexcept
Definition: NdArrayCore.hpp:2516
bool isempty() const noexcept
Definition: NdArrayCore.hpp:2835
column_iterator colbegin() noexcept
Definition: NdArrayCore.hpp:1248
const_reference front(size_type row) const
Definition: NdArrayCore.hpp:2786
reverse_column_iterator rcolend(size_type inCol)
Definition: NdArrayCore.hpp:1722
NdArray< dtype > sum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:4382
NdArray(Iterator inFirst, Iterator inLast)
Definition: NdArrayCore.hpp:419
NdArray< dtype > operator[](const Slice &inSlice) const
Definition: NdArrayCore.hpp:713
reverse_column_iterator rcolbegin() noexcept
Definition: NdArrayCore.hpp:1402
NdArrayConstIterator< dtype, const_pointer, difference_type > const_iterator
Definition: NdArrayCore.hpp:92
const_iterator cbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1233
const_column_iterator ccolend(size_type inCol) const
Definition: NdArrayCore.hpp:1695
NdArray< dtype > cumsum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2458
NdArray< dtype > median(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3048
NdArray< dtype > getByMask(const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:2823
const_iterator cend(size_type inRow) const
Definition: NdArrayCore.hpp:1541
NdArray< dtype > column(uint32 inColumn)
Definition: NdArrayCore.hpp:2319
const_reverse_column_iterator rcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1749
NdArray< dtype > & putMask(const NdArray< bool > &inMask, value_type inValue)
Definition: NdArrayCore.hpp:3942
const_iterator end(size_type inRow) const
Definition: NdArrayCore.hpp:1518
reference back() noexcept
Definition: NdArrayCore.hpp:2205
const_reverse_column_iterator crcolend() const noexcept
Definition: NdArrayCore.hpp:1760
const_reference back(size_type row) const
Definition: NdArrayCore.hpp:2216
reverse_column_iterator rcolbegin(size_type inCol)
Definition: NdArrayCore.hpp:1414
NdArray(const std::deque< std::deque< dtype >> &in2dDeque)
Definition: NdArrayCore.hpp:367
NdArray< dtype > & put(int32 inRow, int32 inCol, value_type inValue)
Definition: NdArrayCore.hpp:3680
iterator begin(size_type inRow)
Definition: NdArrayCore.hpp:1183
const_reverse_iterator rend() const noexcept
Definition: NdArrayCore.hpp:1583
NdArray< dtype > clip(value_type inMin, value_type inMax) const
Definition: NdArrayCore.hpp:2280
const_reverse_column_iterator rcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1441
NdArray< dtype > & operator=(NdArray< dtype > &&rhs) noexcept
Definition: NdArrayCore.hpp:606
typename AllocTraits::difference_type difference_type
Definition: NdArrayCore.hpp:89
NdArray< uint32 > argmin(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1954
const_iterator end() const noexcept
Definition: NdArrayCore.hpp:1506
bool ownsInternalData() noexcept
Definition: NdArrayCore.hpp:3452
NdArray< dtype > & fill(value_type inFillValue) noexcept
Definition: NdArrayCore.hpp:2712
column_iterator colend() noexcept
Definition: NdArrayCore.hpp:1633
NdArray(std::initializer_list< dtype > inList)
Definition: NdArrayCore.hpp:153
NdArray< dtype > operator()(Slice inRowSlice, Slice inColSlice) const
Definition: NdArrayCore.hpp:787
NdArray< dtype > & put(const NdArray< uint32 > &inIndices, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3715
const_reference back() const noexcept
Definition: NdArrayCore.hpp:2194
NdArray< dtype > operator()(int32 inRowIndex, Slice inColSlice) const
Definition: NdArrayCore.hpp:837
std::pair< NdArray< uint32 >, NdArray< uint32 > > nonzero() const
Definition: NdArrayCore.hpp:4735
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: NdArrayCore.hpp:94
NdArray(const_pointer inPtr, UIntType1 numRows, UIntType2 numCols)
Definition: NdArrayCore.hpp:462
NdArray< dtype > cumprod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2396
uint64 nbytes() const noexcept
Definition: NdArrayCore.hpp:3176
const_reference at(int32 inRowIndex, int32 inColIndex) const
Definition: NdArrayCore.hpp:1069
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4650
NdArray< dtype > swapaxes() const
Definition: NdArrayCore.hpp:4432
NdArray< dtype > & put(int32 inRowIndex, const Slice &inColSlice, value_type inValue)
Definition: NdArrayCore.hpp:3840
NdArray(const std::list< dtype > &inList)
Definition: NdArrayCore.hpp:399
NdArray< dtype > at(int32 inRowIndex, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1144
const_reference front() const noexcept
Definition: NdArrayCore.hpp:2764
NdArray< dtype > repeat(const Shape &inRepeatShape) const
Definition: NdArrayCore.hpp:4034
~NdArray() noexcept
Definition: NdArrayCore.hpp:553
NdArray< dtype > min(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2993
NdArray< dtype > & reshape(const Shape &inShape)
Definition: NdArrayCore.hpp:4141
reference front() noexcept
Definition: NdArrayCore.hpp:2775
NdArray(size_type inNumRows, size_type inNumCols)
Definition: NdArrayCore.hpp:127
Allocator allocator_type
Definition: NdArrayCore.hpp:83
void print() const
Definition: NdArrayCore.hpp:3537
void swapCols(int32 colIdx1, int32 colIdx2) noexcept
Definition: NdArrayCore.hpp:4444
const_reverse_column_iterator crcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1464
reverse_iterator rend(size_type inRow)
Definition: NdArrayCore.hpp:1568
NdArray< uint32 > flatnonzero() const
Definition: NdArrayCore.hpp:2725
NdArray(size_type inSquareSize)
Definition: NdArrayCore.hpp:113
NdArray< dtype > operator()(int32 rowIndex, const Indices &colIndices) const
Definition: NdArrayCore.hpp:894
reverse_iterator rend() noexcept
Definition: NdArrayCore.hpp:1556
const_reverse_iterator rend(size_type inRow) const
Definition: NdArrayCore.hpp:1595
NdArray< dtype > getByIndices(const NdArray< uint32 > &inIndices) const
Definition: NdArrayCore.hpp:2809
typename AllocTraits::const_pointer const_pointer
Definition: NdArrayCore.hpp:85
NdArray< dtype > & resizeSlow(const Shape &inShape)
Definition: NdArrayCore.hpp:4227
const_reverse_iterator crbegin() const noexcept
Definition: NdArrayCore.hpp:1375
const_column_iterator colend(size_type inCol) const
Definition: NdArrayCore.hpp:1672
std::reverse_iterator< iterator > reverse_iterator
Definition: NdArrayCore.hpp:93
NdArray< dtype > operator()(const Indices &rowIndices, Slice colSlice) const
Definition: NdArrayCore.hpp:878
NdArray(const std::vector< std::vector< dtype >> &in2dVector)
Definition: NdArrayCore.hpp:288
const_reverse_iterator rbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1364
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1529
std::string str() const
Definition: NdArrayCore.hpp:4346
std::reverse_iterator< const_column_iterator > const_reverse_column_iterator
Definition: NdArrayCore.hpp:99
reference operator[](int32 inIndex) noexcept
Definition: NdArrayCore.hpp:632
NdArray< dtype > & reshape(int32 inNumRows, int32 inNumCols)
Definition: NdArrayCore.hpp:4091
NdArray(NdArray< dtype > &&inOtherArray) noexcept
Definition: NdArrayCore.hpp:536
NdArray< dtype > & nans() noexcept
Definition: NdArrayCore.hpp:3160
NdArray< dtype > & put(const NdArray< uint32 > &inIndices, value_type inValue)
Definition: NdArrayCore.hpp:3696
NdArray< dtype > ptp(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3607
const_reference operator()(int32 inRowIndex, int32 inColIndex) const noexcept
Definition: NdArrayCore.hpp:690
reference front(size_type row)
Definition: NdArrayCore.hpp:2797
NdArray< dtype > diagonal(int32 inOffset=0, Axis inAxis=Axis::ROW) const
Definition: NdArrayCore.hpp:2555
NdArray(pointer inPtr, uint32 numRows, uint32 numCols, BoolType takeOwnership) noexcept
Definition: NdArrayCore.hpp:504
NdArray< dtype > & putMask(const NdArray< bool > &inMask, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3959
NdArray< dtype > operator[](const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:734
NdArray< dtype > row(uint32 inRow)
Definition: NdArrayCore.hpp:4263
NdArray< dtype > operator()(const Indices &rowIndices, int32 colIndex) const
Definition: NdArrayCore.hpp:861
const_iterator begin(size_type inRow) const
Definition: NdArrayCore.hpp:1210
iterator begin() noexcept
Definition: NdArrayCore.hpp:1171
NdArray< dtype > & put(const Slice &inSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3762
const_column_iterator colbegin() const noexcept
Definition: NdArrayCore.hpp:1275
NdArray< dtype > max(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2940
std::reverse_iterator< column_iterator > reverse_column_iterator
Definition: NdArrayCore.hpp:98
void swapRows(int32 rowIdx1, int32 rowIdx2) noexcept
Definition: NdArrayCore.hpp:4459
NdArray< dtype > & operator=(const NdArray< dtype > &rhs)
Definition: NdArrayCore.hpp:565
value_type item() const
Definition: NdArrayCore.hpp:2921
reference operator()(int32 inRowIndex, int32 inColIndex) noexcept
Definition: NdArrayCore.hpp:667
const_column_iterator colend() const noexcept
Definition: NdArrayCore.hpp:1660
NdArray< dtype > & resizeFast(uint32 inNumRows, uint32 inNumCols)
Definition: NdArrayCore.hpp:4156
const_reverse_iterator crend() const noexcept
Definition: NdArrayCore.hpp:1606
NdArray< dtype > & ones() noexcept
Definition: NdArrayCore.hpp:3438
NdArray< dtype > operator()(RowIndices rowIndices, ColIndices colIndices) const
Definition: NdArrayCore.hpp:929
NdArray< dtype > & zeros() noexcept
Definition: NdArrayCore.hpp:4668
const_column_iterator colbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1287
NdArray< dtype > dot(const NdArray< dtype > &inOtherArray) const
Definition: NdArrayCore.hpp:2623
NdArray< dtype > repeat(uint32 inNumRows, uint32 inNumCols) const
Definition: NdArrayCore.hpp:3993
NdArray< dtype > & reshape(size_type inSize)
Definition: NdArrayCore.hpp:4064
NdArray< bool > contains(value_type inValue, Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2332
const_column_iterator ccolend() const noexcept
Definition: NdArrayCore.hpp:1683
NdArray< uint32 > argmax(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1896
value_type trace(uint32 inOffset=0, Axis inAxis=Axis::ROW) const noexcept
Definition: NdArrayCore.hpp:4597
reverse_column_iterator rcolend() noexcept
Definition: NdArrayCore.hpp:1710
NdArray(std::array< dtype, ArraySize > &inArray, bool copy=true)
Definition: NdArrayCore.hpp:206
NdArray< dtype > & put(int32 inRowIndex, const Slice &inColSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3920
const_reverse_iterator rbegin() const noexcept
Definition: NdArrayCore.hpp:1352
NdArray(const_pointer inPtr, size_type size)
Definition: NdArrayCore.hpp:438
NdArray(const std::deque< dtype > &inDeque)
Definition: NdArrayCore.hpp:350
NdArray(std::array< std::array< dtype, Dim1Size >, Dim0Size > &in2dArray, bool copy=true)
Definition: NdArrayCore.hpp:234
void dump(const std::string &inFilename) const
Definition: NdArrayCore.hpp:2669
dtype & reference
Definition: NdArrayCore.hpp:86
pointer dataRelease() noexcept
Definition: NdArrayCore.hpp:2538
reference at(int32 inRowIndex, int32 inColIndex)
Definition: NdArrayCore.hpp:1038
NdArray< dtype > at(const Slice &inRowSlice, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1114
NdArray< dtype > operator()(Slice rowSlice, const Indices &colIndices) const
Definition: NdArrayCore.hpp:911
NdArray(const NdArray< dtype > &inOtherArray)
Definition: NdArrayCore.hpp:518
NdArray< uint32 > argsort(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2011
uint32 size_type
Definition: NdArrayCore.hpp:88
const_iterator begin() const noexcept
Definition: NdArrayCore.hpp:1198
NdArray< dtype > & operator=(value_type inValue) noexcept
Definition: NdArrayCore.hpp:589
NdArray< dtype > newbyteorder(Endian inEndianess) const
Definition: NdArrayCore.hpp:3191
column_iterator colend(size_type inCol)
Definition: NdArrayCore.hpp:1645
NdArray< dtype > & put(const Slice &inSlice, value_type inValue)
Definition: NdArrayCore.hpp:3740
const_reference operator[](int32 inIndex) const noexcept
Definition: NdArrayCore.hpp:649
NdArray< dtype > & ravel() noexcept
Definition: NdArrayCore.hpp:3977
dtype value_type
Definition: NdArrayCore.hpp:82
void replace(value_type oldValue, value_type newValue)
Definition: NdArrayCore.hpp:4046
NdArray< dtype > & put(const Slice &inRowSlice, int32 inColIndex, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3895
Slice rSlice(int32 inStartIdx=0, uint32 inStepSize=1) const noexcept
Definition: NdArrayCore.hpp:983
const_reverse_iterator crend(size_type inRow) const
Definition: NdArrayCore.hpp:1618
const_reverse_iterator crbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1387
NdArray(pointer inPtr, size_type size, BoolType takeOwnership) noexcept
Definition: NdArrayCore.hpp:484
NdArray(const Shape &inShape)
Definition: NdArrayCore.hpp:140
NdArray< bool > all(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1791
Custom iterator for NdArray.
Definition: NdArrayIterators.hpp:318
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
uint32 rows
Definition: Core/Shape.hpp:44
uint32 cols
Definition: Core/Shape.hpp:45
uint32 size() const noexcept
Definition: Core/Shape.hpp:104
A Class for slicing into NdArrays.
Definition: Slice.hpp:44
int32 step
Definition: Slice.hpp:49
int32 start
Definition: Slice.hpp:47
void makePositiveAndValidate(uint32 inArraySize)
Definition: Slice.hpp:141
uint32 numElements(uint32 inArraySize)
Definition: Slice.hpp:194
int32 stop
Definition: Slice.hpp:48
Provides simple filesystem functions.
Definition: Filesystem.hpp:40
constexpr auto j
Definition: Constants.hpp:45
const double nan
NaN.
Definition: Constants.hpp:44
bool isLittleEndian() noexcept
Definition: Endian.hpp:44
dtype byteSwap(dtype value) noexcept
Definition: Endian.hpp:63
dtype f(GeneratorType &generator, dtype inDofN, dtype inDofD)
Definition: f.hpp:58
bool any_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:78
void sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:705
bool none_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:408
ForwardIt max_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:287
void stable_sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:743
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:784
bool all_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:57
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:227
InputIt find(InputIt first, InputIt last, const T &value) noexcept
Definition: StlAlgorithms.hpp:207
constexpr OutputIt unique_copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:835
std::pair< ForwardIt, ForwardIt > minmax_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:366
void replace(ForwardIt first, ForwardIt last, const T &oldValue, const T &newValue) noexcept
Definition: StlAlgorithms.hpp:471
bool is_sorted(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:247
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:99
void nth_element(RandomIt first, RandomIt nth, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:428
ForwardIt min_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:326
void fill(ForwardIt first, ForwardIt last, const T &value) noexcept
Definition: StlAlgorithms.hpp:185
std::string num2str(dtype inNumber)
Definition: num2str.hpp:46
dtype power(dtype inValue, uint8 inPower) noexcept
Definition: Utils/power.hpp:48
std::string value2str(dtype inValue)
Definition: value2str.hpp:48
Definition: Coordinate.hpp:45
NdArray< dtype > repeat(const NdArray< dtype > &inArray, uint32 inNumRows, uint32 inNumCols)
Definition: repeat.hpp:49
void swap(NdArray< dtype > &inArray1, NdArray< dtype > &inArray2) noexcept
Definition: swap.hpp:42
std::pair< NdArray< uint32 >, NdArray< uint32 > > nonzero(const NdArray< dtype > &inArray)
Definition: nonzero.hpp:48
NdArray< dtype > & resizeFast(NdArray< dtype > &inArray, uint32 inNumRows, uint32 inNumCols)
Definition: resizeFast.hpp:50
Axis
Enum To describe an axis.
Definition: Types.hpp:47
NdArray< dtype > & reshape(NdArray< dtype > &inArray, uint32 inSize)
Definition: reshape.hpp:51
std::int64_t int64
Definition: Types.hpp:35
auto abs(dtype inValue) noexcept
Definition: abs.hpp:49
std::uint64_t uint64
Definition: Types.hpp:39
NdArray< dtype > & resizeSlow(NdArray< dtype > &inArray, uint32 inNumRows, uint32 inNumCols)
Definition: resizeSlow.hpp:52
Endian
Enum for endianess.
Definition: Types.hpp:56
std::int32_t int32
Definition: Types.hpp:36
std::uint8_t uint8
Definition: Types.hpp:42
NdArray< dtype > sum(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: sum.hpp:46
NdArray< dtype > & put(NdArray< dtype > &inArray, const NdArray< uint32 > &inIndices, dtype inValue)
Definition: put.hpp:48
NdArray< dtype > transpose(const NdArray< dtype > &inArray)
Definition: transpose.hpp:45
typename std::enable_if< B, T >::type enable_if_t
Definition: TypeTraits.hpp:40
std::uint32_t uint32
Definition: Types.hpp:40
void dump(const NdArray< dtype > &inArray, const std::string &inFilename)
Definition: dump.hpp:46