34 #include <forward_list>
36 #include <initializer_list>
44 #include <type_traits>
85 template<
typename dtype,
typename Allocator>
88 static constexpr
bool value = std::is_integral_v<dtype>;
112 template<
typename dtype,
typename Allocator>
115 static constexpr
bool value = std::is_signed_v<dtype>;
136 template<
typename dtype,
class Allocator = std::allocator<dtype>>
140 STATIC_ASSERT_VALID_DTYPE(dtype);
141 static_assert(std::is_same_v<dtype, typename Allocator::value_type>,
142 "value_type and Allocator::value_type must match");
144 using AllocType =
typename std::allocator_traits<Allocator>::template rebind_alloc<dtype>;
145 using AllocTraits = std::allocator_traits<AllocType>;
151 using pointer =
typename AllocTraits::pointer;
182 shape_(inSquareSize, inSquareSize),
183 size_(inSquareSize * inSquareSize)
196 shape_(inNumRows, inNumCols),
197 size_(inNumRows * inNumCols)
221 NdArray(std::initializer_list<dtype> inList) :
222 shape_(1, static_cast<
uint32>(inList.
size())),
238 NdArray(
const std::initializer_list<std::initializer_list<dtype>>& inList) :
241 for (
const auto& list : inList)
243 if (shape_.
cols == 0)
245 shape_.
cols =
static_cast<uint32>(list.size());
247 else if (list.size() != shape_.
cols)
250 "All rows of the initializer list needs to have the same number of elements");
254 size_ = shape_.
size();
257 for (
const auto& list : inList)
273 template<
size_t ArraySize, std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
274 NdArray(std::array<dtype, ArraySize>& inArray,
bool copy =
true) :
275 shape_(1, static_cast<
uint32>(ArraySize)),
288 array_ = inArray.data();
301 template<
size_t Dim0Size,
size_t Dim1Size>
302 NdArray(std::array<std::array<dtype, Dim1Size>, Dim0Size>& in2dArray,
bool copy =
true) :
303 shape_(static_cast<
uint32>(Dim0Size), static_cast<
uint32>(Dim1Size)),
311 const auto start = in2dArray.front().begin();
317 array_ = in2dArray.front().data();
330 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
332 shape_(1, static_cast<
uint32>(inVector.
size())),
345 array_ = inVector.data();
356 explicit NdArray(
const std::vector<std::vector<dtype>>& in2dVector) :
357 shape_(static_cast<
uint32>(in2dVector.
size()), 0)
359 for (
const auto&
row : in2dVector)
361 if (shape_.
cols == 0)
371 size_ = shape_.
size();
374 auto currentPosition =
begin();
375 for (
const auto&
row : in2dVector)
378 currentPosition += shape_.
cols;
390 template<
size_t Dim1Size>
391 NdArray(std::vector<std::array<dtype, Dim1Size>>& in2dArray,
bool copy =
true) :
392 shape_(static_cast<
uint32>(in2dArray.
size()), static_cast<
uint32>(Dim1Size)),
400 const auto start = in2dArray.front().begin();
406 array_ = in2dArray.front().data();
417 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
418 explicit NdArray(
const std::deque<dtype>& inDeque) :
419 shape_(1, static_cast<
uint32>(inDeque.
size())),
435 explicit NdArray(
const std::deque<std::deque<dtype>>& in2dDeque) :
436 shape_(static_cast<
uint32>(in2dDeque.
size()), 0)
438 for (
const auto&
row : in2dDeque)
440 if (shape_.
cols == 0)
450 size_ = shape_.
size();
453 auto currentPosition =
begin();
454 for (
const auto&
row : in2dDeque)
457 currentPosition += shape_.
cols;
467 explicit NdArray(
const std::list<dtype>& inList) :
468 shape_(1, static_cast<
uint32>(inList.
size())),
485 template<
typename Iterator,
486 std::enable_if_t<std::is_same_v<typename std::iterator_traits<Iterator>::value_type, dtype>,
int> = 0>
488 shape_(1, static_cast<
uint32>(std::distance(inFirst, inLast))),
511 if (inPtr !=
nullptr && size_ > 0)
526 template<
typename UIntType1,
528 std::enable_if_t<!std::is_same_v<UIntType1, bool>,
int> = 0,
529 std::enable_if_t<!std::is_same_v<UIntType2, bool>,
int> = 0>
535 if (inPtr !=
nullptr && size_ > 0)
551 template<
typename BoolType, std::enable_if_t<std::is_same_v<BoolType,
bool>,
int> = 0>
556 ownsPtr_(takeOwnership)
571 template<
typename BoolType, std::enable_if_t<std::is_same_v<BoolType,
bool>,
int> = 0>
576 ownsPtr_(takeOwnership)
587 shape_(inOtherArray.shape_),
588 size_(inOtherArray.size_),
589 endianess_(inOtherArray.endianess_)
605 shape_(inOtherArray.shape_),
606 size_(inOtherArray.size_),
607 endianess_(inOtherArray.endianess_),
608 array_(inOtherArray.array_),
609 ownsPtr_(inOtherArray.ownsPtr_)
611 inOtherArray.shape_.rows = inOtherArray.shape_.cols = 0;
612 inOtherArray.size_ = 0;
613 inOtherArray.ownsPtr_ =
false;
614 inOtherArray.array_ =
nullptr;
639 newArray(rhs.shape_);
640 endianess_ = rhs.endianess_;
659 if (array_ !=
nullptr)
681 endianess_ = rhs.endianess_;
683 ownsPtr_ = rhs.ownsPtr_;
685 rhs.shape_.rows = rhs.shape_.cols = rhs.size_ = 0;
686 rhs.array_ =
nullptr;
687 rhs.ownsPtr_ =
false;
702 return const_cast<reference>(
const_cast<const self_type*
>(
this)->
operator[](inIndex));
719 return array_[inIndex];
732 return const_cast<reference>(
const_cast<const self_type*
>(
this)->
operator()(inRowIndex, inColIndex));
747 inRowIndex += shape_.
rows;
752 inColIndex += shape_.
cols;
755 return array_[inRowIndex * shape_.
cols + inColIndex];
791 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
796 for (
auto& index : inIndices)
857 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
873 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
888 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
904 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
919 template<
typename RowIndices,
925 self_type returnArray(rowIndices.size(), colIndices.size());
928 for (
auto rowIter = rowIndices.begin(); rowIter != rowIndices.end(); ++rowIter)
931 for (
auto colIter = colIndices.begin(); colIter != colIndices.end(); ++colIter)
933 returnArray(rowCounter, colCounter++) =
operator()(*rowIter, *colIter);
953 return Slice(inStartIdx, shape_.
cols, inStepSize);
967 return Slice(inStartIdx, shape_.
rows, inStepSize);
996 errStr +=
" is out of bounds for array of size " +
utils::num2str(size_) +
".";
1031 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
rows) +
".";
1039 std::string errStr =
"Column index " +
utils::num2str(inColIndex);
1040 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
cols) +
".";
1068 if (inMask.
shape() != shape_)
1083 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1090 auto indexSigned = static_cast<index_type>(index);
1091 if (indexSigned < 0)
1093 indexSigned += size_;
1096 if (indexSigned < 0 || indexSigned >
static_cast<index_type>(size_ - 1))
1129 return at(toIndices(inRowSlice,
Axis::ROW), colIndices);
1143 return at(rowIndices, toIndices(inColSlice,
Axis::COL));
1154 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1158 return at(rowIndices, colIndices);
1169 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1172 return at(rowIndices, toIndices(colSlice,
Axis::COL));
1183 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1187 return at(rowIndices, colIndices);
1198 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1201 return at(toIndices(rowSlice,
Axis::ROW), colIndices);
1212 template<
typename RowIndices,
1213 typename ColIndices,
1216 [[nodiscard]]
self_type at(
const RowIndices& rowIndices,
const ColIndices& colIndices)
const
1222 auto rowSigned = static_cast<index_type>(row);
1225 rowSigned += shape_.rows;
1228 if (rowSigned < 0 || rowSigned >
static_cast<index_type>(shape_.rows - 1))
1230 THROW_INVALID_ARGUMENT_ERROR(
"Row index exceeds matrix dimensions");
1238 auto colSigned = static_cast<index_type>(col);
1241 colSigned += shape_.cols;
1244 if (colSigned < 0 || colSigned >
static_cast<index_type
>(shape_.cols - 1))
1246 THROW_INVALID_ARGUMENT_ERROR(
"Column index exceeds matrix dimensions");
1250 return operator()(rowIndices, colIndices);
1272 if (inRow >= shape_.rows)
1277 return begin() += (inRow * shape_.cols);
1299 return cbegin(inRow);
1322 if (inRow >= shape_.rows)
1327 return cbegin() += (inRow * shape_.cols);
1349 if (inCol >= shape_.cols)
1354 return colbegin() += (inCol * shape_.rows);
1376 return ccolbegin(inCol);
1399 if (inCol >= shape_.cols)
1404 return ccolbegin() += (inCol * shape_.rows);
1426 if (inRow >= shape_.rows)
1431 return rbegin() += (shape_.rows - inRow - 1) * shape_.cols;
1453 return crbegin(inRow);
1476 if (inRow >= shape_.rows)
1481 return crbegin() += (shape_.rows - inRow - 1) * shape_.cols;
1503 if (inCol >= shape_.cols)
1508 return rcolbegin() += (shape_.cols - inCol - 1) * shape_.rows;
1518 return crcolbegin();
1530 return crcolbegin(inCol);
1553 if (inCol >= shape_.cols)
1558 return crcolbegin() += (shape_.cols - inCol - 1) * shape_.rows;
1568 return begin() += size_;
1580 if (inRow >= shape_.rows)
1585 return begin(inRow) += shape_.cols;
1618 return cbegin() += size_;
1630 if (inRow >= shape_.rows)
1635 return cbegin(inRow) += shape_.cols;
1645 return rbegin() += size_;
1657 if (inRow >= shape_.rows)
1662 return rbegin(inRow) += shape_.cols;
1684 return crend(inRow);
1695 return crbegin() += size_;
1707 if (inRow >= shape_.rows)
1712 return crbegin(inRow) += shape_.cols;
1722 return colbegin() += size_;
1734 if (inCol >= shape_.cols)
1739 return colbegin(inCol) += shape_.rows;
1761 return ccolend(inCol);
1772 return ccolbegin() += size_;
1784 if (inCol >= shape_.cols)
1789 return ccolbegin(inCol) += shape_.rows;
1799 return rcolbegin() += size_;
1811 if (inCol >= shape_.cols)
1816 return rcolbegin(inCol) += shape_.rows;
1838 return crcolend(inCol);
1849 return crcolbegin() += size_;
1861 if (inCol >= shape_.cols)
1866 return crcolbegin(inCol) += shape_.rows;
1894 for (
uint32 row = 0; row < shape_.rows; ++row)
1938 for (
uint32 row = 0; row < shape_.rows; ++row)
1971 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
1984 for (
size_type row = 0; row < shape_.rows; ++row)
1986 returnArray(0, row) =
static_cast<size_type>(
2018 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
2031 for (
size_type row = 0; row < shape_.rows; ++row)
2033 returnArray(0, row) =
static_cast<size_type>(
2068 std::vector<size_type> idx(size_);
2069 std::iota(idx.begin(), idx.end(), 0);
2072 {
return (*
this)[i1] < (*this)[i2]; };
2080 std::vector<size_type> idx(shape_.cols);
2082 for (
index_type row = 0; row < static_cast<index_type>(shape_.rows); ++row)
2084 std::iota(idx.begin(), idx.end(), 0);
2087 {
return operator()(row, i1) < operator()(row, i2); };
2091 for (
index_type col = 0; col < static_cast<index_type>(shape_.cols); ++col)
2093 returnArray(row, col) = idx[
static_cast<size_type>(col)];
2100 return transpose().argsort(Axis::COL).transpose();
2119 template<
typename dtypeOut,
2120 typename dtype_ = dtype,
2121 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2122 std::enable_if_t<std::is_arithmetic_v<dtype_>,
int> = 0,
2123 std::enable_if_t<std::is_arithmetic_v<dtypeOut>,
int> = 0>
2126 if constexpr (std::is_same_v<dtypeOut, dtype>)
2136 [](dtype value) -> dtypeOut { return static_cast<dtypeOut>(value); });
2151 template<
typename dtypeOut,
2152 typename dtype_ = dtype,
2153 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2154 std::enable_if_t<std::is_arithmetic_v<dtype_>,
int> = 0,
2155 std::enable_if_t<is_complex_v<dtypeOut>,
int> = 0>
2161 {
return std::complex<typename dtypeOut::value_type>(value); };
2177 template<
typename dtypeOut,
2178 typename dtype_ = dtype,
2179 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2180 std::enable_if_t<is_complex_v<dtype_>,
int> = 0,
2181 std::enable_if_t<is_complex_v<dtypeOut>,
int> = 0>
2184 if constexpr (std::is_same_v<dtypeOut, dtype>)
2191 {
return complex_cast<typename dtypeOut::value_type>(value); };
2208 template<
typename dtypeOut,
2209 typename dtype_ = dtype,
2210 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2211 std::enable_if_t<is_complex_v<dtype_>,
int> = 0,
2212 std::enable_if_t<std::is_arithmetic_v<dtypeOut>,
int> = 0>
2217 const auto function = [](
const_reference value) -> dtypeOut {
return static_cast<dtypeOut
>(value.real()); };
2232 return *(cend() - 1);
2243 return *(end() - 1);
2254 return *(cend(row) - 1);
2265 return *(end(row) - 1);
2286 case Endian::NATIVE:
2291 case Endian::LITTLE:
2293 endianess_ = Endian::BIG;
2298 endianess_ = Endian::LITTLE;
2324 [inMin, inMax](dtype value) noexcept -> dtype
2326 #ifdef __cpp_lib_clamp
2327 const auto comparitor = [](dtype lhs, dtype rhs) noexcept -> bool
2328 { return lhs < rhs; };
2330 return std::clamp(value, inMin, inMax, comparitor);
2336 else if (value > inMax)
2357 return operator()(rSlice(), inColumn);
2382 for (
size_type row = 0; row < shape_.rows; ++row)
2391 return transpose().contains(inValue, Axis::COL);
2432 returnArray[0] = front();
2435 returnArray[i] = returnArray[i - 1] * array_[i];
2443 for (
uint32 row = 0; row < shape_.rows; ++row)
2445 returnArray(row, 0) = operator()(row, 0);
2446 for (
uint32 col = 1; col < shape_.cols; ++col)
2448 returnArray(row, col) = returnArray(row, col - 1) * operator()(row, col);
2456 return transpose().cumprod(Axis::COL).transpose();
2484 returnArray[0] = front();
2487 returnArray[i] = returnArray[i - 1] + array_[i];
2495 for (
uint32 row = 0; row < shape_.rows; ++row)
2497 returnArray(row, 0) = operator()(row, 0);
2498 for (
uint32 col = 1; col < shape_.cols; ++col)
2500 returnArray(row, col) = returnArray(row, col - 1) + operator()(row, col);
2508 return transpose().cumsum(Axis::COL).transpose();
2568 std::vector<dtype> diagnolValues;
2570 for (
index_type row = inOffset; row < static_cast<index_type>(shape_.rows); ++row)
2577 if (col >= shape_.cols)
2582 diagnolValues.push_back(
operator()(
static_cast<size_type>(row), col));
2590 return transpose().diagonal(inOffset, Axis::COL);
2646 if (shape_ == inOtherArray.shape_ && (shape_.rows == 1 || shape_.cols == 1))
2648 dtype dotProduct = std::inner_product(cbegin(), cend(), inOtherArray.
cbegin(), dtype{ 0 });
2652 if (shape_.cols == inOtherArray.shape_.
rows)
2655 self_type returnArray(shape_.rows, inOtherArray.shape_.
cols);
2656 auto otherArrayT = inOtherArray.
transpose();
2658 for (
uint32 i = 0; i < shape_.rows; ++i)
2660 for (
uint32 j = 0;
j < otherArrayT.shape_.rows; ++
j)
2663 std::inner_product(otherArrayT.cbegin(
j), otherArrayT.cend(
j), cbegin(i), dtype{ 0 });
2673 errStr +=
" are not consistent.";
2688 void dump(
const std::string& inFilename)
const
2690 std::filesystem::path
f(inFilename);
2691 if (!
f.has_extension())
2693 f.replace_extension(
"bin");
2696 std::ofstream ofile(
f.c_str(), std::ios::binary);
2702 if (array_ !=
nullptr)
2704 ofile.write(
reinterpret_cast<const char*
>(array_), size_ *
sizeof(dtype));
2748 std::vector<size_type> indices;
2750 for (
auto value : *
this)
2754 indices.push_back(idx);
2807 return *cbegin(row);
2830 return operator[](inIndices);
2844 return operator[](inMask);
2870 return !isscalar() && (shape_.rows == 1 || shape_.cols == 1);
2895 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
2906 for (
uint32 row = 0; row < shape_.rows; ++row)
2934 return shape_.issquare();
2968 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
2980 for (
uint32 row = 0; row < shape_.rows; ++row)
3012 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
3024 for (
uint32 row = 0; row < shape_.rows; ++row)
3058 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
3073 copyArray.
begin() + middleIdx,
3077 dtype medianValue = copyArray.array_[middleIdx];
3080 const size_type lhsIndex = middleIdx - 1;
3082 copyArray.
begin() + lhsIndex,
3086 (medianValue + copyArray.array_[lhsIndex]) / dtype{ 2 };
3089 return { medianValue };
3096 const bool isEven = shape_.cols % 2 == 0;
3097 for (
uint32 row = 0; row < shape_.rows; ++row)
3099 const uint32 middleIdx = shape_.cols / 2;
3101 copyArray.
begin(row) + middleIdx,
3105 dtype medianValue = copyArray(row, middleIdx);
3108 const size_type lhsIndex = middleIdx - 1;
3110 copyArray.
begin(row) + lhsIndex,
3113 medianValue = (medianValue + copyArray(row, lhsIndex)) /
3117 returnArray(0, row) = medianValue;
3158 return static_cast<uint64>(
sizeof(dtype) * size_);
3179 case Endian::NATIVE:
3181 switch (inEndianess)
3183 case Endian::NATIVE:
3195 outArray.endianess_ = Endian::BIG;
3200 auto outArray =
NdArray(*
this);
3201 outArray.endianess_ = Endian::BIG;
3205 case Endian::LITTLE:
3209 auto outArray =
NdArray(*
this);
3210 outArray.endianess_ = Endian::LITTLE;
3219 outArray.endianess_ = Endian::LITTLE;
3233 switch (inEndianess)
3235 case Endian::NATIVE:
3243 outArray.endianess_ = Endian::NATIVE;
3248 auto outArray =
NdArray(*
this);
3249 outArray.endianess_ = Endian::NATIVE;
3257 case Endian::LITTLE:
3263 outArray.endianess_ = Endian::LITTLE;
3274 case Endian::LITTLE:
3276 switch (inEndianess)
3278 case Endian::NATIVE:
3282 auto outArray =
NdArray(*
this);
3283 outArray.endianess_ = Endian::NATIVE;
3292 outArray.endianess_ = Endian::NATIVE;
3302 outArray.endianess_ = Endian::BIG;
3305 case Endian::LITTLE:
3350 for (
uint32 row = 0; row < shape_.rows; ++row)
3448 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3449 {
return lhs < rhs; };
3467 if (inKth >= shape_.cols)
3470 errStr +=
") out of bounds (" +
utils::num2str(shape_.cols) +
")";
3474 for (
uint32 row = 0; row < shape_.rows; ++row)
3482 if (inKth >= shape_.rows)
3485 errStr +=
") out of bounds (" +
utils::num2str(shape_.rows) +
")";
3490 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3493 transposedArray.
begin(row) + inKth,
3494 transposedArray.
end(row),
3534 dtype product = std::accumulate(cbegin(), cend(), dtype{ 1 }, std::multiplies<dtype>());
3541 for (
uint32 row = 0; row < shape_.rows; ++row)
3543 returnArray(0, row) =
3544 std::accumulate(cbegin(row), cend(row), dtype{ 1 }, std::multiplies<dtype>());
3574 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
3581 self_type returnArray = { *result.second - *result.first };
3587 for (
uint32 row = 0; row < shape_.rows; ++row)
3590 returnArray(0, row) = *result.second - *result.first;
3618 at(inIndex) = inValue;
3635 at(inRow, inCol) = inValue;
3650 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3653 for (
auto index : inIndices)
3655 put(index, inValue);
3671 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3676 return put(inIndices, inValues.
item());
3678 else if (inIndices.size() != inValues.
size())
3684 for (
auto index : inIndices)
3686 put(index, inValues[counter++]);
3704 return put(toIndices(inSlice, Axis::NONE), inValue);
3719 return put(toIndices(inSlice, Axis::NONE), inValues);
3733 template<
typename RowIndices,
3734 typename ColIndices,
3741 [
this, &inColIndices, &inValue](
const auto row)
3743 stl_algorithms::for_each(inColIndices.begin(),
3745 [this, row, &inValue](const auto col)
3746 { this->put(row, col, inValue); });
3763 template<
typename RowIndices, type_traits::ndarray_
int_concept<RowIndices> = 0>
3766 return put(inRowIndices, toIndices(inColSlice, Axis::COL), inValue);
3780 template<
typename ColIndices, type_traits::ndarray_
int_concept<ColIndices> = 0>
3783 return put(toIndices(inRowSlice, Axis::ROW), inColIndices, inValue);
3799 return put(toIndices(inRowSlice, Axis::ROW), toIndices(inColSlice, Axis::COL), inValue);
3813 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3817 return put(inRowIndices, colIndices, inValue);
3834 return put(toIndices(inRowSlice, Axis::ROW), colIndices, inValue);
3848 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3852 return put(rowIndices, inColIndices, inValue);
3869 return put(rowIndices, toIndices(inColSlice, Axis::COL), inValue);
3883 template<
typename RowIndices,
3884 typename ColIndices,
3889 std::vector<size_type> indices;
3890 indices.reserve(inRowIndices.size() * inColIndices.size());
3893 [
this, &inColIndices, &indices](
auto row)
3895 if constexpr (std::is_signed_v<decltype(row)>)
3904 THROW_INVALID_ARGUMENT_ERROR(
"row index exceeds matrix dimensions");
3909 [
this, row, &indices](
auto col)
3911 if constexpr (std::is_signed_v<decltype(col)>)
3920 THROW_INVALID_ARGUMENT_ERROR(
3921 "col index exceeds matrix dimensions");
3924 indices.push_back(row * shape_.cols + col);
3928 return put(NdArray<size_type>(indices.data(), indices.size(),
false), inValues);
3942 template<
typename RowIndices, type_traits::ndarray_
int_concept<RowIndices> = 0>
3945 return put(inRowIndices, toIndices(inColSlice, Axis::COL), inValues);
3959 template<
typename ColIndices, type_traits::ndarray_
int_concept<ColIndices> = 0>
3962 return put(toIndices(inRowSlice, Axis::ROW), inColIndices, inValues);
3978 return put(toIndices(inRowSlice, Axis::ROW), toIndices(inColSlice, Axis::COL), inValues);
3992 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3996 return put(inRowIndices, colIndices, inValues);
4013 return put(toIndices(inRowSlice, Axis::ROW), colIndices, inValues);
4027 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
4031 return put(rowIndices, inColIndices, inValues);
4048 return put(rowIndices, toIndices(inColSlice, Axis::COL), inValues);
4060 if (inMask.
shape() != shape_)
4077 if (inMask.
shape() != shape_)
4120 self_type returnArray(shape_.rows * inNumRows, shape_.cols * inNumCols);
4122 for (
size_type row = 0; row < inNumRows; ++row)
4124 for (
size_type col = 0; col < inNumCols; ++col)
4126 std::vector<size_type> indices(shape_.size());
4128 const size_type rowStart = row * shape_.rows;
4129 const size_type colStart = col * shape_.cols;
4131 const size_type rowEnd = (row + 1) * shape_.rows;
4132 const size_type colEnd = (col + 1) * shape_.cols;
4135 for (
size_type rowIdx = rowStart; rowIdx < rowEnd; ++rowIdx)
4137 for (
size_type colIdx = colStart; colIdx < colEnd; ++colIdx)
4139 indices[counter++] = rowIdx * returnArray.shape_.
cols + colIdx;
4192 if (inSize != size_)
4194 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4200 shape_.cols = inSize;
4221 if (size_ % inNumCols == 0)
4223 return reshape(size_ / inNumCols, inNumCols);
4226 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4233 if (size_ % inNumRows == 0)
4235 return reshape(inNumRows, size_ / inNumRows);
4238 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4243 if (
static_cast<size_type>(inNumRows * inNumCols) != size_)
4245 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4250 shape_.rows =
static_cast<size_type>(inNumRows);
4251 shape_.cols =
static_cast<size_type>(inNumCols);
4284 newArray(
Shape(inNumRows, inNumCols));
4316 std::vector<dtype> oldData(size_);
4319 const Shape inShape(inNumRows, inNumCols);
4320 const Shape oldShape = shape_;
4324 for (
uint32 row = 0; row < inShape.
rows; ++row)
4326 for (
uint32 col = 0; col < inShape.
cols; ++col)
4328 if (row >= oldShape.
rows || col >= oldShape.
cols)
4330 operator()(row, col) = dtype{ 0 };
4334 operator()(row, col) = oldData[row * oldShape.
cols + col];
4373 const double multFactor =
utils::power(10., inNumDecimals);
4374 const auto function = [multFactor](dtype value) noexcept -> dtype
4375 {
return static_cast<dtype
>(std::nearbyint(
static_cast<double>(value) * multFactor) / multFactor); };
4391 return self_type(cbegin(inRow), cend(inRow));
4433 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
4434 {
return lhs < rhs; };
4445 for (
uint32 row = 0; row < shape_.rows; ++row)
4454 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
4473 [[nodiscard]] std::string
str()
const
4479 for (
uint32 row = 0; row < shape_.rows; ++row)
4482 for (
uint32 col = 0; col < shape_.cols; ++col)
4487 if (row == shape_.rows - 1)
4517 self_type returnArray = { std::accumulate(cbegin(), cend(), dtype{ 0 }) };
4523 for (
uint32 row = 0; row < shape_.rows; ++row)
4525 returnArray(0, row) = std::accumulate(cbegin(row), cend(row), dtype{ 0 });
4565 for (
index_type row = 0; row < static_cast<index_type>(shape_.rows); ++row)
4567 std::swap(
operator()(row, colIdx1),
operator()(row, colIdx2));
4583 for (
index_type col = 0; col < static_cast<index_type>(shape_.cols); ++col)
4585 std::swap(
operator()(rowIdx1, col),
operator()(rowIdx2, col));
4602 void tofile(
const std::string& inFilename)
const
4619 void tofile(
const std::string& inFilename,
const char inSep)
const
4623 std::filesystem::path
f(inFilename);
4624 if (!
f.has_extension())
4626 f.replace_extension(
"txt");
4629 std::ofstream ofile(
f.c_str());
4636 for (
auto value : *
this)
4639 if (counter++ != size_ - 1)
4683 if (numElements == 0)
4707 return std::vector<dtype>(cbegin(), cend());
4732 rowStart += inOffset;
4737 colStart += inOffset;
4748 if (rowStart >= shape_.rows || colStart >= shape_.cols)
4755 for (
size_type row = rowStart; row < shape_.rows; ++row)
4757 if (col >= shape_.cols)
4761 sum += operator()(row, col++);
4777 self_type transArray(shape_.cols, shape_.rows);
4778 for (
uint32 row = 0; row < shape_.rows; ++row)
4780 for (
uint32 col = 0; col < shape_.cols; ++col)
4782 transArray(col, row) = operator()(row, col);
4803 allocator_type allocator_{};
4804 Shape shape_{ 0, 0 };
4805 size_type size_{ 0 };
4806 Endian endianess_{ Endian::NATIVE };
4807 pointer array_{
nullptr };
4808 bool ownsPtr_{
false };
4814 void deleteArray() noexcept
4816 if (ownsPtr_ && array_ !=
nullptr)
4818 allocator_.deallocate(array_, size_);
4822 shape_.rows = shape_.cols = 0;
4825 endianess_ = Endian::NATIVE;
4836 array_ = allocator_.allocate(size_);
4847 void newArray(
const Shape& inShape)
4852 size_ = inShape.size();
4859 template<
typename dtype,
class Alloc_>
4864 std::vector<size_type> rowIndices;
4865 std::vector<size_type> colIndices;
4867 for (
uint32 row = 0; row < shape_.rows; ++row)
4869 for (
uint32 col = 0; col < shape_.cols; ++col)
4873 rowIndices.push_back(row);
4874 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_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:818
Custom column const_iterator for NdArray.
Definition: NdArrayIterators.hpp:492
Custom const_iterator for NdArray.
Definition: NdArrayIterators.hpp:42
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:138
NdArray(std::vector< std::array< dtype, Dim1Size >> &in2dArray, bool copy=true)
Definition: NdArrayCore.hpp:391
const_reverse_column_iterator rcolbegin() const noexcept
Definition: NdArrayCore.hpp:1516
size_type dimSize(Axis inAxis) const noexcept
Definition: NdArrayCore.hpp:2607
self_type row(size_type inRow)
Definition: NdArrayCore.hpp:4389
NdArray< dtypeOut > astype() const
Definition: NdArrayCore.hpp:2124
self_type operator[](Slice inSlice) const
Definition: NdArrayCore.hpp:766
self_type & fill(value_type inFillValue) noexcept
Definition: NdArrayCore.hpp:2731
self_type max(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2964
size_type size() const noexcept
Definition: NdArrayCore.hpp:4415
self_type & resizeFast(size_type inNumRows, size_type inNumCols)
Definition: NdArrayCore.hpp:4282
self_type & zeros() noexcept
Definition: NdArrayCore.hpp:4793
reverse_iterator rbegin() noexcept
Definition: NdArrayCore.hpp:1412
self_type at(index_type inRowIndex, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1140
self_type & reshape(size_type inSize)
Definition: NdArrayCore.hpp:4190
self_type & put(const Indices &inRowIndices, index_type inColIndex, const self_type &inValues)
Definition: NdArrayCore.hpp:3993
NdArray< bool > issorted(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2891
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1308
self_type at(const RowIndices &rowIndices, const ColIndices &colIndices) const
Definition: NdArrayCore.hpp:1216
self_type & put(const Slice &inRowSlice, index_type inColIndex, const self_type &inValues)
Definition: NdArrayCore.hpp:4010
self_type & put(const Indices &inRowIndices, index_type inColIndex, const value_type &inValue)
Definition: NdArrayCore.hpp:3814
const_column_iterator ccolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1397
self_type & put(index_type inRowIndex, const Slice &inColSlice, const self_type &inValues)
Definition: NdArrayCore.hpp:4045
NdArray< bool > any(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1922
self_type & put(index_type inRowIndex, const Indices &inColIndices, const value_type &inValue)
Definition: NdArrayCore.hpp:3849
const_pointer data() const noexcept
Definition: NdArrayCore.hpp:2533
iterator end() noexcept
Definition: NdArrayCore.hpp:1566
NdArray(std::vector< dtype > &inVector, bool copy=true)
Definition: NdArrayCore.hpp:331
self_type & ones() noexcept
Definition: NdArrayCore.hpp:3410
self_type & put(index_type inIndex, const value_type &inValue)
Definition: NdArrayCore.hpp:3616
reference at(index_type inRowIndex, index_type inColIndex)
Definition: NdArrayCore.hpp:1011
self_type & resizeFast(const Shape &inShape)
Definition: NdArrayCore.hpp:4297
self_type & swapCols(index_type colIdx1, index_type colIdx2) noexcept
Definition: NdArrayCore.hpp:4563
self_type repeat(const Shape &inRepeatShape) const
Definition: NdArrayCore.hpp:4159
self_type at(Slice rowSlice, const Indices &colIndices) const
Definition: NdArrayCore.hpp:1199
std::vector< dtype > toStlVector() const
Definition: NdArrayCore.hpp:4705
reference back(size_type row)
Definition: NdArrayCore.hpp:2263
iterator end(size_type inRow)
Definition: NdArrayCore.hpp:1578
self_type column(size_type inColumn)
Definition: NdArrayCore.hpp:2355
NdArray(const std::initializer_list< std::initializer_list< dtype >> &inList)
Definition: NdArrayCore.hpp:238
self_type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) const
Definition: NdArrayCore.hpp:923
void tofile(const std::string &inFilename, const char inSep) const
Definition: NdArrayCore.hpp:4619
const_column_iterator ccolbegin() const noexcept
Definition: NdArrayCore.hpp:1385
NdArray< size_type > argmin(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2014
typename AllocTraits::pointer pointer
Definition: NdArrayCore.hpp:151
self_type transpose() const
Definition: NdArrayCore.hpp:4775
reverse_iterator rbegin(size_type inRow)
Definition: NdArrayCore.hpp:1424
self_type & ravel()
Definition: NdArrayCore.hpp:4102
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4402
NdArray< size_type > toIndices(Slice inSlice, Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:4656
const_reverse_column_iterator rcolend() const noexcept
Definition: NdArrayCore.hpp:1824
const dtype & const_reference
Definition: NdArrayCore.hpp:154
bool issquare() const noexcept
Definition: NdArrayCore.hpp:2932
bool isflat() const noexcept
Definition: NdArrayCore.hpp:2868
Endian endianess() const noexcept
Definition: NdArrayCore.hpp:2715
self_type dot(const self_type &inOtherArray) const
Definition: NdArrayCore.hpp:2642
void tofile(const std::string &inFilename) const
Definition: NdArrayCore.hpp:4602
const_reverse_column_iterator crcolbegin() const noexcept
Definition: NdArrayCore.hpp:1539
const_reverse_column_iterator crcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1859
size_type numCols() const noexcept
Definition: NdArrayCore.hpp:3388
column_iterator colbegin(size_type inCol)
Definition: NdArrayCore.hpp:1347
NdArray< bool > none(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3334
self_type median(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3054
const_reference at(index_type inRowIndex, index_type inColIndex) const
Definition: NdArrayCore.hpp:1024
self_type at(const Slice &inSlice) const
Definition: NdArrayCore.hpp:1054
pointer data() noexcept
Definition: NdArrayCore.hpp:2523
bool isempty() const noexcept
Definition: NdArrayCore.hpp:2855
column_iterator colbegin() noexcept
Definition: NdArrayCore.hpp:1335
const_reference front(size_type row) const
Definition: NdArrayCore.hpp:2805
reverse_column_iterator rcolend(size_type inCol)
Definition: NdArrayCore.hpp:1809
self_type & put(const Slice &inRowSlice, const Slice &inColSlice, const value_type &inValue)
Definition: NdArrayCore.hpp:3797
self_type prod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3526
NdArray(Iterator inFirst, Iterator inLast)
Definition: NdArrayCore.hpp:487
reference at(index_type inIndex)
Definition: NdArrayCore.hpp:977
reverse_column_iterator rcolbegin() noexcept
Definition: NdArrayCore.hpp:1489
self_type & reshape(const Shape &inShape)
Definition: NdArrayCore.hpp:4267
self_type at(const Indices &inIndices) const
Definition: NdArrayCore.hpp:1084
const_iterator cbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1320
const_column_iterator ccolend(size_type inCol) const
Definition: NdArrayCore.hpp:1782
self_type at(index_type rowIndex, const Indices &colIndices) const
Definition: NdArrayCore.hpp:1184
const_iterator cend(size_type inRow) const
Definition: NdArrayCore.hpp:1628
self_type & reshape(index_type inNumRows, index_type inNumCols)
Definition: NdArrayCore.hpp:4217
self_type getByIndices(const NdArray< size_type > &inIndices) const
Definition: NdArrayCore.hpp:2828
const_reverse_column_iterator rcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1836
const_iterator end(size_type inRow) const
Definition: NdArrayCore.hpp:1605
self_type flatten() const
Definition: NdArrayCore.hpp:2770
reference back() noexcept
Definition: NdArrayCore.hpp:2241
const_reverse_column_iterator crcolend() const noexcept
Definition: NdArrayCore.hpp:1847
const_reference back(size_type row) const
Definition: NdArrayCore.hpp:2252
reverse_column_iterator rcolbegin(size_type inCol)
Definition: NdArrayCore.hpp:1501
NdArray(const std::deque< std::deque< dtype >> &in2dDeque)
Definition: NdArrayCore.hpp:435
iterator begin(size_type inRow)
Definition: NdArrayCore.hpp:1270
const_reverse_iterator rend() const noexcept
Definition: NdArrayCore.hpp:1670
self_type copy() const
Definition: NdArrayCore.hpp:2409
self_type round(uint8 inNumDecimals=0) const
Definition: NdArrayCore.hpp:4368
self_type swapaxes() const
Definition: NdArrayCore.hpp:4550
const_reverse_column_iterator rcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1528
typename AllocTraits::difference_type difference_type
Definition: NdArrayCore.hpp:157
self_type & put(const Slice &inRowSlice, const ColIndices &inColIndices, const value_type &inValue)
Definition: NdArrayCore.hpp:3781
const_iterator end() const noexcept
Definition: NdArrayCore.hpp:1593
bool ownsInternalData() noexcept
Definition: NdArrayCore.hpp:3424
self_type operator[](const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:778
column_iterator colend() noexcept
Definition: NdArrayCore.hpp:1720
NdArray(std::initializer_list< dtype > inList)
Definition: NdArrayCore.hpp:221
self_type & operator=(self_type &&rhs) noexcept
Definition: NdArrayCore.hpp:674
self_type at(const Indices &rowIndices, Slice colSlice) const
Definition: NdArrayCore.hpp:1170
self_type & put(const Slice &inSlice, const self_type &inValues)
Definition: NdArrayCore.hpp:3717
const_reference back() const noexcept
Definition: NdArrayCore.hpp:2230
self_type & operator=(const self_type &rhs)
Definition: NdArrayCore.hpp:633
std::pair< NdArray< size_type >, NdArray< size_type > > nonzero() const
Definition: NdArrayCore.hpp:4860
self_type diagonal(index_type inOffset=0, Axis inAxis=Axis::ROW) const
Definition: NdArrayCore.hpp:2562
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: NdArrayCore.hpp:162
self_type at(const Slice &inRowSlice, index_type inColIndex) const
Definition: NdArrayCore.hpp:1126
NdArray(const_pointer inPtr, UIntType1 numRows, UIntType2 numCols)
Definition: NdArrayCore.hpp:530
NdArray(const self_type &inOtherArray)
Definition: NdArrayCore.hpp:586
NdArray(self_type &&inOtherArray) noexcept
Definition: NdArrayCore.hpp:604
self_type & put(index_type inRow, index_type inCol, const value_type &inValue)
Definition: NdArrayCore.hpp:3633
uint64 nbytes() const noexcept
Definition: NdArrayCore.hpp:3156
self_type & put(const RowIndices &inRowIndices, const ColIndices &inColIndices, const self_type &inValues)
Definition: NdArrayCore.hpp:3887
self_type & putMask(const NdArray< bool > &inMask, const self_type &inValues)
Definition: NdArrayCore.hpp:4075
self_type at(const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:1066
NdArray(const std::list< dtype > &inList)
Definition: NdArrayCore.hpp:467
const_reference front() const noexcept
Definition: NdArrayCore.hpp:2783
~NdArray() noexcept
Definition: NdArrayCore.hpp:621
Slice rSlice(index_type inStartIdx=0, size_type inStepSize=1) const
Definition: NdArrayCore.hpp:965
reference front() noexcept
Definition: NdArrayCore.hpp:2794
NdArray(size_type inNumRows, size_type inNumCols)
Definition: NdArrayCore.hpp:195
Allocator allocator_type
Definition: NdArrayCore.hpp:150
self_type & put(const Indices &inIndices, const value_type &inValue)
Definition: NdArrayCore.hpp:3651
void print() const
Definition: NdArrayCore.hpp:3510
self_type & byteswap() noexcept
Definition: NdArrayCore.hpp:2276
const_reverse_column_iterator crcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1551
self_type & put(const RowIndices &inRowIndices, const ColIndices &inColIndices, const value_type &inValue)
Definition: NdArrayCore.hpp:3737
size_type numRows() const noexcept
Definition: NdArrayCore.hpp:3400
reverse_iterator rend(size_type inRow)
Definition: NdArrayCore.hpp:1655
NdArray(size_type inSquareSize)
Definition: NdArrayCore.hpp:181
self_type at(const Indices &rowIndices, index_type colIndex) const
Definition: NdArrayCore.hpp:1155
reverse_iterator rend() noexcept
Definition: NdArrayCore.hpp:1643
const_reverse_iterator rend(size_type inRow) const
Definition: NdArrayCore.hpp:1682
typename AllocTraits::const_pointer const_pointer
Definition: NdArrayCore.hpp:152
const_reverse_iterator crbegin() const noexcept
Definition: NdArrayCore.hpp:1462
const_column_iterator colend(size_type inCol) const
Definition: NdArrayCore.hpp:1759
self_type & operator=(value_type inValue) noexcept
Definition: NdArrayCore.hpp:657
self_type & put(const RowIndices &inRowIndices, Slice inColSlice, const self_type &inValues)
Definition: NdArrayCore.hpp:3943
std::reverse_iterator< iterator > reverse_iterator
Definition: NdArrayCore.hpp:161
self_type & put(const Slice &inRowSlice, index_type inColIndex, const value_type &inValue)
Definition: NdArrayCore.hpp:3831
self_type & put(Slice inRowSlice, const ColIndices &inColIndices, const self_type &inValues)
Definition: NdArrayCore.hpp:3960
NdArray(const std::vector< std::vector< dtype >> &in2dVector)
Definition: NdArrayCore.hpp:356
const_reverse_iterator rbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1451
self_type operator[](const Indices &inIndices) const
Definition: NdArrayCore.hpp:792
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1616
self_type & put(index_type inRowIndex, const Slice &inColSlice, const value_type &inValue)
Definition: NdArrayCore.hpp:3866
std::string str() const
Definition: NdArrayCore.hpp:4473
std::reverse_iterator< const_column_iterator > const_reverse_column_iterator
Definition: NdArrayCore.hpp:167
self_type cumsum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2475
self_type & put(Slice inRowSlice, Slice inColSlice, const self_type &inValues)
Definition: NdArrayCore.hpp:3976
reference front(size_type row)
Definition: NdArrayCore.hpp:2816
self_type & nans() noexcept
Definition: NdArrayCore.hpp:3139
self_type & partition(size_type inKth, Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:3444
self_type repeat(size_type inNumRows, size_type inNumCols) const
Definition: NdArrayCore.hpp:4118
NdArray< size_type > argmax(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1967
NdArray(pointer inPtr, size_type numRows, size_type numCols, BoolType takeOwnership) noexcept
Definition: NdArrayCore.hpp:572
NdArray< size_type > flatnonzero() const
Definition: NdArrayCore.hpp:2744
const_iterator begin(size_type inRow) const
Definition: NdArrayCore.hpp:1297
iterator begin() noexcept
Definition: NdArrayCore.hpp:1258
self_type & put(const RowIndices &inRowIndices, const Slice &inColSlice, const value_type &inValue)
Definition: NdArrayCore.hpp:3764
const_column_iterator colbegin() const noexcept
Definition: NdArrayCore.hpp:1362
bool isscalar() const noexcept
Definition: NdArrayCore.hpp:2879
std::reverse_iterator< column_iterator > reverse_column_iterator
Definition: NdArrayCore.hpp:166
self_type operator()(Slice inRowSlice, Slice inColSlice) const
Definition: NdArrayCore.hpp:813
self_type newbyteorder(Endian inEndianess) const
Definition: NdArrayCore.hpp:3171
value_type item() const
Definition: NdArrayCore.hpp:2945
const_reference at(index_type inIndex) const
Definition: NdArrayCore.hpp:989
const_column_iterator colend() const noexcept
Definition: NdArrayCore.hpp:1747
self_type operator()(const Indices &rowIndices, index_type colIndex) const
Definition: NdArrayCore.hpp:858
self_type at(const Slice &inRowSlice, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1113
self_type operator()(Slice inRowSlice, index_type inColIndex) const
Definition: NdArrayCore.hpp:827
const_reverse_iterator crend() const noexcept
Definition: NdArrayCore.hpp:1693
self_type & sort(Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:4429
self_type operator()(index_type rowIndex, const Indices &colIndices) const
Definition: NdArrayCore.hpp:889
NdArray< dtype, Allocator > self_type
Definition: NdArrayCore.hpp:148
const_column_iterator colbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1374
self_type cumprod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2423
NdArray< bool > contains(value_type inValue, Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2368
const_column_iterator ccolend() const noexcept
Definition: NdArrayCore.hpp:1770
reference operator()(index_type inRowIndex, index_type inColIndex) noexcept
Definition: NdArrayCore.hpp:730
self_type operator()(index_type inRowIndex, Slice inColSlice) const
Definition: NdArrayCore.hpp:842
reverse_column_iterator rcolend() noexcept
Definition: NdArrayCore.hpp:1797
NdArray(std::array< dtype, ArraySize > &inArray, bool copy=true)
Definition: NdArrayCore.hpp:274
const_reverse_iterator rbegin() const noexcept
Definition: NdArrayCore.hpp:1439
NdArray(const_pointer inPtr, size_type size)
Definition: NdArrayCore.hpp:506
NdArray(const std::deque< dtype > &inDeque)
Definition: NdArrayCore.hpp:418
self_type & replace(value_type oldValue, value_type newValue)
Definition: NdArrayCore.hpp:4171
NdArray(std::array< std::array< dtype, Dim1Size >, Dim0Size > &in2dArray, bool copy=true)
Definition: NdArrayCore.hpp:302
self_type & put(const Indices &inIndices, const self_type &inValues)
Definition: NdArrayCore.hpp:3672
void dump(const std::string &inFilename) const
Definition: NdArrayCore.hpp:2688
dtype & reference
Definition: NdArrayCore.hpp:153
value_type trace(size_type inOffset=0, Axis inAxis=Axis::ROW) const noexcept
Definition: NdArrayCore.hpp:4722
pointer dataRelease() noexcept
Definition: NdArrayCore.hpp:2545
self_type ptp(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3570
self_type & put(const Slice &inSlice, const value_type &inValue)
Definition: NdArrayCore.hpp:3702
self_type clip(value_type inMin, value_type inMax) const
Definition: NdArrayCore.hpp:2316
self_type getByMask(const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:2842
self_type & swapRows(index_type rowIdx1, index_type rowIdx2) noexcept
Definition: NdArrayCore.hpp:4581
uint32 size_type
Definition: NdArrayCore.hpp:155
const_iterator begin() const noexcept
Definition: NdArrayCore.hpp:1285
column_iterator colend(size_type inCol)
Definition: NdArrayCore.hpp:1732
const_reference operator[](index_type inIndex) const noexcept
Definition: NdArrayCore.hpp:712
self_type operator()(Slice rowSlice, const Indices &colIndices) const
Definition: NdArrayCore.hpp:905
const_reference operator()(index_type inRowIndex, index_type inColIndex) const noexcept
Definition: NdArrayCore.hpp:743
self_type min(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3008
dtype value_type
Definition: NdArrayCore.hpp:149
reference operator[](index_type inIndex) noexcept
Definition: NdArrayCore.hpp:700
Slice cSlice(index_type inStartIdx=0, size_type inStepSize=1) const
Definition: NdArrayCore.hpp:951
self_type & put(index_type inRowIndex, const Indices &inColIndices, const self_type &inValues)
Definition: NdArrayCore.hpp:4028
NdArray< size_type > argsort(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2060
const_reverse_iterator crend(size_type inRow) const
Definition: NdArrayCore.hpp:1705
const_reverse_iterator crbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1474
int32 index_type
Definition: NdArrayCore.hpp:156
NdArray(pointer inPtr, size_type size, BoolType takeOwnership) noexcept
Definition: NdArrayCore.hpp:552
NdArray(const Shape &inShape)
Definition: NdArrayCore.hpp:208
self_type sum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:4509
self_type operator()(const Indices &rowIndices, Slice colSlice) const
Definition: NdArrayCore.hpp:874
NdArray< bool > all(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1878
self_type & resizeSlow(size_type inNumRows, size_type inNumCols)
Definition: NdArrayCore.hpp:4314
self_type & resizeSlow(const Shape &inShape)
Definition: NdArrayCore.hpp:4353
self_type & putMask(const NdArray< bool > &inMask, const value_type &inValue)
Definition: NdArrayCore.hpp:4058
Custom iterator for NdArray.
Definition: NdArrayIterators.hpp:318
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
uint32 rows
Definition: Core/Shape.hpp:44
uint32 cols
Definition: Core/Shape.hpp:45
uint32 size() const noexcept
Definition: Core/Shape.hpp:104
A Class for slicing into NdArrays.
Definition: Slice.hpp:45
int32 step
Definition: Slice.hpp:50
int32 start
Definition: Slice.hpp:48
uint32 numElements(uint32 inArraySize)
Definition: Slice.hpp:195
constexpr auto j
Definition: Constants.hpp:41
const double nan
NaN.
Definition: Constants.hpp:40
bool isLittleEndian() noexcept
Definition: Endian.hpp:43
dtype byteSwap(dtype value) noexcept
Definition: Endian.hpp:63
dtype f(GeneratorType &generator, dtype inDofN, dtype inDofD)
Definition: f.hpp:56
bool any_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:76
void sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:696
bool none_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:405
ForwardIt max_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:285
void stable_sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:734
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:775
bool all_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:55
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:225
InputIt find(InputIt first, InputIt last, const T &value) noexcept
Definition: StlAlgorithms.hpp:205
std::pair< ForwardIt, ForwardIt > minmax_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:364
void replace(ForwardIt first, ForwardIt last, const T &oldValue, const T &newValue) noexcept
Definition: StlAlgorithms.hpp:468
bool is_sorted(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:245
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:97
void nth_element(RandomIt first, RandomIt nth, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:425
ForwardIt min_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:324
void fill(ForwardIt first, ForwardIt last, const T &value) noexcept
Definition: StlAlgorithms.hpp:183
constexpr bool is_ndarray_signed_int_v
Definition: NdArrayCore.hpp:123
std::enable_if_t< is_ndarray_int_v< T >, int > ndarray_int_concept
Definition: NdArrayCore.hpp:130
constexpr bool is_ndarray_int_v
Definition: NdArrayCore.hpp:96
std::string num2str(dtype inNumber)
Definition: num2str.hpp:44
std::string value2str(dtype inValue)
Definition: value2str.hpp:46
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:48
Definition: Coordinate.hpp:45
constexpr dtype power(dtype inValue, uint8 inExponent) noexcept
Definition: Functions/power.hpp:52
uint32 size(const NdArray< dtype > &inArray) noexcept
Definition: size.hpp:43
NdArray< dtype > repeat(const NdArray< dtype > &inArray, uint32 inNumRows, uint32 inNumCols)
Definition: repeat.hpp:49
void swap(NdArray< dtype > &inArray1, NdArray< dtype > &inArray2) noexcept
Definition: swap.hpp:42
std::pair< NdArray< uint32 >, NdArray< uint32 > > nonzero(const NdArray< dtype > &inArray)
Definition: nonzero.hpp:48
NdArray< dtype > & resizeFast(NdArray< dtype > &inArray, uint32 inNumRows, uint32 inNumCols)
Definition: resizeFast.hpp:50
Axis
Enum To describe an axis.
Definition: Types.hpp:47
NdArray< dtype > & reshape(NdArray< dtype > &inArray, uint32 inSize)
Definition: reshape.hpp:51
std::int64_t int64
Definition: Types.hpp:35
auto abs(dtype inValue) noexcept
Definition: abs.hpp:49
std::uint64_t uint64
Definition: Types.hpp:39
NdArray< dtype > & resizeSlow(NdArray< dtype > &inArray, uint32 inNumRows, uint32 inNumCols)
Definition: resizeSlow.hpp:52
Endian
Enum for endianess.
Definition: Types.hpp:56
std::int32_t int32
Definition: Types.hpp:36
std::uint8_t uint8
Definition: Types.hpp:42
NdArray< dtype > sum(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: sum.hpp:46
NdArray< dtype > transpose(const NdArray< dtype > &inArray)
Definition: transpose.hpp:45
std::uint32_t uint32
Definition: Types.hpp:40
void dump(const NdArray< dtype > &inArray, const std::string &inFilename)
Definition: dump.hpp:46
NdArray< dtype > & put(NdArray< dtype > &inArray, int32 inIndex, const dtype &inValue)
Definition: put.hpp:46
Definition: NdArrayCore.hpp:77
Definition: NdArrayCore.hpp:104