51 #include <forward_list>
53 #include <initializer_list>
61 #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>,
"value_type and Allocator::value_type must match");
77 using AllocType =
typename std::allocator_traits<Allocator>::template rebind_alloc<dtype>;
78 using AllocTraits = std::allocator_traits<AllocType>;
83 using pointer =
typename AllocTraits::pointer;
113 shape_(inSquareSize, inSquareSize),
114 size_(inSquareSize * inSquareSize)
127 shape_(inNumRows, inNumCols),
128 size_(inNumRows * inNumCols)
152 NdArray(std::initializer_list<dtype> inList) :
153 shape_(1, static_cast<
uint32>(inList.
size())),
169 NdArray(
const std::initializer_list<std::initializer_list<dtype> >& inList) :
172 for (
const auto& list : inList)
174 if (shape_.
cols == 0)
176 shape_.
cols =
static_cast<uint32>(list.size());
178 else if (list.size() != shape_.
cols)
184 size_ = shape_.
size();
187 for (
const auto& list : inList)
203 template<
size_t ArraySize,
204 std::enable_if_t<is_valid_dtype_v<dtype>,
int> = 0>
205 NdArray(std::array<dtype, ArraySize>& inArray,
bool copy =
true) :
206 shape_(1, static_cast<
uint32>(ArraySize)),
219 array_ = inArray.data();
232 template<
size_t Dim0Size,
size_t Dim1Size>
233 NdArray(std::array<std::array<dtype, Dim1Size>, Dim0Size>& in2dArray,
bool copy =
true) :
234 shape_(static_cast<
uint32>(Dim0Size), static_cast<
uint32>(Dim1Size)),
242 const auto start = in2dArray.front().begin();
248 array_ = in2dArray.front().data();
261 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
263 shape_(1, static_cast<
uint32>(inVector.
size())),
276 array_ = inVector.data();
287 explicit NdArray(
const std::vector<std::vector<dtype>>& in2dVector) :
288 shape_(static_cast<
uint32>(in2dVector.
size()), 0)
290 for (
const auto&
row : in2dVector)
292 if (shape_.
cols == 0)
296 else if (
row.size() != shape_.
cols)
302 size_ = shape_.
size();
305 auto currentPosition =
begin();
306 for (
const auto&
row : in2dVector)
309 currentPosition += shape_.
cols;
321 template<
size_t Dim1Size>
322 NdArray(std::vector<std::array<dtype, Dim1Size>>& in2dArray,
bool copy =
true) :
323 shape_(static_cast<
uint32>(in2dArray.
size()), static_cast<
uint32>(Dim1Size)),
331 const auto start = in2dArray.front().begin();
337 array_ = in2dArray.front().data();
348 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
349 explicit NdArray(
const std::deque<dtype>& inDeque) :
350 shape_(1, static_cast<
uint32>(inDeque.
size())),
366 explicit NdArray(
const std::deque<std::deque<dtype>>& in2dDeque) :
367 shape_(static_cast<
uint32>(in2dDeque.
size()), 0)
369 for (
const auto&
row : in2dDeque)
371 if (shape_.
cols == 0)
375 else if (
row.size() != shape_.
cols)
381 size_ = shape_.
size();
384 auto currentPosition =
begin();
385 for (
const auto&
row : in2dDeque)
388 currentPosition += shape_.
cols;
398 explicit NdArray(
const std::list<dtype>& inList) :
399 shape_(1, static_cast<
uint32>(inList.
size())),
416 template<
typename Iterator,
417 std::enable_if_t<is_same_v<typename std::iterator_traits<Iterator>::value_type, dtype>,
int> = 0>
419 shape_(1, static_cast<
uint32>(std::distance(inFirst, inLast))),
442 if (inPtr !=
nullptr && size_ > 0)
457 template<
typename UIntType1,
typename UIntType2,
458 std::enable_if_t<!is_same_v<UIntType1, bool>,
int> = 0,
459 std::enable_if_t<!is_same_v<UIntType2, bool>,
int> = 0>
465 if (inPtr !=
nullptr && size_ > 0)
481 template<
typename Bool,
482 std::enable_if_t<is_same_v<Bool, bool>,
int> = 0>
487 ownsPtr_(takeOwnership)
501 template<
typename Bool,
502 std::enable_if_t<is_same_v<Bool, bool>,
int> = 0>
507 ownsPtr_(takeOwnership)
517 shape_(inOtherArray.shape_),
518 size_(inOtherArray.size_),
519 endianess_(inOtherArray.endianess_)
535 shape_(inOtherArray.shape_),
536 size_(inOtherArray.size_),
537 endianess_(inOtherArray.endianess_),
538 array_(inOtherArray.array_),
539 ownsPtr_(inOtherArray.ownsPtr_)
541 inOtherArray.shape_.rows = inOtherArray.shape_.cols = 0;
542 inOtherArray.size_ = 0;
543 inOtherArray.ownsPtr_ =
false;
544 inOtherArray.array_ =
nullptr;
569 newArray(rhs.shape_);
570 endianess_ = rhs.endianess_;
589 if (array_ !=
nullptr)
611 endianess_ = rhs.endianess_;
613 ownsPtr_ = rhs.ownsPtr_;
615 rhs.shape_.rows = rhs.shape_.cols = rhs.size_ = 0;
616 rhs.array_ =
nullptr;
617 rhs.ownsPtr_ =
false;
637 return array_[inIndex];
654 return array_[inIndex];
669 inRowIndex += shape_.
rows;
674 inColIndex += shape_.
cols;
677 return array_[inRowIndex * shape_.
cols + inColIndex];
692 inRowIndex += shape_.
rows;
697 inColIndex += shape_.
cols;
700 return array_[inRowIndex * shape_.
cols + inColIndex];
713 Slice inSliceCopy(inSlice);
719 returnArray[counter++] =
at(i);
734 if (inMask.
shape() != shape_)
741 for (
size_type i = 0; i < indices.size(); ++i)
757 template<
typename Indices,
761 if (inIndices.max().item() > size_ - 1)
768 for (
auto& index : inIndices)
795 returnArray(rowCounter, colCounter++) =
at(
row, col);
820 returnArray(rowCounter++, 0) =
at(
row, inColIndex);
842 returnArray(0, colCounter++) =
at(inRowIndex, col);
857 template<
typename Indices,
874 template<
typename Indices,
890 template<
typename Indices,
907 template<
typename Indices,
923 template<
typename RowIndices,
typename ColIndices,
931 std::vector<int32> rowIndicesUnique(rowIndices.size());
932 std::vector<int32> colIndicesUnique(colIndices.size());
938 static_cast<uint32>(lastCol - colIndicesUnique.begin()));
941 for (
auto rowIter = rowIndicesUnique.begin(); rowIter != lastRow; ++rowIter)
944 for (
auto colIter = colIndicesUnique.begin(); colIter != lastCol; ++colIter)
946 returnArray(rowCounter, colCounter++) =
at(*rowIter, *colIter);
966 return Slice(inStartIdx, shape_.
cols, inStepSize);
980 return Slice(inStartIdx, shape_.
rows, inStepSize);
997 errStr +=
" is out of bounds for array of size " +
utils::num2str(size_) +
".";
1018 errStr +=
" is out of bounds for array of size " +
utils::num2str(size_) +
".";
1040 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
rows) +
".";
1048 std::string errStr =
"Column index " +
utils::num2str(inColIndex);
1049 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
cols) +
".";
1071 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
rows) +
".";
1079 std::string errStr =
"Column index " +
utils::num2str(inColIndex);
1080 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
cols) +
".";
1180 if (inRow >= shape_.
rows)
1185 return begin() += (inRow * shape_.
cols);
1230 if (inRow >= shape_.
rows)
1257 if (inCol >= shape_.
cols)
1307 if (inCol >= shape_.
cols)
1334 if (inRow >= shape_.
rows)
1384 if (inRow >= shape_.
rows)
1411 if (inCol >= shape_.
cols)
1461 if (inCol >= shape_.
cols)
1476 return begin() += size_;
1488 if (inRow >= shape_.
rows)
1526 return cbegin() += size_;
1538 if (inRow >= shape_.
rows)
1553 return rbegin() += size_;
1565 if (inRow >= shape_.
rows)
1592 return crend(inRow);
1615 if (inRow >= shape_.
rows)
1642 if (inCol >= shape_.
cols)
1692 if (inCol >= shape_.
cols)
1719 if (inCol >= shape_.
cols)
1769 if (inCol >= shape_.
cols)
1790 const auto function = [](dtype i) ->
bool
1792 return i != dtype{ 0 };
1844 const auto function = [](dtype i) ->
bool
1846 return i != dtype{ 0 };
1899 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
1957 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
2018 std::vector<uint32> idx(size_);
2019 std::iota(idx.begin(), idx.end(), 0);
2021 const auto function = [
this](
uint32 i1,
uint32 i2) noexcept ->
bool
2023 return (*
this)[i1] < (*this)[i2];
2032 std::vector<uint32> idx(shape_.
cols);
2036 std::iota(idx.begin(), idx.end(), 0);
2038 const auto function = [
this,
row](
uint32 i1,
uint32 i2) noexcept ->
bool
2045 for (
uint32 col = 0; col < shape_.
cols; ++col)
2047 returnArray(
row, col) = idx[col];
2056 std::vector<uint32> idx(arrayTransposed.shape_.
cols);
2060 std::iota(idx.begin(), idx.end(), 0);
2062 const auto function = [&arrayTransposed,
row](
uint32 i1,
uint32 i2) noexcept ->
bool
2064 return arrayTransposed(
row, i1) < arrayTransposed(
row, i2);
2069 for (
uint32 col = 0; col < arrayTransposed.shape_.
cols; ++col)
2071 returnArray(
row, col) = idx[col];
2093 template<
typename dtypeOut,
typename dtype_ = dtype,
2101 [](dtype value) -> dtypeOut
2103 return static_cast<dtypeOut>(value);
2119 template<
typename dtypeOut,
typename dtype_ = dtype,
2129 return std::complex<typename dtypeOut::value_type>(value);
2146 template<
typename dtypeOut,
typename dtype_ = dtype,
2154 if (is_same_v<dtypeOut, dtype>)
2162 return complex_cast<typename dtypeOut::value_type>(value);
2180 template<
typename dtypeOut,
typename dtype_ = dtype,
2190 return static_cast<dtypeOut
>(value.real());
2206 return *(
cend() - 1);
2217 return *(
end() - 1);
2255 [](dtype& value) noexcept ->
void
2299 [inMin, inMax](dtype value) noexcept -> dtype
2301 #ifdef __cpp_lib_clamp
2302 const auto comparitor = [](dtype lhs, dtype rhs) noexcept -> bool
2307 return std::clamp(value, inMin, inMax, comparitor);
2313 else if (value > inMax)
2334 return operator()(rSlice(), inColumn);
2359 for (
uint32 row = 0; row < shape_.rows; ++row)
2370 for (
uint32 row = 0; row < transArray.shape_.
rows; ++row)
2416 returnArray[0] = front();
2417 for (
uint32 i = 1; i < size_; ++i)
2419 returnArray[i] = returnArray[i - 1] * array_[i];
2427 for (
uint32 row = 0; row < shape_.rows; ++row)
2429 returnArray(row, 0) = operator()(row, 0);
2430 for (
uint32 col = 1; col < shape_.cols; ++col)
2432 returnArray(row, col) = returnArray(row, col - 1) * operator()(row, col);
2441 for (
uint32 col = 0; col < shape_.cols; ++col)
2443 returnArray(0, col) = operator()(0, col);
2444 for (
uint32 row = 1; row < shape_.rows; ++row)
2446 returnArray(row, col) = returnArray(row - 1, col) * operator()(row, col);
2478 returnArray[0] = front();
2479 for (
uint32 i = 1; i < size_; ++i)
2481 returnArray[i] = returnArray[i - 1] + array_[i];
2489 for (
uint32 row = 0; row < shape_.rows; ++row)
2491 returnArray(row, 0) = operator()(row, 0);
2492 for (
uint32 col = 1; col < shape_.cols; ++col)
2494 returnArray(row, col) = returnArray(row, col - 1) + operator()(row, col);
2503 for (
uint32 col = 0; col < shape_.cols; ++col)
2505 returnArray(0, col) = operator()(0, col);
2506 for (
uint32 row = 1; row < shape_.rows; ++row)
2508 returnArray(row, col) = returnArray(row - 1, col) + operator()(row, col);
2571 std::vector<dtype> diagnolValues;
2572 int32 col = inOffset;
2573 for (
uint32 row = 0; row < shape_.rows; ++row)
2580 if (col >=
static_cast<int32>(shape_.cols))
2585 diagnolValues.push_back(
operator()(row,
static_cast<uint32>(col)));
2593 std::vector<dtype> diagnolValues;
2595 for (
int32 row = inOffset; row < static_cast<int32>(shape_.rows); ++row)
2602 if (col >= shape_.cols)
2607 diagnolValues.push_back(
operator()(
static_cast<uint32>(row), col));
2637 if (shape_ == inOtherArray.shape_ && (shape_.rows == 1 || shape_.cols == 1))
2639 dtype dotProduct = std::inner_product(cbegin(), cend(), inOtherArray.
cbegin(), dtype{ 0 });
2643 if (shape_.cols == inOtherArray.shape_.
rows)
2647 auto otherArrayT = inOtherArray.
transpose();
2649 for (
uint32 i = 0; i < shape_.rows; ++i)
2651 for (
uint32 j = 0;
j < otherArrayT.shape_.rows; ++
j)
2653 returnArray(i,
j) = std::inner_product(otherArrayT.cbegin(
j), otherArrayT.cend(
j), cbegin(i), dtype{ 0 });
2662 errStr +=
" are not consistent.";
2677 void dump(
const std::string& inFilename)
const
2685 std::ofstream ofile(
f.fullName().c_str(), std::ios::binary);
2691 if (array_ !=
nullptr)
2693 ofile.write(
reinterpret_cast<const char*
>(array_), size_ *
sizeof(dtype));
2737 std::vector<uint32> indices;
2739 for (
auto value : *
this)
2741 if (value != dtype{ 0 })
2743 indices.push_back(idx);
2796 return *cbegin(row);
2819 return operator[](inIndices);
2833 return operator[](inMask);
2857 return shape_.rows == 1 || shape_.cols == 1;
2871 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
2886 for (
uint32 row = 0; row < transposedArray.shape_.rows; ++row)
2889 transposedArray.cend(row), comparitor);
2897 for (
uint32 row = 0; row < shape_.rows; ++row)
2920 return shape_.issquare();
2954 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
2969 for (
uint32 row = 0; row < shape_.rows; ++row)
2980 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
2983 transposedArray.
cend(row), comparitor);
3009 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3024 for (
uint32 row = 0; row < shape_.rows; ++row)
3035 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3038 transposedArray.
cend(row), comparitor);
3066 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3082 const uint32 middleIdx = size_ / 2;
3085 dtype medianValue = copyArray.array_[middleIdx];
3088 const uint32 lhsIndex = middleIdx - 1;
3090 medianValue = (medianValue + copyArray.array_[lhsIndex]) / dtype{2};
3093 return { medianValue };
3100 const bool isEven = shape_.cols % 2 == 0;
3101 for (
uint32 row = 0; row < shape_.rows; ++row)
3103 const uint32 middleIdx = shape_.cols / 2;
3105 copyArray.
end(row), comparitor);
3107 dtype medianValue = copyArray(row, middleIdx);
3110 const uint32 lhsIndex = middleIdx - 1;
3112 copyArray.
end(row), comparitor);
3113 medianValue = (medianValue + copyArray(row, lhsIndex)) / dtype{2};
3116 returnArray(0, row) = medianValue;
3126 const bool isEven = shape_.rows % 2 == 0;
3127 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3129 const uint32 middleIdx = transposedArray.shape_.
cols / 2;
3131 transposedArray.
end(row), comparitor);
3133 dtype medianValue = transposedArray(row, middleIdx);
3136 const uint32 lhsIndex = middleIdx - 1;
3138 transposedArray.
end(row), comparitor);
3139 medianValue = (medianValue + transposedArray(row, lhsIndex)) / dtype{2};
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
3360 return i != dtype{ 0 };
3373 for (
uint32 row = 0; row < shape_.rows; ++row)
3384 for (
uint32 row = 0; row < arrayTransposed.shape_.
rows; ++row)
3478 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3499 if (inKth >= shape_.cols)
3502 errStr +=
") out of bounds (" +
utils::num2str(shape_.cols) +
")";
3506 for (
uint32 row = 0; row < shape_.rows; ++row)
3514 if (inKth >= shape_.rows)
3517 errStr +=
") out of bounds (" +
utils::num2str(shape_.rows) +
")";
3522 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3525 transposedArray.
end(row), comparitor);
3564 dtype product = std::accumulate(cbegin(), cend(),
3565 dtype{ 1 }, std::multiplies<dtype>());
3572 for (
uint32 row = 0; row < shape_.rows; ++row)
3574 returnArray(0, row) = std::accumulate(cbegin(row), cend(row),
3575 dtype{ 1 }, std::multiplies<dtype>());
3584 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3586 returnArray(0, row) = std::accumulate(transposedArray.
cbegin(row), transposedArray.
cend(row),
3587 dtype{ 1 }, std::multiplies<dtype>());
3613 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3629 for (
uint32 row = 0; row < shape_.rows; ++row)
3632 returnArray(0, row) = *result.second - *result.first;
3641 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3644 returnArray(0, row) = *result.second - *result.first;
3668 at(inIndex) = inValue;
3685 at(inRow, inCol) = inValue;
3701 for (
auto index : inIndices)
3703 put(index, inValue);
3720 if (inIndices.
size() != inValues.
size())
3726 for (
auto index : inIndices)
3728 put(index, inValues[counter++]);
3745 Slice inSliceCopy(inSlice);
3767 Slice inSliceCopy(inSlice);
3770 std::vector<uint32> indices;
3773 indices.push_back(i);
3791 Slice inRowSliceCopy(inRowSlice);
3792 Slice inColSliceCopy(inColSlice);
3797 std::vector<uint32> indices;
3798 for (
int32 row = inRowSliceCopy.
start; row < inRowSliceCopy.
stop; row += inRowSliceCopy.
step)
3800 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3802 put(row, col, inValue);
3821 Slice inRowSliceCopy(inRowSlice);
3824 std::vector<uint32> indices;
3825 for (
int32 row = inRowSliceCopy.
start; row < inRowSliceCopy.
stop; row += inRowSliceCopy.
step)
3827 put(row, inColIndex, inValue);
3845 Slice inColSliceCopy(inColSlice);
3848 std::vector<uint32> indices;
3849 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3851 put(inRowIndex, col, inValue);
3869 Slice inRowSliceCopy(inRowSlice);
3870 Slice inColSliceCopy(inColSlice);
3875 std::vector<uint32> indices;
3876 for (
int32 row = inRowSliceCopy.
start; row < inRowSliceCopy.
stop; row += inRowSliceCopy.
step)
3878 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3880 const uint32 index = row * shape_.cols + col;
3881 indices.push_back(index);
3900 Slice inRowSliceCopy(inRowSlice);
3903 std::vector<uint32> indices;
3904 for (
int32 row = inRowSliceCopy.
start; row < inRowSliceCopy.
stop; row += inRowSliceCopy.
step)
3906 const uint32 index = row * shape_.cols + inColIndex;
3907 indices.push_back(index);
3925 Slice inColSliceCopy(inColSlice);
3928 std::vector<uint32> indices;
3929 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3931 const uint32 index = inRowIndex * shape_.cols + col;
3932 indices.push_back(index);
3947 if (inMask.
shape() != shape_)
3964 if (inMask.
shape() != shape_)
3998 NdArray<dtype> returnArray(shape_.rows * inNumRows, shape_.cols * inNumCols);
4000 for (
uint32 row = 0; row < inNumRows; ++row)
4002 for (
uint32 col = 0; col < inNumCols; ++col)
4004 std::vector<uint32> indices(shape_.size());
4006 const uint32 rowStart = row * shape_.rows;
4007 const uint32 colStart = col * shape_.cols;
4009 const uint32 rowEnd = (row + 1) * shape_.rows;
4010 const uint32 colEnd = (col + 1) * shape_.cols;
4013 for (
uint32 rowIdx = rowStart; rowIdx < rowEnd; ++rowIdx)
4015 for (
uint32 colIdx = colStart; colIdx < colEnd; ++colIdx)
4017 indices[counter++] = rowIdx * returnArray.shape_.
cols + colIdx;
4069 if (inSize != size_)
4071 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4077 shape_.cols = inSize;
4098 if (size_ % inNumCols == 0)
4100 return reshape(size_ / inNumCols, inNumCols);
4103 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4111 if (size_ % inNumRows == 0)
4113 return reshape(inNumRows, size_ / inNumRows);
4116 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4122 if (
static_cast<uint32>(inNumRows * inNumCols) != size_)
4124 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4129 shape_.rows =
static_cast<uint32>(inNumRows);
4130 shape_.cols =
static_cast<uint32>(inNumCols);
4163 newArray(
Shape(inNumRows, inNumCols));
4195 std::vector<dtype> oldData(size_);
4198 const Shape inShape(inNumRows, inNumCols);
4199 const Shape oldShape = shape_;
4203 for (
uint32 row = 0; row < inShape.
rows; ++row)
4205 for (
uint32 col = 0; col < inShape.
cols; ++col)
4207 if (row >= oldShape.
rows || col >= oldShape.
cols)
4209 operator()(row, col) = dtype{ 0 };
4213 operator()(row, col) = oldData[row * oldShape.
cols + col];
4252 const double multFactor =
utils::power(10.0, inNumDecimals);
4253 const auto function = [multFactor](dtype value) noexcept -> dtype
4255 return static_cast<dtype
>(std::nearbyint(
static_cast<double>(value) * multFactor) / multFactor);
4314 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
4328 for (
uint32 row = 0; row < shape_.rows; ++row)
4337 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
4362 for (
uint32 row = 0; row < shape_.rows; ++row)
4365 for (
uint32 col = 0; col < shape_.cols; ++col)
4370 if (row == shape_.rows - 1)
4400 NdArray<dtype> returnArray = { std::accumulate(cbegin(), cend(), dtype{ 0 }) };
4406 for (
uint32 row = 0; row < shape_.rows; ++row)
4408 returnArray(0, row) = std::accumulate(cbegin(row), cend(row), dtype{ 0 });
4416 const Shape transShape = transposedArray.
shape();
4418 for (
uint32 row = 0; row < transShape.
rows; ++row)
4420 returnArray(0, row) = std::accumulate(transposedArray.
cbegin(row), transposedArray.
cend(row), dtype{ 0 });
4458 void tofile(
const std::string& inFilename)
const
4475 void tofile(
const std::string& inFilename,
const char inSep)
const
4485 std::ofstream ofile(
f.fullName().c_str());
4492 for (
auto value : *
this)
4495 if (counter++ != size_ - 1)
4539 if (numElements == 0)
4545 indices[0] = inSlice.
start;
4548 indices[i] =
static_cast<uint32>(indices[i - 1] + inSlice.
step);
4562 return std::vector<dtype>(cbegin(), cend());
4586 rowStart += inOffset;
4591 colStart += inOffset;
4602 if (rowStart >= shape_.rows || colStart >= shape_.cols)
4609 for (
uint32 row = rowStart; row < shape_.rows; ++row)
4611 if (col >= shape_.cols)
4615 sum += operator()(row, col++);
4632 for (
uint32 row = 0; row < shape_.rows; ++row)
4634 for (
uint32 col = 0; col < shape_.cols; ++col)
4636 transArray(col, row) = operator()(row, col);
4657 allocator_type allocator_{};
4658 Shape shape_{ 0, 0 };
4659 size_type size_{ 0 };
4661 pointer array_{
nullptr };
4662 bool ownsPtr_{
false };
4668 void deleteArray() noexcept
4670 if (ownsPtr_ && array_ !=
nullptr)
4672 allocator_.deallocate(array_, size_);
4676 shape_.rows = shape_.cols = 0;
4690 array_ = allocator_.allocate(size_);
4701 void newArray(
const Shape& inShape)
4706 size_ = inShape.size();
4713 template<
typename dtype,
class _Alloc>
4718 std::vector<uint32> rowIndices;
4719 std::vector<uint32> colIndices;
4721 for (
uint32 row = 0; row < shape_.rows; ++row)
4723 for (
uint32 col = 0; col < shape_.cols; ++col)
4725 if (
operator()(row, col) != dtype{ 0 })
4727 rowIndices.push_back(row);
4728 colIndices.push_back(col);
#define THROW_RUNTIME_ERROR(msg)
Definition: Error.hpp:37
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:43
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:50
#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:834
Custom column const_iterator for NdArray.
Definition: NdArrayIterators.hpp:503
Custom const_iterator for NdArray.
Definition: NdArrayIterators.hpp:44
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
uint32 numCols() const noexcept
Definition: NdArrayCore.hpp:3418
NdArray(std::vector< std::array< dtype, Dim1Size >> &in2dArray, bool copy=true)
Definition: NdArrayCore.hpp:322
const_reverse_column_iterator rcolbegin() const noexcept
Definition: NdArrayCore.hpp:1424
NdArray< dtype > at(const NdArray< int32 > &rowIndices, const NdArray< int32 > &colIndices) const
Definition: NdArrayCore.hpp:1154
NdArray< dtypeOut > astype() const
Definition: NdArrayCore.hpp:2097
NdArray< dtype > & put(int32 inIndex, value_type inValue)
Definition: NdArrayCore.hpp:3666
size_type size() const noexcept
Definition: NdArrayCore.hpp:4296
reverse_iterator rbegin() noexcept
Definition: NdArrayCore.hpp:1320
NdArray< dtype > & resizeSlow(uint32 inNumRows, uint32 inNumCols)
Definition: NdArrayCore.hpp:4193
NdArray< dtype > & put(const Slice &inRowSlice, const Slice &inColSlice, value_type inValue)
Definition: NdArrayCore.hpp:3789
NdArray< bool > issorted(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2867
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1216
NdArray< dtype > operator[](const Indices &inIndices) const
Definition: NdArrayCore.hpp:759
const_reference at(int32 inIndex) const
Definition: NdArrayCore.hpp:1011
const_column_iterator ccolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1305
NdArrayConstColumnIterator< dtype, size_type, const_pointer, difference_type > const_column_iterator
Definition: NdArrayCore.hpp:96
NdArray< dtype > round(uint8 inNumDecimals=0) const
Definition: NdArrayCore.hpp:4247
NdArray< bool > any(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1840
const_pointer data() const noexcept
Definition: NdArrayCore.hpp:2537
NdArray< uint32 > toIndices(Slice inSlice, Axis inAxis=Axis::ROW) const
Definition: NdArrayCore.hpp:4512
NdArray< dtype > at(const Slice &inRowSlice, int32 inColIndex) const
Definition: NdArrayCore.hpp:1124
iterator end() noexcept
Definition: NdArrayCore.hpp:1474
NdArray< dtype > operator()(Slice inRowSlice, int32 inColIndex) const
Definition: NdArrayCore.hpp:813
NdArray< dtype > & put(const Slice &inRowSlice, const Slice &inColSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3867
NdArray(std::vector< dtype > &inVector, bool copy=true)
Definition: NdArrayCore.hpp:262
NdArray(const std::initializer_list< std::initializer_list< dtype > > &inList)
Definition: NdArrayCore.hpp:169
NdArray< dtype > prod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3556
NdArray< dtype > copy() const
Definition: NdArrayCore.hpp:2393
NdArray< dtype > & resizeFast(const Shape &inShape)
Definition: NdArrayCore.hpp:4176
std::vector< dtype > toStlVector() const
Definition: NdArrayCore.hpp:4560
reference back(size_type row)
Definition: NdArrayCore.hpp:2237
iterator end(size_type inRow)
Definition: NdArrayCore.hpp:1486
NdArray< dtype > flatten() const
Definition: NdArrayCore.hpp:2759
void tofile(const std::string &inFilename, const char inSep) const
Definition: NdArrayCore.hpp:4475
const_column_iterator ccolbegin() const noexcept
Definition: NdArrayCore.hpp:1293
typename AllocTraits::pointer pointer
Definition: NdArrayCore.hpp:83
Slice cSlice(int32 inStartIdx=0, uint32 inStepSize=1) const noexcept
Definition: NdArrayCore.hpp:964
reverse_iterator rbegin(size_type inRow)
Definition: NdArrayCore.hpp:1332
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4283
NdArray< dtype > & byteswap() noexcept
Definition: NdArrayCore.hpp:2250
const_reverse_column_iterator rcolend() const noexcept
Definition: NdArrayCore.hpp:1732
uint32 numRows() const noexcept
Definition: NdArrayCore.hpp:3430
const dtype & const_reference
Definition: NdArrayCore.hpp:86
NdArray< dtype > & put(const Slice &inRowSlice, int32 inColIndex, value_type inValue)
Definition: NdArrayCore.hpp:3819
NdArray< dtype > & partition(uint32 inKth, Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:3474
bool issquare() const noexcept
Definition: NdArrayCore.hpp:2918
NdArrayIterator< dtype, pointer, difference_type > iterator
Definition: NdArrayCore.hpp:90
bool isflat() const noexcept
Definition: NdArrayCore.hpp:2855
Endian endianess() const noexcept
Definition: NdArrayCore.hpp:2704
void tofile(const std::string &inFilename) const
Definition: NdArrayCore.hpp:4458
const_reverse_column_iterator crcolbegin() const noexcept
Definition: NdArrayCore.hpp:1447
const_reverse_column_iterator crcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1767
column_iterator colbegin(size_type inCol)
Definition: NdArrayCore.hpp:1255
NdArrayColumnIterator< dtype, size_type, pointer, difference_type > column_iterator
Definition: NdArrayCore.hpp:95
NdArray< bool > none(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3354
NdArray< dtype > at(const Slice &inSlice) const
Definition: NdArrayCore.hpp:1094
reference at(int32 inIndex)
Definition: NdArrayCore.hpp:990
NdArray< dtype > & sort(Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:4310
pointer data() noexcept
Definition: NdArrayCore.hpp:2527
bool isempty() const noexcept
Definition: NdArrayCore.hpp:2843
column_iterator colbegin() noexcept
Definition: NdArrayCore.hpp:1243
const_reference front(size_type row) const
Definition: NdArrayCore.hpp:2794
reverse_column_iterator rcolend(size_type inCol)
Definition: NdArrayCore.hpp:1717
NdArray< dtype > sum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:4392
NdArray(Iterator inFirst, Iterator inLast)
Definition: NdArrayCore.hpp:418
NdArray< dtype > operator[](const Slice &inSlice) const
Definition: NdArrayCore.hpp:711
reverse_column_iterator rcolbegin() noexcept
Definition: NdArrayCore.hpp:1397
NdArrayConstIterator< dtype, const_pointer, difference_type > const_iterator
Definition: NdArrayCore.hpp:91
const_iterator cbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1228
const_column_iterator ccolend(size_type inCol) const
Definition: NdArrayCore.hpp:1690
NdArray< dtype > cumsum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2469
NdArray< dtype > median(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3062
NdArray< dtype > getByMask(const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:2831
const_iterator cend(size_type inRow) const
Definition: NdArrayCore.hpp:1536
NdArray< dtype > column(uint32 inColumn)
Definition: NdArrayCore.hpp:2332
const_reverse_column_iterator rcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1744
NdArray< dtype > & putMask(const NdArray< bool > &inMask, value_type inValue)
Definition: NdArrayCore.hpp:3945
const_iterator end(size_type inRow) const
Definition: NdArrayCore.hpp:1513
reference back() noexcept
Definition: NdArrayCore.hpp:2215
const_reverse_column_iterator crcolend() const noexcept
Definition: NdArrayCore.hpp:1755
const_reference back(size_type row) const
Definition: NdArrayCore.hpp:2226
reverse_column_iterator rcolbegin(size_type inCol)
Definition: NdArrayCore.hpp:1409
NdArray(const std::deque< std::deque< dtype >> &in2dDeque)
Definition: NdArrayCore.hpp:366
NdArray< dtype > & put(int32 inRow, int32 inCol, value_type inValue)
Definition: NdArrayCore.hpp:3683
iterator begin(size_type inRow)
Definition: NdArrayCore.hpp:1178
const_reverse_iterator rend() const noexcept
Definition: NdArrayCore.hpp:1578
NdArray< dtype > clip(value_type inMin, value_type inMax) const
Definition: NdArrayCore.hpp:2293
const_reverse_column_iterator rcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1436
NdArray< dtype > & operator=(NdArray< dtype > &&rhs) noexcept
Definition: NdArrayCore.hpp:604
typename AllocTraits::difference_type difference_type
Definition: NdArrayCore.hpp:88
NdArray< uint32 > argmin(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1953
const_iterator end() const noexcept
Definition: NdArrayCore.hpp:1501
bool ownsInternalData() noexcept
Definition: NdArrayCore.hpp:3454
NdArray< dtype > & fill(value_type inFillValue) noexcept
Definition: NdArrayCore.hpp:2720
column_iterator colend() noexcept
Definition: NdArrayCore.hpp:1628
NdArray(std::initializer_list< dtype > inList)
Definition: NdArrayCore.hpp:152
NdArray< dtype > operator()(Slice inRowSlice, Slice inColSlice) const
Definition: NdArrayCore.hpp:785
NdArray< dtype > & put(const NdArray< uint32 > &inIndices, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3718
const_reference back() const noexcept
Definition: NdArrayCore.hpp:2204
NdArray< dtype > operator()(int32 inRowIndex, Slice inColSlice) const
Definition: NdArrayCore.hpp:835
std::pair< NdArray< uint32 >, NdArray< uint32 > > nonzero() const
Definition: NdArrayCore.hpp:4714
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: NdArrayCore.hpp:93
NdArray(const_pointer inPtr, UIntType1 numRows, UIntType2 numCols)
Definition: NdArrayCore.hpp:460
NdArray< dtype > cumprod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2407
uint64 nbytes() const noexcept
Definition: NdArrayCore.hpp:3176
const_reference at(int32 inRowIndex, int32 inColIndex) const
Definition: NdArrayCore.hpp:1064
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4629
NdArray< dtype > swapaxes() const
Definition: NdArrayCore.hpp:4441
NdArray< dtype > & put(int32 inRowIndex, const Slice &inColSlice, value_type inValue)
Definition: NdArrayCore.hpp:3843
NdArray(const std::list< dtype > &inList)
Definition: NdArrayCore.hpp:398
NdArray< dtype > at(int32 inRowIndex, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1139
const_reference front() const noexcept
Definition: NdArrayCore.hpp:2772
NdArray< dtype > repeat(const Shape &inRepeatShape) const
Definition: NdArrayCore.hpp:4037
~NdArray() noexcept
Definition: NdArrayCore.hpp:551
NdArray< dtype > min(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3005
NdArray(pointer inPtr, uint32 numRows, uint32 numCols, Bool takeOwnership) noexcept
Definition: NdArrayCore.hpp:503
NdArray< dtype > & reshape(const Shape &inShape)
Definition: NdArrayCore.hpp:4146
reference front() noexcept
Definition: NdArrayCore.hpp:2783
NdArray(size_type inNumRows, size_type inNumCols)
Definition: NdArrayCore.hpp:126
Allocator allocator_type
Definition: NdArrayCore.hpp:82
void print() const
Definition: NdArrayCore.hpp:3540
const_reverse_column_iterator crcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1459
reverse_iterator rend(size_type inRow)
Definition: NdArrayCore.hpp:1563
NdArray< uint32 > flatnonzero() const
Definition: NdArrayCore.hpp:2733
NdArray(size_type inSquareSize)
Definition: NdArrayCore.hpp:112
NdArray< dtype > operator()(int32 rowIndex, const Indices &colIndices) const
Definition: NdArrayCore.hpp:892
reverse_iterator rend() noexcept
Definition: NdArrayCore.hpp:1551
const_reverse_iterator rend(size_type inRow) const
Definition: NdArrayCore.hpp:1590
NdArray< dtype > getByIndices(const NdArray< uint32 > &inIndices) const
Definition: NdArrayCore.hpp:2817
typename AllocTraits::const_pointer const_pointer
Definition: NdArrayCore.hpp:84
NdArray< dtype > & resizeSlow(const Shape &inShape)
Definition: NdArrayCore.hpp:4232
const_reverse_iterator crbegin() const noexcept
Definition: NdArrayCore.hpp:1370
const_column_iterator colend(size_type inCol) const
Definition: NdArrayCore.hpp:1667
std::reverse_iterator< iterator > reverse_iterator
Definition: NdArrayCore.hpp:92
NdArray< dtype > operator()(const Indices &rowIndices, Slice colSlice) const
Definition: NdArrayCore.hpp:876
NdArray(const std::vector< std::vector< dtype >> &in2dVector)
Definition: NdArrayCore.hpp:287
const_reverse_iterator rbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1359
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1524
std::string str() const
Definition: NdArrayCore.hpp:4356
std::reverse_iterator< const_column_iterator > const_reverse_column_iterator
Definition: NdArrayCore.hpp:98
reference operator[](int32 inIndex) noexcept
Definition: NdArrayCore.hpp:630
NdArray< dtype > & reshape(int32 inNumRows, int32 inNumCols)
Definition: NdArrayCore.hpp:4094
NdArray(NdArray< dtype > &&inOtherArray) noexcept
Definition: NdArrayCore.hpp:534
NdArray< dtype > & nans() noexcept
Definition: NdArrayCore.hpp:3160
NdArray< dtype > & put(const NdArray< uint32 > &inIndices, value_type inValue)
Definition: NdArrayCore.hpp:3699
NdArray< dtype > ptp(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3609
const_reference operator()(int32 inRowIndex, int32 inColIndex) const noexcept
Definition: NdArrayCore.hpp:688
reference front(size_type row)
Definition: NdArrayCore.hpp:2805
NdArray< dtype > diagonal(int32 inOffset=0, Axis inAxis=Axis::ROW) const
Definition: NdArrayCore.hpp:2565
NdArray< dtype > & putMask(const NdArray< bool > &inMask, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3962
NdArray< dtype > operator[](const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:732
NdArray< dtype > row(uint32 inRow)
Definition: NdArrayCore.hpp:4270
NdArray< dtype > operator()(const Indices &rowIndices, int32 colIndex) const
Definition: NdArrayCore.hpp:859
const_iterator begin(size_type inRow) const
Definition: NdArrayCore.hpp:1205
iterator begin() noexcept
Definition: NdArrayCore.hpp:1166
NdArray< dtype > & put(const Slice &inSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3765
const_column_iterator colbegin() const noexcept
Definition: NdArrayCore.hpp:1270
NdArray< dtype > max(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2950
std::reverse_iterator< column_iterator > reverse_column_iterator
Definition: NdArrayCore.hpp:97
NdArray< dtype > & operator=(const NdArray< dtype > &rhs)
Definition: NdArrayCore.hpp:563
value_type item() const
Definition: NdArrayCore.hpp:2931
reference operator()(int32 inRowIndex, int32 inColIndex) noexcept
Definition: NdArrayCore.hpp:665
const_column_iterator colend() const noexcept
Definition: NdArrayCore.hpp:1655
NdArray< dtype > & resizeFast(uint32 inNumRows, uint32 inNumCols)
Definition: NdArrayCore.hpp:4161
const_reverse_iterator crend() const noexcept
Definition: NdArrayCore.hpp:1601
NdArray< dtype > & ones() noexcept
Definition: NdArrayCore.hpp:3440
NdArray< dtype > operator()(RowIndices rowIndices, ColIndices colIndices) const
Definition: NdArrayCore.hpp:926
NdArray< dtype > & zeros() noexcept
Definition: NdArrayCore.hpp:4647
const_column_iterator colbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1282
NdArray< dtype > dot(const NdArray< dtype > &inOtherArray) const
Definition: NdArrayCore.hpp:2633
NdArray< dtype > repeat(uint32 inNumRows, uint32 inNumCols) const
Definition: NdArrayCore.hpp:3996
NdArray< dtype > & reshape(size_type inSize)
Definition: NdArrayCore.hpp:4067
NdArray< bool > contains(value_type inValue, Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2345
const_column_iterator ccolend() const noexcept
Definition: NdArrayCore.hpp:1678
NdArray< uint32 > argmax(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1895
value_type trace(uint32 inOffset=0, Axis inAxis=Axis::ROW) const noexcept
Definition: NdArrayCore.hpp:4576
reverse_column_iterator rcolend() noexcept
Definition: NdArrayCore.hpp:1705
NdArray(std::array< dtype, ArraySize > &inArray, bool copy=true)
Definition: NdArrayCore.hpp:205
NdArray< dtype > & put(int32 inRowIndex, const Slice &inColSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3923
const_reverse_iterator rbegin() const noexcept
Definition: NdArrayCore.hpp:1347
NdArray(const_pointer inPtr, size_type size)
Definition: NdArrayCore.hpp:437
NdArray(const std::deque< dtype > &inDeque)
Definition: NdArrayCore.hpp:349
NdArray(std::array< std::array< dtype, Dim1Size >, Dim0Size > &in2dArray, bool copy=true)
Definition: NdArrayCore.hpp:233
void dump(const std::string &inFilename) const
Definition: NdArrayCore.hpp:2677
dtype & reference
Definition: NdArrayCore.hpp:85
pointer dataRelease() noexcept
Definition: NdArrayCore.hpp:2549
reference at(int32 inRowIndex, int32 inColIndex)
Definition: NdArrayCore.hpp:1033
NdArray< dtype > at(const Slice &inRowSlice, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1109
NdArray< dtype > operator()(Slice rowSlice, const Indices &colIndices) const
Definition: NdArrayCore.hpp:909
NdArray(const NdArray< dtype > &inOtherArray)
Definition: NdArrayCore.hpp:516
NdArray< uint32 > argsort(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2010
uint32 size_type
Definition: NdArrayCore.hpp:87
const_iterator begin() const noexcept
Definition: NdArrayCore.hpp:1193
NdArray< dtype > & operator=(value_type inValue) noexcept
Definition: NdArrayCore.hpp:587
NdArray< dtype > newbyteorder(Endian inEndianess) const
Definition: NdArrayCore.hpp:3191
column_iterator colend(size_type inCol)
Definition: NdArrayCore.hpp:1640
NdArray< dtype > & put(const Slice &inSlice, value_type inValue)
Definition: NdArrayCore.hpp:3743
const_reference operator[](int32 inIndex) const noexcept
Definition: NdArrayCore.hpp:647
NdArray< dtype > & ravel() noexcept
Definition: NdArrayCore.hpp:3980
dtype value_type
Definition: NdArrayCore.hpp:81
NdArray(pointer inPtr, size_type size, Bool takeOwnership) noexcept
Definition: NdArrayCore.hpp:483
void replace(value_type oldValue, value_type newValue)
Definition: NdArrayCore.hpp:4049
NdArray< dtype > & put(const Slice &inRowSlice, int32 inColIndex, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3898
Slice rSlice(int32 inStartIdx=0, uint32 inStepSize=1) const noexcept
Definition: NdArrayCore.hpp:978
const_reverse_iterator crend(size_type inRow) const
Definition: NdArrayCore.hpp:1613
const_reverse_iterator crbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1382
NdArray(const Shape &inShape)
Definition: NdArrayCore.hpp:139
NdArray< bool > all(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1786
Custom iterator for NdArray.
Definition: NdArrayIterators.hpp:324
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:102
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:137
uint32 numElements(uint32 inArraySize)
Definition: Slice.hpp:188
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(dtype inDofN, dtype inDofD)
Definition: f.hpp:55
bool any_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:76
void sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:629
bool none_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:379
ForwardIt max_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:268
void stable_sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:664
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:702
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:213
InputIt find(InputIt first, InputIt last, const T &value) noexcept
Definition: StlAlgorithms.hpp:195
constexpr OutputIt unique_copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:744
std::pair< ForwardIt, ForwardIt > minmax_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:341
void replace(ForwardIt first, ForwardIt last, const T &oldValue, const T &newValue) noexcept
Definition: StlAlgorithms.hpp:435
bool is_sorted(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:231
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:95
void nth_element(RandomIt first, RandomIt nth, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:397
ForwardIt min_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:304
void fill(ForwardIt first, ForwardIt last, const T &value) noexcept
Definition: StlAlgorithms.hpp:174
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
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:46
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:50
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