35#include <initializer_list>
82 template<
typename dtype,
typename Allocator>
85 static constexpr bool value = std::is_integral_v<dtype>;
109 template<
typename dtype,
typename Allocator>
112 static constexpr bool value = std::is_signed_v<dtype>;
133 template<
typename dtype,
class Allocator = std::allocator<dtype>>
138 static_assert(std::is_same_v<dtype, typename Allocator::value_type>,
139 "value_type and Allocator::value_type must match");
141 using AllocType =
typename std::allocator_traits<Allocator>::template rebind_alloc<dtype>;
142 using AllocTraits = std::allocator_traits<AllocType>;
148 using pointer =
typename AllocTraits::pointer;
179 shape_{ inSquareSize, inSquareSize },
180 size_{ inSquareSize * inSquareSize }
193 shape_{ inNumRows, inNumCols },
194 size_{ inNumRows * inNumCols }
207 size_{ shape_.
size() }
218 NdArray(std::initializer_list<dtype> inList) :
219 shape_{ 1, static_cast<
uint32>(inList.
size()) },
220 size_{ shape_.
size() }
235 NdArray(
const std::initializer_list<std::initializer_list<dtype>>& inList) :
236 shape_{ static_cast<
uint32>(inList.
size()), 0 }
238 for (
const auto& list : inList)
240 if (shape_.cols == 0)
242 shape_.cols =
static_cast<uint32>(list.size());
244 else if (list.size() != shape_.cols)
247 "All rows of the initializer list needs to have the same number of elements");
251 size_ = shape_.size();
254 for (
const auto& list : inList)
256 const auto ptr =
begin() +=
row * shape_.cols;
269 template<
size_t ArraySize, std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
271 shape_{ 1, static_cast<
uint32>(ArraySize) },
272 size_{ shape_.
size() }
287 array_ = inArray.data();
305 template<
size_t Dim0Size,
size_t Dim1Size>
306 NdArray(std::array<std::array<dtype, Dim1Size>, Dim0Size>& in2dArray,
308 shape_{ static_cast<
uint32>(Dim0Size), static_cast<
uint32>(Dim1Size) },
309 size_{ shape_.
size() }
318 const auto start = in2dArray.front().begin();
325 array_ = in2dArray.front().data();
343 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
345 shape_{ 1, static_cast<
uint32>(inVector.
size()) },
346 size_{ shape_.
size() }
361 array_ = inVector.data();
378 explicit NdArray(
const std::vector<std::vector<dtype>>& in2dVector) :
379 shape_{ static_cast<
uint32>(in2dVector.
size()), 0 }
381 for (
const auto&
row : in2dVector)
383 if (shape_.cols == 0)
385 shape_.cols =
static_cast<uint32>(
row.size());
387 else if (
row.size() != shape_.cols)
393 size_ = shape_.size();
396 auto currentPosition =
begin();
397 for (
const auto&
row : in2dVector)
400 currentPosition += shape_.cols;
411 template<
size_t Dim1Size>
413 shape_{ static_cast<
uint32>(in2dArray.
size()), static_cast<
uint32>(Dim1Size) },
414 size_{ shape_.
size() }
423 const auto start = in2dArray.front().begin();
430 array_ = in2dArray.front().data();
447 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
448 explicit NdArray(
const std::deque<dtype>& inDeque) :
449 shape_{ 1, static_cast<
uint32>(inDeque.
size()) },
450 size_{ shape_.
size() }
465 explicit NdArray(
const std::deque<std::deque<dtype>>& in2dDeque) :
466 shape_{ static_cast<
uint32>(in2dDeque.
size()), 0 }
468 for (
const auto&
row : in2dDeque)
470 if (shape_.cols == 0)
472 shape_.cols =
static_cast<uint32>(
row.size());
474 else if (
row.size() != shape_.cols)
480 size_ = shape_.size();
483 auto currentPosition =
begin();
484 for (
const auto&
row : in2dDeque)
487 currentPosition += shape_.cols;
497 explicit NdArray(
const std::list<dtype>& inList) :
498 shape_{ 1, static_cast<
uint32>(inList.
size()) },
499 size_{ shape_.
size() }
515 template<
typename Iterator,
516 std::enable_if_t<std::is_same_v<typename std::iterator_traits<Iterator>::value_type, dtype>,
int> = 0>
518 shape_{ 1, static_cast<
uint32>(std::distance(inFirst, inLast)) },
519 size_{ shape_.
size() }
535 template<
typename UIntType,
536 std::enable_if_t<std::is_integral_v<UIntType> && !std::is_same_v<UIntType, bool>,
int> = 0>
550 template<
typename UIntType1,
552 std::enable_if_t<std::is_integral_v<UIntType1> && !std::is_same_v<UIntType1, bool>,
int> = 0,
553 std::enable_if_t<std::is_integral_v<UIntType2> && !std::is_same_v<UIntType2, bool>,
int> = 0>
556 size_{ shape_.
size() }
559 if (inPtr !=
nullptr && size_ > 0)
574 template<
typename UIntType,
575 std::enable_if_t<std::is_integral_v<UIntType> && !std::is_same_v<UIntType, bool>,
int> = 0>
591 template<
typename UIntType1,
593 std::enable_if_t<std::is_integral_v<UIntType1> && !std::is_same_v<UIntType1, bool>,
int> = 0,
594 std::enable_if_t<std::is_integral_v<UIntType2> && !std::is_same_v<UIntType2, bool>,
int> = 0>
597 size_{ shape_.
size() }
604 if (inPtr !=
nullptr && size_ > 0)
630 shape_{ inOtherArray.shape_ },
631 size_{ inOtherArray.size_ },
632 endianess_{ inOtherArray.endianess_ }
648 shape_{ inOtherArray.shape_ },
649 size_{ inOtherArray.size_ },
650 endianess_{ inOtherArray.endianess_ },
651 array_{ inOtherArray.array_ },
652 ownsPtr_{ inOtherArray.ownsPtr_ }
654 inOtherArray.shape_.rows = inOtherArray.shape_.cols = 0;
655 inOtherArray.size_ = 0;
656 inOtherArray.ownsPtr_ =
false;
657 inOtherArray.array_ =
nullptr;
674 explicit operator bool() const noexcept
692 newArray(rhs.shape_);
693 endianess_ = rhs.endianess_;
712 if (array_ !=
nullptr)
734 endianess_ = rhs.endianess_;
736 ownsPtr_ = rhs.ownsPtr_;
738 rhs.shape_.rows = rhs.shape_.cols = rhs.size_ = 0;
739 rhs.array_ =
nullptr;
740 rhs.ownsPtr_ =
false;
755 return const_cast<reference>(
const_cast<const self_type*
>(
this)->operator[](inIndex));
772 return array_[inIndex];
785 return const_cast<reference>(
const_cast<const self_type*
>(
this)->operator()(inRowIndex, inColIndex));
800 inRowIndex += shape_.rows;
805 inColIndex += shape_.cols;
808 return array_[inRowIndex * shape_.cols + inColIndex];
844 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
849 for (
auto& index : inIndices)
910 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
926 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
941 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
957 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
972 template<
typename RowIndices,
978 self_type returnArray(rowIndices.size(), colIndices.size());
981 for (
auto rowIter = rowIndices.begin(); rowIter != rowIndices.end(); ++rowIter)
984 for (
auto colIter = colIndices.begin(); colIter != colIndices.end(); ++colIter)
986 returnArray(rowCounter, colCounter++) =
operator()(*rowIter, *colIter);
1006 return Slice(inStartIdx, shape_.cols, inStepSize);
1020 return Slice(inStartIdx, shape_.rows, inStepSize);
1046 if (std::abs(inIndex) >
static_cast<int64>(size_ - 1))
1049 errStr +=
" is out of bounds for array of size " +
utils::num2str(size_) +
".";
1066 return const_cast<reference>(
const_cast<const self_type*
>(
this)->at(inRowIndex, inColIndex));
1081 if (std::abs(inRowIndex) >
static_cast<index_type>(shape_.rows - 1))
1084 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.rows) +
".";
1090 if (std::abs(inColIndex) >
static_cast<index_type>(shape_.cols - 1))
1092 std::string errStr =
"Column index " +
utils::num2str(inColIndex);
1093 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.cols) +
".";
1121 if (inMask.
shape() != shape_)
1136 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1143 auto indexSigned = static_cast<index_type>(index);
1144 if (indexSigned < 0)
1146 indexSigned += size_;
1149 if (indexSigned < 0 || indexSigned >
static_cast<index_type>(size_ - 1))
1207 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1211 return at(rowIndices, colIndices);
1222 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1236 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1240 return at(rowIndices, colIndices);
1251 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1265 template<
typename RowIndices,
1266 typename ColIndices,
1269 [[nodiscard]]
self_type at(
const RowIndices& rowIndices,
const ColIndices& colIndices)
const
1275 auto rowSigned = static_cast<index_type>(row);
1278 rowSigned += shape_.rows;
1281 if (rowSigned < 0 || rowSigned >
static_cast<index_type>(shape_.rows - 1))
1283 THROW_INVALID_ARGUMENT_ERROR(
"Row index exceeds matrix dimensions");
1291 auto colSigned = static_cast<index_type>(col);
1294 colSigned += shape_.cols;
1297 if (colSigned < 0 || colSigned >
static_cast<index_type
>(shape_.cols - 1))
1299 THROW_INVALID_ARGUMENT_ERROR(
"Column index exceeds matrix dimensions");
1303 return operator()(rowIndices, colIndices);
1325 if (inRow >= shape_.rows)
1330 return begin() += (inRow * shape_.cols);
1375 if (inRow >= shape_.rows)
1380 return cbegin() += (inRow * shape_.cols);
1402 if (inCol >= shape_.cols)
1407 return colbegin() += (inCol * shape_.rows);
1452 if (inCol >= shape_.cols)
1457 return ccolbegin() += (inCol * shape_.rows);
1479 if (inRow >= shape_.rows)
1484 return rbegin() += (shape_.rows - inRow - 1) * shape_.cols;
1529 if (inRow >= shape_.rows)
1534 return crbegin() += (shape_.rows - inRow - 1) * shape_.cols;
1556 if (inCol >= shape_.cols)
1561 return rcolbegin() += (shape_.cols - inCol - 1) * shape_.rows;
1606 if (inCol >= shape_.cols)
1611 return crcolbegin() += (shape_.cols - inCol - 1) * shape_.rows;
1621 return begin() += size_;
1633 if (inRow >= shape_.rows)
1638 return begin(inRow) += shape_.cols;
1671 return cbegin() += size_;
1683 if (inRow >= shape_.rows)
1688 return cbegin(inRow) += shape_.cols;
1698 return rbegin() += size_;
1710 if (inRow >= shape_.rows)
1715 return rbegin(inRow) += shape_.cols;
1737 return crend(inRow);
1760 if (inRow >= shape_.rows)
1765 return crbegin(inRow) += shape_.cols;
1787 if (inCol >= shape_.cols)
1792 return colbegin(inCol) += shape_.rows;
1837 if (inCol >= shape_.cols)
1864 if (inCol >= shape_.cols)
1914 if (inCol >= shape_.cols)
2024 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
2071 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
2131 std::vector<size_type> idx(size_);
2132 std::iota(idx.begin(), idx.end(), 0);
2135 {
return (*
this)[i1] < (*this)[i2]; };
2142 if (inKth >= shape_.cols)
2145 errStr +=
") out of bounds (" +
utils::num2str(shape_.cols) +
")";
2150 std::vector<size_type> idx(shape_.cols);
2154 std::iota(idx.begin(), idx.end(), 0);
2161 for (
index_type col = 0; col < static_cast<index_type>(shape_.cols); ++col)
2163 returnArray(
row, col) = idx[
static_cast<size_type>(col)];
2197 std::vector<size_type> idx(size_);
2198 std::iota(idx.begin(), idx.end(), 0);
2201 {
return (*
this)[i1] < (*this)[i2]; };
2209 std::vector<size_type> idx(shape_.cols);
2211 for (
index_type row = 0; row < static_cast<index_type>(shape_.rows); ++
row)
2213 std::iota(idx.begin(), idx.end(), 0);
2220 for (
index_type col = 0; col < static_cast<index_type>(shape_.cols); ++col)
2222 returnArray(
row, col) = idx[
static_cast<size_type>(col)];
2248 template<
typename dtypeOut,
2249 typename dtype_ = dtype,
2250 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2251 std::enable_if_t<std::is_arithmetic_v<dtype_>,
int> = 0,
2252 std::enable_if_t<std::is_arithmetic_v<dtypeOut>,
int> = 0>
2255 if constexpr (std::is_same_v<dtypeOut, dtype>)
2265 [](dtype value) -> dtypeOut { return static_cast<dtypeOut>(value); });
2280 template<
typename dtypeOut,
2281 typename dtype_ = dtype,
2282 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2283 std::enable_if_t<std::is_arithmetic_v<dtype_>,
int> = 0,
2284 std::enable_if_t<is_complex_v<dtypeOut>,
int> = 0>
2290 {
return std::complex<typename dtypeOut::value_type>(value); };
2306 template<
typename dtypeOut,
2307 typename dtype_ = dtype,
2308 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2309 std::enable_if_t<is_complex_v<dtype_>,
int> = 0,
2310 std::enable_if_t<is_complex_v<dtypeOut>,
int> = 0>
2313 if constexpr (std::is_same_v<dtypeOut, dtype>)
2337 template<
typename dtypeOut,
2338 typename dtype_ = dtype,
2339 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2340 std::enable_if_t<is_complex_v<dtype_>,
int> = 0,
2341 std::enable_if_t<std::is_arithmetic_v<dtypeOut>,
int> = 0>
2346 const auto function = [](
const_reference value) -> dtypeOut {
return static_cast<dtypeOut
>(value.real()); };
2361 return *(
cend() - 1);
2372 return *(
end() - 1);
2453 [inMin, inMax](dtype value) noexcept -> dtype
2455#ifdef __cpp_lib_clamp
2456 const auto comparitor = [](dtype lhs, dtype rhs) noexcept -> bool
2457 { return lhs < rhs; };
2459 return std::clamp(value, inMin, inMax, comparitor);
2465 else if (value > inMax)
2499 const auto rSlice = returnArray.rSlice();
2581 returnArray[0] =
front();
2584 returnArray[i] = returnArray[i - 1] * array_[i];
2595 for (
uint32 col = 1; col < shape_.cols; ++col)
2633 returnArray[0] =
front();
2636 returnArray[i] = returnArray[i - 1] + array_[i];
2647 for (
uint32 col = 1; col < shape_.cols; ++col)
2717 std::vector<dtype> diagnolValues;
2719 for (
index_type row = inOffset; row < static_cast<index_type>(shape_.rows); ++
row)
2726 if (col >= shape_.cols)
2731 diagnolValues.push_back(
operator()(
static_cast<size_type>(
row), col));
2795 if (shape_ == inOtherArray.shape_ && (shape_.rows == 1 || shape_.cols == 1))
2803 if (shape_.cols == inOtherArray.shape_.
rows)
2806 self_type returnArray(shape_.rows, inOtherArray.shape_.
cols);
2807 auto otherArrayT = inOtherArray.
transpose();
2809 for (
uint32 i = 0; i < shape_.rows; ++i)
2811 for (
uint32 j = 0; j < otherArrayT.shape_.rows; ++j)
2814 otherArrayT.cend(j),
2826 errStr +=
" are not consistent.";
2841 void dump(
const std::string& inFilename)
const
2843 std::filesystem::path f(inFilename);
2844 if (!f.has_extension())
2846 f.replace_extension(
"bin");
2849 std::ofstream ofile(f.c_str(), std::ios::binary);
2855 if (array_ !=
nullptr)
2857 ofile.write(
reinterpret_cast<const char*
>(array_), size_ *
sizeof(dtype));
2901 std::vector<size_type> indices;
2903 for (
auto value : *
this)
2907 indices.push_back(idx);
3023 return !
isscalar() && (shape_.rows == 1 || shape_.cols == 1);
3048 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3087 return shape_.issquare();
3121 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3165 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3211 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3226 copyArray.
begin() + middleIdx,
3230 dtype medianValue = copyArray.array_[middleIdx];
3233 const size_type lhsIndex = middleIdx - 1;
3235 copyArray.
begin() + lhsIndex,
3239 (medianValue + copyArray.array_[lhsIndex]) / dtype{ 2 };
3242 return { medianValue };
3249 const bool isEven = shape_.cols % 2 == 0;
3252 const uint32 middleIdx = shape_.cols / 2;
3258 dtype medianValue = copyArray(
row, middleIdx);
3261 const size_type lhsIndex = middleIdx - 1;
3266 medianValue = (medianValue + copyArray(
row, lhsIndex)) /
3270 returnArray(0,
row) = medianValue;
3311 return static_cast<uint64>(
sizeof(dtype) * size_);
3334 switch (inEndianess)
3353 auto outArray =
NdArray(*
this);
3362 auto outArray =
NdArray(*
this);
3386 switch (inEndianess)
3401 auto outArray =
NdArray(*
this);
3429 switch (inEndianess)
3435 auto outArray =
NdArray(*
this);
3601 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool
3602 {
return lhs < rhs; };
3620 if (inKth >= shape_.cols)
3623 errStr +=
") out of bounds (" +
utils::num2str(shape_.cols) +
")";
3635 if (inKth >= shape_.rows)
3638 errStr +=
") out of bounds (" +
utils::num2str(shape_.rows) +
")";
3646 transposedArray.
begin(
row) + inKth,
3647 transposedArray.
end(
row),
3687 dtype product = std::accumulate(
cbegin(),
cend(), dtype{ 1 }, std::multiplies<dtype>());
3696 returnArray(0,
row) =
3697 std::accumulate(
cbegin(
row),
cend(
row), dtype{ 1 }, std::multiplies<dtype>());
3727 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3734 self_type returnArray = { *result.second - *result.first };
3743 returnArray(0,
row) = *result.second - *result.first;
3771 at(inIndex) = inValue;
3788 at(inRow, inCol) = inValue;
3803 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3806 for (
auto index : inIndices)
3808 put(index, inValue);
3824 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3829 return put(inIndices, inValues.
item());
3831 else if (inIndices.size() != inValues.
size())
3837 for (
auto index : inIndices)
3839 put(index, inValues[counter++]);
3886 template<
typename RowIndices,
3887 typename ColIndices,
3894 [
this, &inColIndices, &inValue](
const auto row)
3896 stl_algorithms::for_each(inColIndices.begin(),
3898 [this, row, &inValue](const auto col)
3899 { this->put(row, col, inValue); });
3916 template<
typename RowIndices, type_traits::ndarray_
int_concept<RowIndices> = 0>
3933 template<
typename ColIndices, type_traits::ndarray_
int_concept<ColIndices> = 0>
3966 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3970 return put(inRowIndices, colIndices, inValue);
4001 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
4005 return put(rowIndices, inColIndices, inValue);
4036 template<
typename RowIndices,
4037 typename ColIndices,
4042 std::vector<size_type> indices;
4043 indices.reserve(inRowIndices.size() * inColIndices.size());
4044 std::for_each(inRowIndices.begin(),
4046 [
this, &inColIndices, &indices](
auto row)
4048 if constexpr (std::is_signed_v<decltype(row)>)
4057 THROW_INVALID_ARGUMENT_ERROR(
"row index exceeds matrix dimensions");
4060 std::for_each(inColIndices.begin(),
4062 [
this,
row, &indices](
auto col)
4064 if constexpr (std::is_signed_v<decltype(col)>)
4073 THROW_INVALID_ARGUMENT_ERROR(
4074 "col index exceeds matrix dimensions");
4077 indices.push_back(
row * shape_.cols + col);
4081 return put(NdArray<size_type>(indices.data(), indices.size(), PointerPolicy::SHELL), inValues);
4095 template<
typename RowIndices, type_traits::ndarray_
int_concept<RowIndices> = 0>
4112 template<
typename ColIndices, type_traits::ndarray_
int_concept<ColIndices> = 0>
4145 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
4149 return put(inRowIndices, colIndices, inValues);
4180 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
4184 return put(rowIndices, inColIndices, inValues);
4213 if (inMask.
shape() != shape_)
4230 if (inMask.
shape() != shape_)
4273 self_type returnArray(shape_.rows * inNumRows, shape_.cols * inNumCols);
4277 for (
size_type col = 0; col < inNumCols; ++col)
4279 std::vector<size_type> indices(shape_.size());
4282 const size_type colStart = col * shape_.cols;
4285 const size_type colEnd = (col + 1) * shape_.cols;
4288 for (
size_type rowIdx = rowStart; rowIdx < rowEnd; ++rowIdx)
4290 for (
size_type colIdx = colStart; colIdx < colEnd; ++colIdx)
4292 indices[counter++] = rowIdx * returnArray.shape_.
cols + colIdx;
4349 if (inSize != size_)
4351 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4357 shape_.cols = inSize;
4382 if (size_ % inNumCols == 0)
4384 return reshape(size_ / inNumCols, inNumCols);
4387 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4394 if (size_ % inNumRows == 0)
4396 return reshape(inNumRows, size_ / inNumRows);
4399 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4404 if (
static_cast<size_type>(inNumRows * inNumCols) != size_)
4406 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4412 shape_.cols =
static_cast<size_type>(inNumCols);
4449 newArray(
Shape(inNumRows, inNumCols));
4481 std::vector<dtype> oldData(size_);
4484 const Shape inShape(inNumRows, inNumCols);
4485 const Shape oldShape = shape_;
4491 for (
uint32 col = 0; col < inShape.
cols; ++col)
4538 const double multFactor =
utils::power(10., inNumDecimals);
4539 const auto function = [multFactor](dtype value)
noexcept -> dtype
4540 {
return static_cast<dtype
>(std::nearbyint(
static_cast<double>(value) * multFactor) / multFactor); };
4569 const auto cSlice = returnArray.cSlice();
4573 returnArray.put(i,
cSlice,
row(inRows[i]));
4618 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool
4619 {
return lhs < rhs; };
4658 [[nodiscard]] std::string
str()
const
4667 for (
uint32 col = 0; col < shape_.cols; ++col)
4672 if (
row == shape_.rows - 1)
4750 for (
index_type row = 0; row < static_cast<index_type>(shape_.rows); ++
row)
4752 std::swap(
operator()(
row, colIdx1),
operator()(
row, colIdx2));
4768 for (
index_type col = 0; col < static_cast<index_type>(shape_.cols); ++col)
4770 std::swap(
operator()(rowIdx1, col),
operator()(rowIdx2, col));
4786 void tofile(
const std::string& inFilename)
const
4802 void tofile(
const std::string& inFilename,
const char inSep)
const
4806 std::filesystem::path f(inFilename);
4807 if (!f.has_extension())
4809 f.replace_extension(
"txt");
4812 std::ofstream ofile(f.c_str());
4819 for (
auto value : *
this)
4822 if (counter++ != size_ - 1)
4867 if (numElements == 0)
4916 rowStart += inOffset;
4921 colStart += inOffset;
4932 if (rowStart >= shape_.rows || colStart >= shape_.cols)
4941 if (col >= shape_.cols)
4961 self_type transArray(shape_.cols, shape_.rows);
4964 for (
uint32 col = 0; col < shape_.cols; ++col)
4987 allocator_type allocator_{};
4988 Shape shape_{ 0, 0 };
4989 size_type size_{ 0 };
4990 Endian endianess_{ Endian::NATIVE };
4991 pointer array_{
nullptr };
4992 bool ownsPtr_{
false };
4998 void deleteArray() noexcept
5000 if (ownsPtr_ && array_ !=
nullptr)
5002 allocator_.deallocate(array_, size_);
5006 shape_.rows = shape_.cols = 0;
5009 endianess_ = Endian::NATIVE;
5020 array_ = allocator_.allocate(size_);
5031 void newArray(
const Shape& inShape)
5036 size_ = inShape.size();
5043 template<
typename dtype,
class Alloc_>
5048 std::vector<size_type> rowIndices;
5049 std::vector<size_type> colIndices;
5053 for (
uint32 col = 0; col < shape_.cols; ++col)
5057 rowIndices.push_back(
row);
5058 colIndices.push_back(col);
#define THROW_RUNTIME_ERROR(msg)
Definition Error.hpp:40
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_VALID_DTYPE(dtype)
Definition StaticAsserts.hpp:35
#define STATIC_ASSERT_FLOAT(dtype)
Definition StaticAsserts.hpp:50
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition StaticAsserts.hpp:56
#define STATIC_ASSERT_INTEGER(dtype)
Definition StaticAsserts.hpp:43
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
Custom column iterator for NdArray.
Definition NdArrayIterators.hpp:813
Custom column const_iterator for NdArray.
Definition NdArrayIterators.hpp:487
Custom const_iterator for NdArray.
Definition NdArrayIterators.hpp:41
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:135
NdArray(pointer inPtr, UIntType size, PointerPolicy policy)
Definition NdArrayCore.hpp:576
const_reverse_column_iterator rcolbegin() const noexcept
Definition NdArrayCore.hpp:1569
size_type dimSize(Axis inAxis) const noexcept
Definition NdArrayCore.hpp:2756
NdArray< size_type > toIndices(Slice inSlice, Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:4840
self_type operator[](Slice inSlice) const
Definition NdArrayCore.hpp:819
self_type max(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:3117
size_type size() const noexcept
Definition NdArrayCore.hpp:4600
reverse_iterator rbegin() noexcept
Definition NdArrayCore.hpp:1465
self_type at(index_type inRowIndex, const Slice &inColSlice) const
Definition NdArrayCore.hpp:1193
self_type columns(const NdArray< size_type > &inCols) const
Definition NdArrayCore.hpp:2496
self_type & put(const RowIndices &inRowIndices, const ColIndices &inColIndices, const self_type &inValues)
Definition NdArrayCore.hpp:4040
self_type & resizeSlow(size_type inNumRows, size_type inNumCols)
Definition NdArrayCore.hpp:4479
self_type & put(const Slice &inRowSlice, const ColIndices &inColIndices, const value_type &inValue)
Definition NdArrayCore.hpp:3934
self_type & zeros() noexcept
Definition NdArrayCore.hpp:4977
self_type & ones() noexcept
Definition NdArrayCore.hpp:3563
const_iterator cbegin() const noexcept
Definition NdArrayCore.hpp:1361
self_type at(const RowIndices &rowIndices, const ColIndices &colIndices) const
Definition NdArrayCore.hpp:1269
const_column_iterator ccolbegin(size_type inCol) const
Definition NdArrayCore.hpp:1450
NdArrayConstColumnIterator< dtype, size_type, const_pointer, difference_type > const_column_iterator
Definition NdArrayCore.hpp:162
NdArray< bool > contains(value_type inValue, Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:2517
const_pointer data() const noexcept
Definition NdArrayCore.hpp:2682
iterator end() noexcept
Definition NdArrayCore.hpp:1619
self_type & swapCols(index_type colIdx1, index_type colIdx2) noexcept
Definition NdArrayCore.hpp:4748
NdArray(const std::initializer_list< std::initializer_list< dtype > > &inList)
Definition NdArrayCore.hpp:235
reference at(index_type inRowIndex, index_type inColIndex)
Definition NdArrayCore.hpp:1064
self_type & put(const RowIndices &inRowIndices, const ColIndices &inColIndices, const value_type &inValue)
Definition NdArrayCore.hpp:3890
self_type repeat(const Shape &inRepeatShape) const
Definition NdArrayCore.hpp:4312
self_type at(Slice rowSlice, const Indices &colIndices) const
Definition NdArrayCore.hpp:1252
reference back(size_type row)
Definition NdArrayCore.hpp:2392
iterator end(size_type inRow)
Definition NdArrayCore.hpp:1631
self_type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) const
Definition NdArrayCore.hpp:976
void tofile(const std::string &inFilename, const char inSep) const
Definition NdArrayCore.hpp:4802
const_column_iterator ccolbegin() const noexcept
Definition NdArrayCore.hpp:1438
NdArray(std::array< dtype, ArraySize > &inArray, PointerPolicy policy=PointerPolicy::COPY)
Definition NdArrayCore.hpp:270
NdArray(const std::deque< std::deque< dtype > > &in2dDeque)
Definition NdArrayCore.hpp:465
self_type & reshape(size_type inSize)
Definition NdArrayCore.hpp:4347
typename AllocTraits::pointer pointer
Definition NdArrayCore.hpp:148
self_type transpose() const
Definition NdArrayCore.hpp:4959
reverse_iterator rbegin(size_type inRow)
Definition NdArrayCore.hpp:1477
NdArray(std::vector< dtype > &inVector, PointerPolicy policy=PointerPolicy::COPY)
Definition NdArrayCore.hpp:344
NdArray< size_type > argsort(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:2189
const_reverse_column_iterator rcolend() const noexcept
Definition NdArrayCore.hpp:1877
self_type rows(const NdArray< size_type > &inRows) const
Definition NdArrayCore.hpp:4566
const dtype & const_reference
Definition NdArrayCore.hpp:151
bool issquare() const noexcept
Definition NdArrayCore.hpp:3085
NdArrayIterator< dtype, pointer, difference_type > iterator
Definition NdArrayCore.hpp:156
bool isflat() const noexcept
Definition NdArrayCore.hpp:3021
Endian endianess() const noexcept
Definition NdArrayCore.hpp:2868
self_type dot(const self_type &inOtherArray) const
Definition NdArrayCore.hpp:2791
void tofile(const std::string &inFilename) const
Definition NdArrayCore.hpp:4786
const_reverse_column_iterator crcolbegin() const noexcept
Definition NdArrayCore.hpp:1592
self_type & swapRows(index_type rowIdx1, index_type rowIdx2) noexcept
Definition NdArrayCore.hpp:4766
const_reverse_column_iterator crcolend(size_type inCol) const
Definition NdArrayCore.hpp:1912
size_type numCols() const noexcept
Definition NdArrayCore.hpp:3541
column_iterator colbegin(size_type inCol)
Definition NdArrayCore.hpp:1400
NdArrayColumnIterator< dtype, size_type, pointer, difference_type > column_iterator
Definition NdArrayCore.hpp:161
self_type median(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:3207
const_reference at(index_type inRowIndex, index_type inColIndex) const
Definition NdArrayCore.hpp:1077
self_type at(const Slice &inSlice) const
Definition NdArrayCore.hpp:1107
NdArray< bool > none(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:3487
pointer data() noexcept
Definition NdArrayCore.hpp:2672
bool isempty() const noexcept
Definition NdArrayCore.hpp:3008
column_iterator colbegin() noexcept
Definition NdArrayCore.hpp:1388
NdArray(std::vector< std::array< dtype, Dim1Size > > &in2dArray, PointerPolicy policy=PointerPolicy::COPY)
Definition NdArrayCore.hpp:412
const_reference front(size_type row) const
Definition NdArrayCore.hpp:2958
reverse_column_iterator rcolend(size_type inCol)
Definition NdArrayCore.hpp:1862
self_type column(size_type inColumn) const
Definition NdArrayCore.hpp:2484
self_type prod(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:3679
NdArray(Iterator inFirst, Iterator inLast)
Definition NdArrayCore.hpp:517
reference at(index_type inIndex)
Definition NdArrayCore.hpp:1030
const Shape & shape() const noexcept
Definition NdArrayCore.hpp:4587
reverse_column_iterator rcolbegin() noexcept
Definition NdArrayCore.hpp:1542
self_type at(const Indices &inIndices) const
Definition NdArrayCore.hpp:1137
NdArrayConstIterator< dtype, const_pointer, difference_type > const_iterator
Definition NdArrayCore.hpp:157
const_iterator cbegin(size_type inRow) const
Definition NdArrayCore.hpp:1373
const_column_iterator ccolend(size_type inCol) const
Definition NdArrayCore.hpp:1835
self_type at(index_type rowIndex, const Indices &colIndices) const
Definition NdArrayCore.hpp:1237
self_type & resizeFast(size_type inNumRows, size_type inNumCols)
Definition NdArrayCore.hpp:4447
const_iterator cend(size_type inRow) const
Definition NdArrayCore.hpp:1681
NdArray< size_type > flatnonzero() const
Definition NdArrayCore.hpp:2897
self_type & byteswap() noexcept
Definition NdArrayCore.hpp:2405
self_type & ravel()
Definition NdArrayCore.hpp:4255
self_type getByIndices(const NdArray< size_type > &inIndices) const
Definition NdArrayCore.hpp:2981
const_reverse_column_iterator rcolend(size_type inCol) const
Definition NdArrayCore.hpp:1889
NdArray(const std::vector< std::vector< dtype > > &in2dVector)
Definition NdArrayCore.hpp:378
self_type & partition(size_type inKth, Axis inAxis=Axis::NONE)
Definition NdArrayCore.hpp:3597
self_type & put(const Indices &inRowIndices, index_type inColIndex, const value_type &inValue)
Definition NdArrayCore.hpp:3967
const_iterator end(size_type inRow) const
Definition NdArrayCore.hpp:1658
self_type flatten() const
Definition NdArrayCore.hpp:2923
self_type & replace(value_type oldValue, value_type newValue)
Definition NdArrayCore.hpp:4324
reference back() noexcept
Definition NdArrayCore.hpp:2370
const_reverse_column_iterator crcolend() const noexcept
Definition NdArrayCore.hpp:1900
const_reference back(size_type row) const
Definition NdArrayCore.hpp:2381
reverse_column_iterator rcolbegin(size_type inCol)
Definition NdArrayCore.hpp:1554
self_type & put(Slice inRowSlice, Slice inColSlice, const self_type &inValues)
Definition NdArrayCore.hpp:4129
iterator begin(size_type inRow)
Definition NdArrayCore.hpp:1323
const_reverse_iterator rend() const noexcept
Definition NdArrayCore.hpp:1723
self_type copy() const
Definition NdArrayCore.hpp:2558
self_type round(uint8 inNumDecimals=0) const
Definition NdArrayCore.hpp:4533
std::vector< dtype > toStlVector() const
Definition NdArrayCore.hpp:4889
self_type swapaxes() const
Definition NdArrayCore.hpp:4735
const_reverse_column_iterator rcolbegin(size_type inCol) const
Definition NdArrayCore.hpp:1581
typename AllocTraits::difference_type difference_type
Definition NdArrayCore.hpp:154
const_iterator end() const noexcept
Definition NdArrayCore.hpp:1646
NdArray< dtypeOut > astype() const
Definition NdArrayCore.hpp:2253
self_type & put(index_type inRowIndex, const Slice &inColSlice, const self_type &inValues)
Definition NdArrayCore.hpp:4198
bool ownsInternalData() noexcept
Definition NdArrayCore.hpp:3577
self_type operator[](const NdArray< bool > &inMask) const
Definition NdArrayCore.hpp:831
self_type & fill(value_type inFillValue) noexcept
Definition NdArrayCore.hpp:2884
column_iterator colend() noexcept
Definition NdArrayCore.hpp:1773
NdArray(std::initializer_list< dtype > inList)
Definition NdArrayCore.hpp:218
self_type at(const Indices &rowIndices, Slice colSlice) const
Definition NdArrayCore.hpp:1223
const_reference back() const noexcept
Definition NdArrayCore.hpp:2359
std::pair< NdArray< size_type >, NdArray< size_type > > nonzero() const
Definition NdArrayCore.hpp:5044
self_type diagonal(index_type inOffset=0, Axis inAxis=Axis::ROW) const
Definition NdArrayCore.hpp:2711
self_type & put(index_type inRowIndex, const Indices &inColIndices, const self_type &inValues)
Definition NdArrayCore.hpp:4181
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition NdArrayCore.hpp:159
self_type at(const Slice &inRowSlice, index_type inColIndex) const
Definition NdArrayCore.hpp:1179
NdArray(const_pointer inPtr, UIntType1 numRows, UIntType2 numCols)
Definition NdArrayCore.hpp:554
NdArray< bool > any(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:1975
NdArray(const self_type &inOtherArray)
Definition NdArrayCore.hpp:629
NdArray(self_type &&inOtherArray) noexcept
Definition NdArrayCore.hpp:647
uint64 nbytes() const noexcept
Definition NdArrayCore.hpp:3309
NdArray< size_type > argmax(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:2020
self_type at(const NdArray< bool > &inMask) const
Definition NdArrayCore.hpp:1119
NdArray(const std::list< dtype > &inList)
Definition NdArrayCore.hpp:497
self_type & put(const Indices &inRowIndices, index_type inColIndex, const self_type &inValues)
Definition NdArrayCore.hpp:4146
const_reference front() const noexcept
Definition NdArrayCore.hpp:2936
~NdArray() noexcept
Definition NdArrayCore.hpp:664
Slice rSlice(index_type inStartIdx=0, size_type inStepSize=1) const
Definition NdArrayCore.hpp:1018
reference front() noexcept
Definition NdArrayCore.hpp:2947
self_type & put(const Slice &inRowSlice, index_type inColIndex, const self_type &inValues)
Definition NdArrayCore.hpp:4163
self_type & put(Slice inRowSlice, const ColIndices &inColIndices, const self_type &inValues)
Definition NdArrayCore.hpp:4113
self_type & put(const Slice &inRowSlice, index_type inColIndex, const value_type &inValue)
Definition NdArrayCore.hpp:3984
NdArray(size_type inNumRows, size_type inNumCols)
Definition NdArrayCore.hpp:192
self_type & putMask(const NdArray< bool > &inMask, const value_type &inValue)
Definition NdArrayCore.hpp:4211
Allocator allocator_type
Definition NdArrayCore.hpp:147
self_type & nans() noexcept
Definition NdArrayCore.hpp:3292
NdArray(pointer inPtr, UIntType1 numRows, UIntType2 numCols, PointerPolicy policy)
Definition NdArrayCore.hpp:595
void print() const
Definition NdArrayCore.hpp:3663
const_reverse_column_iterator crcolbegin(size_type inCol) const
Definition NdArrayCore.hpp:1604
self_type & reshape(const Shape &inShape)
Definition NdArrayCore.hpp:4432
size_type numRows() const noexcept
Definition NdArrayCore.hpp:3553
reverse_iterator rend(size_type inRow)
Definition NdArrayCore.hpp:1708
NdArray(size_type inSquareSize)
Definition NdArrayCore.hpp:178
self_type at(const Indices &rowIndices, index_type colIndex) const
Definition NdArrayCore.hpp:1208
reverse_iterator rend() noexcept
Definition NdArrayCore.hpp:1696
const_reverse_iterator rend(size_type inRow) const
Definition NdArrayCore.hpp:1735
typename AllocTraits::const_pointer const_pointer
Definition NdArrayCore.hpp:149
self_type & put(const Indices &inIndices, const self_type &inValues)
Definition NdArrayCore.hpp:3825
self_type & operator=(value_type inValue) noexcept
Definition NdArrayCore.hpp:710
const_reverse_iterator crbegin() const noexcept
Definition NdArrayCore.hpp:1515
NdArray(const_pointer inPtr, UIntType size)
Definition NdArrayCore.hpp:537
const_column_iterator colend(size_type inCol) const
Definition NdArrayCore.hpp:1812
std::reverse_iterator< iterator > reverse_iterator
Definition NdArrayCore.hpp:158
const_reverse_iterator rbegin(size_type inRow) const
Definition NdArrayCore.hpp:1504
self_type operator[](const Indices &inIndices) const
Definition NdArrayCore.hpp:845
const_iterator cend() const noexcept
Definition NdArrayCore.hpp:1669
self_type & resizeSlow(const Shape &inShape)
Definition NdArrayCore.hpp:4518
self_type & operator=(self_type &&rhs) noexcept
Definition NdArrayCore.hpp:727
std::string str() const
Definition NdArrayCore.hpp:4658
std::reverse_iterator< const_column_iterator > const_reverse_column_iterator
Definition NdArrayCore.hpp:164
self_type cumsum(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:2624
NdArray< bool > all(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:1931
self_type & resizeFast(const Shape &inShape)
Definition NdArrayCore.hpp:4462
self_type & put(index_type inRowIndex, const Indices &inColIndices, const value_type &inValue)
Definition NdArrayCore.hpp:4002
reference front(size_type row)
Definition NdArrayCore.hpp:2969
self_type & put(const RowIndices &inRowIndices, Slice inColSlice, const self_type &inValues)
Definition NdArrayCore.hpp:4096
NdArray(std::array< std::array< dtype, Dim1Size >, Dim0Size > &in2dArray, PointerPolicy policy=PointerPolicy::COPY)
Definition NdArrayCore.hpp:306
self_type repeat(size_type inNumRows, size_type inNumCols) const
Definition NdArrayCore.hpp:4271
const_iterator begin(size_type inRow) const
Definition NdArrayCore.hpp:1350
iterator begin() noexcept
Definition NdArrayCore.hpp:1311
const_column_iterator colbegin() const noexcept
Definition NdArrayCore.hpp:1415
bool isscalar() const noexcept
Definition NdArrayCore.hpp:3032
std::reverse_iterator< column_iterator > reverse_column_iterator
Definition NdArrayCore.hpp:163
self_type operator()(Slice inRowSlice, Slice inColSlice) const
Definition NdArrayCore.hpp:866
self_type & put(const Slice &inSlice, const value_type &inValue)
Definition NdArrayCore.hpp:3855
self_type newbyteorder(Endian inEndianess) const
Definition NdArrayCore.hpp:3324
value_type item() const
Definition NdArrayCore.hpp:3098
const_reference at(index_type inIndex) const
Definition NdArrayCore.hpp:1042
self_type & reshape(index_type inNumRows, index_type inNumCols)
Definition NdArrayCore.hpp:4378
const_column_iterator colend() const noexcept
Definition NdArrayCore.hpp:1800
self_type row(size_type inRow) const
Definition NdArrayCore.hpp:4554
self_type operator()(const Indices &rowIndices, index_type colIndex) const
Definition NdArrayCore.hpp:911
self_type at(const Slice &inRowSlice, const Slice &inColSlice) const
Definition NdArrayCore.hpp:1166
self_type operator()(Slice inRowSlice, index_type inColIndex) const
Definition NdArrayCore.hpp:880
const_reverse_iterator crend() const noexcept
Definition NdArrayCore.hpp:1746
self_type operator()(index_type rowIndex, const Indices &colIndices) const
Definition NdArrayCore.hpp:942
NdArray< dtype, Allocator > self_type
Definition NdArrayCore.hpp:145
const_column_iterator colbegin(size_type inCol) const
Definition NdArrayCore.hpp:1427
self_type & put(const Slice &inSlice, const self_type &inValues)
Definition NdArrayCore.hpp:3870
self_type & put(const Indices &inIndices, const value_type &inValue)
Definition NdArrayCore.hpp:3804
self_type cumprod(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:2572
const_column_iterator ccolend() const noexcept
Definition NdArrayCore.hpp:1823
reference operator()(index_type inRowIndex, index_type inColIndex) noexcept
Definition NdArrayCore.hpp:783
self_type operator()(index_type inRowIndex, Slice inColSlice) const
Definition NdArrayCore.hpp:895
reverse_column_iterator rcolend() noexcept
Definition NdArrayCore.hpp:1850
const_reverse_iterator rbegin() const noexcept
Definition NdArrayCore.hpp:1492
NdArray(const std::deque< dtype > &inDeque)
Definition NdArrayCore.hpp:448
void dump(const std::string &inFilename) const
Definition NdArrayCore.hpp:2841
dtype & reference
Definition NdArrayCore.hpp:150
self_type & put(const RowIndices &inRowIndices, const Slice &inColSlice, const value_type &inValue)
Definition NdArrayCore.hpp:3917
self_type & put(index_type inRowIndex, const Slice &inColSlice, const value_type &inValue)
Definition NdArrayCore.hpp:4019
value_type trace(size_type inOffset=0, Axis inAxis=Axis::ROW) const noexcept
Definition NdArrayCore.hpp:4906
pointer dataRelease() noexcept
Definition NdArrayCore.hpp:2694
self_type ptp(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:3723
self_type clip(value_type inMin, value_type inMax) const
Definition NdArrayCore.hpp:2445
self_type getByMask(const NdArray< bool > &inMask) const
Definition NdArrayCore.hpp:2995
uint32 size_type
Definition NdArrayCore.hpp:152
NdArray< bool > issorted(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:3044
self_type & operator=(const self_type &rhs)
Definition NdArrayCore.hpp:686
const_iterator begin() const noexcept
Definition NdArrayCore.hpp:1338
NdArray< size_type > argpartition(size_type inKth, Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:2116
column_iterator colend(size_type inCol)
Definition NdArrayCore.hpp:1785
NdArray< size_type > argmin(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:2067
const_reference operator[](index_type inIndex) const noexcept
Definition NdArrayCore.hpp:765
self_type operator()(Slice rowSlice, const Indices &colIndices) const
Definition NdArrayCore.hpp:958
const_reference operator()(index_type inRowIndex, index_type inColIndex) const noexcept
Definition NdArrayCore.hpp:796
self_type min(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:3161
self_type & putMask(const NdArray< bool > &inMask, const self_type &inValues)
Definition NdArrayCore.hpp:4228
dtype value_type
Definition NdArrayCore.hpp:146
reference operator[](index_type inIndex) noexcept
Definition NdArrayCore.hpp:753
Slice cSlice(index_type inStartIdx=0, size_type inStepSize=1) const
Definition NdArrayCore.hpp:1004
self_type & sort(Axis inAxis=Axis::NONE)
Definition NdArrayCore.hpp:4614
self_type & put(const Slice &inRowSlice, const Slice &inColSlice, const value_type &inValue)
Definition NdArrayCore.hpp:3950
const_reverse_iterator crend(size_type inRow) const
Definition NdArrayCore.hpp:1758
const_reverse_iterator crbegin(size_type inRow) const
Definition NdArrayCore.hpp:1527
int32 index_type
Definition NdArrayCore.hpp:153
NdArray(const Shape &inShape)
Definition NdArrayCore.hpp:205
self_type sum(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:4694
self_type operator()(const Indices &rowIndices, Slice colSlice) const
Definition NdArrayCore.hpp:927
self_type & put(index_type inRow, index_type inCol, const value_type &inValue)
Definition NdArrayCore.hpp:3786
self_type & put(index_type inIndex, const value_type &inValue)
Definition NdArrayCore.hpp:3769
Custom iterator for NdArray.
Definition NdArrayIterators.hpp:313
A Shape Class for NdArrays.
Definition Core/shape.hpp:41
uint32 rows
Definition Core/shape.hpp:44
uint32 cols
Definition Core/shape.hpp:45
A Class for slicing into NdArrays.
Definition Slice.hpp:45
int32 step
Definition Slice.hpp:50
int32 start
Definition Slice.hpp:48
uint32 numElements(uint32 inArraySize)
Definition Slice.hpp:195
const double nan
NaN.
Definition Core/Constants.hpp:41
bool isLittleEndian() noexcept
Definition Endian.hpp:44
dtype byteSwap(dtype value) noexcept
Definition Endian.hpp:64
bool any_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition StlAlgorithms.hpp:77
T transform_reduce(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, T init)
Definition StlAlgorithms.hpp:825
void sort(RandomIt first, RandomIt last) noexcept
Definition StlAlgorithms.hpp:697
bool none_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition StlAlgorithms.hpp:406
ForwardIt max_element(ForwardIt first, ForwardIt last) noexcept
Definition StlAlgorithms.hpp:286
void stable_sort(RandomIt first, RandomIt last) noexcept
Definition StlAlgorithms.hpp:735
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition StlAlgorithms.hpp:776
bool all_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition StlAlgorithms.hpp:56
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition StlAlgorithms.hpp:226
InputIt find(InputIt first, InputIt last, const T &value) noexcept
Definition StlAlgorithms.hpp:206
void replace(ForwardIt first, ForwardIt last, const T &oldValue, const T &newValue) noexcept
Definition StlAlgorithms.hpp:469
std::pair< ForwardIt, ForwardIt > minmax_element(ForwardIt first, ForwardIt last) noexcept
Definition StlAlgorithms.hpp:365
bool is_sorted(ForwardIt first, ForwardIt last) noexcept
Definition StlAlgorithms.hpp:246
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition StlAlgorithms.hpp:98
void nth_element(RandomIt first, RandomIt nth, RandomIt last) noexcept
Definition StlAlgorithms.hpp:426
ForwardIt min_element(ForwardIt first, ForwardIt last) noexcept
Definition StlAlgorithms.hpp:325
void fill(ForwardIt first, ForwardIt last, const T &value) noexcept
Definition StlAlgorithms.hpp:184
Definition NdArrayCore.hpp:67
constexpr bool is_ndarray_signed_int_v
Definition NdArrayCore.hpp:120
constexpr bool is_ndarray_int_v
Definition NdArrayCore.hpp:93
std::enable_if_t< is_ndarray_int_v< T >, int > ndarray_int_concept
Definition NdArrayCore.hpp:127
std::string num2str(dtype inNumber)
Definition num2str.hpp:44
dtype power(dtype inValue, uint8 inPower) noexcept
Definition Utils/power.hpp:44
std::string value2str(dtype inValue)
Definition value2str.hpp:45
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition essentiallyEqual.hpp:47
Definition Cartesian.hpp:39
std::uint64_t uint64
Definition Types.hpp:39
std::uint8_t uint8
Definition Types.hpp:42
Axis
Enum To describe an axis.
Definition Enums.hpp:36
@ ROW
Definition Enums.hpp:38
@ COL
Definition Enums.hpp:39
@ NONE
Definition Enums.hpp:37
std::complex< Out > complex_cast(const std::complex< In > &value) noexcept
Definition StdComplexOperators.hpp:111
std::int32_t int32
Definition Types.hpp:36
Endian
Enum for endianess.
Definition Enums.hpp:46
@ LITTLE
Definition Enums.hpp:49
@ BIG
Definition Enums.hpp:48
@ NATIVE
Definition Enums.hpp:47
std::int64_t int64
Definition Types.hpp:35
PointerPolicy
Policy for NdArray constructor that takes in a pointer to data.
Definition Enums.hpp:56
@ SHELL
Definition Enums.hpp:58
@ COPY
Definition Enums.hpp:57
std::uint32_t uint32
Definition Types.hpp:40
static constexpr bool value
Definition NdArrayCore.hpp:85
Definition NdArrayCore.hpp:74
static constexpr bool value
Definition NdArrayCore.hpp:112
Definition NdArrayCore.hpp:101