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;
631 explicit operator bool() const noexcept
649 newArray(rhs.shape_);
650 endianess_ = rhs.endianess_;
669 if (array_ !=
nullptr)
691 endianess_ = rhs.endianess_;
693 ownsPtr_ = rhs.ownsPtr_;
695 rhs.shape_.rows = rhs.shape_.cols = rhs.size_ = 0;
696 rhs.array_ =
nullptr;
697 rhs.ownsPtr_ =
false;
712 return const_cast<reference>(
const_cast<const self_type*
>(
this)->
operator[](inIndex));
729 return array_[inIndex];
742 return const_cast<reference>(
const_cast<const self_type*
>(
this)->
operator()(inRowIndex, inColIndex));
757 inRowIndex += shape_.
rows;
762 inColIndex += shape_.
cols;
765 return array_[inRowIndex * shape_.
cols + inColIndex];
801 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
806 for (
auto& index : inIndices)
867 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
883 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
898 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
914 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
929 template<
typename RowIndices,
935 self_type returnArray(rowIndices.size(), colIndices.size());
938 for (
auto rowIter = rowIndices.begin(); rowIter != rowIndices.end(); ++rowIter)
941 for (
auto colIter = colIndices.begin(); colIter != colIndices.end(); ++colIter)
943 returnArray(rowCounter, colCounter++) =
operator()(*rowIter, *colIter);
963 return Slice(inStartIdx, shape_.
cols, inStepSize);
977 return Slice(inStartIdx, shape_.
rows, inStepSize);
1006 errStr +=
" is out of bounds for array of size " +
utils::num2str(size_) +
".";
1041 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
rows) +
".";
1049 std::string errStr =
"Column index " +
utils::num2str(inColIndex);
1050 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
cols) +
".";
1078 if (inMask.
shape() != shape_)
1093 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1100 auto indexSigned = static_cast<index_type>(index);
1101 if (indexSigned < 0)
1103 indexSigned += size_;
1106 if (indexSigned < 0 || indexSigned >
static_cast<index_type>(size_ - 1))
1139 return at(toIndices(inRowSlice,
Axis::ROW), colIndices);
1153 return at(rowIndices, toIndices(inColSlice,
Axis::COL));
1164 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1168 return at(rowIndices, colIndices);
1179 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1182 return at(rowIndices, toIndices(colSlice,
Axis::COL));
1193 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1197 return at(rowIndices, colIndices);
1208 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1211 return at(toIndices(rowSlice,
Axis::ROW), colIndices);
1222 template<
typename RowIndices,
1223 typename ColIndices,
1226 [[nodiscard]]
self_type at(
const RowIndices& rowIndices,
const ColIndices& colIndices)
const
1232 auto rowSigned = static_cast<index_type>(row);
1235 rowSigned += shape_.rows;
1238 if (rowSigned < 0 || rowSigned >
static_cast<index_type>(shape_.rows - 1))
1240 THROW_INVALID_ARGUMENT_ERROR(
"Row index exceeds matrix dimensions");
1248 auto colSigned = static_cast<index_type>(col);
1251 colSigned += shape_.cols;
1254 if (colSigned < 0 || colSigned >
static_cast<index_type
>(shape_.cols - 1))
1256 THROW_INVALID_ARGUMENT_ERROR(
"Column index exceeds matrix dimensions");
1260 return operator()(rowIndices, colIndices);
1282 if (inRow >= shape_.rows)
1287 return begin() += (inRow * shape_.cols);
1309 return cbegin(inRow);
1332 if (inRow >= shape_.rows)
1337 return cbegin() += (inRow * shape_.cols);
1359 if (inCol >= shape_.cols)
1364 return colbegin() += (inCol * shape_.rows);
1386 return ccolbegin(inCol);
1409 if (inCol >= shape_.cols)
1414 return ccolbegin() += (inCol * shape_.rows);
1436 if (inRow >= shape_.rows)
1441 return rbegin() += (shape_.rows - inRow - 1) * shape_.cols;
1463 return crbegin(inRow);
1486 if (inRow >= shape_.rows)
1491 return crbegin() += (shape_.rows - inRow - 1) * shape_.cols;
1513 if (inCol >= shape_.cols)
1518 return rcolbegin() += (shape_.cols - inCol - 1) * shape_.rows;
1528 return crcolbegin();
1540 return crcolbegin(inCol);
1563 if (inCol >= shape_.cols)
1568 return crcolbegin() += (shape_.cols - inCol - 1) * shape_.rows;
1578 return begin() += size_;
1590 if (inRow >= shape_.rows)
1595 return begin(inRow) += shape_.cols;
1628 return cbegin() += size_;
1640 if (inRow >= shape_.rows)
1645 return cbegin(inRow) += shape_.cols;
1655 return rbegin() += size_;
1667 if (inRow >= shape_.rows)
1672 return rbegin(inRow) += shape_.cols;
1694 return crend(inRow);
1705 return crbegin() += size_;
1717 if (inRow >= shape_.rows)
1722 return crbegin(inRow) += shape_.cols;
1732 return colbegin() += size_;
1744 if (inCol >= shape_.cols)
1749 return colbegin(inCol) += shape_.rows;
1771 return ccolend(inCol);
1782 return ccolbegin() += size_;
1794 if (inCol >= shape_.cols)
1799 return ccolbegin(inCol) += shape_.rows;
1809 return rcolbegin() += size_;
1821 if (inCol >= shape_.cols)
1826 return rcolbegin(inCol) += shape_.rows;
1848 return crcolend(inCol);
1859 return crcolbegin() += size_;
1871 if (inCol >= shape_.cols)
1876 return crcolbegin(inCol) += shape_.rows;
1904 for (
uint32 row = 0; row < shape_.rows; ++row)
1948 for (
uint32 row = 0; row < shape_.rows; ++row)
1981 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
1994 for (
size_type row = 0; row < shape_.rows; ++row)
1996 returnArray(0, row) =
static_cast<size_type>(
2028 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
2041 for (
size_type row = 0; row < shape_.rows; ++row)
2043 returnArray(0, row) =
static_cast<size_type>(
2078 std::vector<size_type> idx(size_);
2079 std::iota(idx.begin(), idx.end(), 0);
2082 {
return (*
this)[i1] < (*this)[i2]; };
2090 std::vector<size_type> idx(shape_.cols);
2092 for (
index_type row = 0; row < static_cast<index_type>(shape_.rows); ++row)
2094 std::iota(idx.begin(), idx.end(), 0);
2097 {
return operator()(row, i1) < operator()(row, i2); };
2101 for (
index_type col = 0; col < static_cast<index_type>(shape_.cols); ++col)
2103 returnArray(row, col) = idx[
static_cast<size_type>(col)];
2110 return transpose().argsort(Axis::COL).transpose();
2129 template<
typename dtypeOut,
2130 typename dtype_ = dtype,
2131 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2132 std::enable_if_t<std::is_arithmetic_v<dtype_>,
int> = 0,
2133 std::enable_if_t<std::is_arithmetic_v<dtypeOut>,
int> = 0>
2136 if constexpr (std::is_same_v<dtypeOut, dtype>)
2146 [](dtype value) -> dtypeOut { return static_cast<dtypeOut>(value); });
2161 template<
typename dtypeOut,
2162 typename dtype_ = dtype,
2163 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2164 std::enable_if_t<std::is_arithmetic_v<dtype_>,
int> = 0,
2165 std::enable_if_t<is_complex_v<dtypeOut>,
int> = 0>
2171 {
return std::complex<typename dtypeOut::value_type>(value); };
2187 template<
typename dtypeOut,
2188 typename dtype_ = dtype,
2189 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2190 std::enable_if_t<is_complex_v<dtype_>,
int> = 0,
2191 std::enable_if_t<is_complex_v<dtypeOut>,
int> = 0>
2194 if constexpr (std::is_same_v<dtypeOut, dtype>)
2201 {
return complex_cast<typename dtypeOut::value_type>(value); };
2218 template<
typename dtypeOut,
2219 typename dtype_ = dtype,
2220 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2221 std::enable_if_t<is_complex_v<dtype_>,
int> = 0,
2222 std::enable_if_t<std::is_arithmetic_v<dtypeOut>,
int> = 0>
2227 const auto function = [](
const_reference value) -> dtypeOut {
return static_cast<dtypeOut
>(value.real()); };
2242 return *(cend() - 1);
2253 return *(end() - 1);
2264 return *(cend(row) - 1);
2275 return *(end(row) - 1);
2296 case Endian::NATIVE:
2301 case Endian::LITTLE:
2303 endianess_ = Endian::BIG;
2308 endianess_ = Endian::LITTLE;
2334 [inMin, inMax](dtype value) noexcept -> dtype
2336 #ifdef __cpp_lib_clamp
2337 const auto comparitor = [](dtype lhs, dtype rhs) noexcept -> bool
2338 { return lhs < rhs; };
2340 return std::clamp(value, inMin, inMax, comparitor);
2346 else if (value > inMax)
2367 return operator()(rSlice(), inColumn);
2380 const auto rSlice = returnArray.rSlice();
2384 returnArray.put(rSlice, i, column(inCols[i]));
2412 for (
size_type row = 0; row < shape_.rows; ++row)
2421 return transpose().contains(inValue, Axis::COL);
2462 returnArray[0] = front();
2465 returnArray[i] = returnArray[i - 1] * array_[i];
2473 for (
uint32 row = 0; row < shape_.rows; ++row)
2475 returnArray(row, 0) = operator()(row, 0);
2476 for (
uint32 col = 1; col < shape_.cols; ++col)
2478 returnArray(row, col) = returnArray(row, col - 1) * operator()(row, col);
2486 return transpose().cumprod(Axis::COL).transpose();
2514 returnArray[0] = front();
2517 returnArray[i] = returnArray[i - 1] + array_[i];
2525 for (
uint32 row = 0; row < shape_.rows; ++row)
2527 returnArray(row, 0) = operator()(row, 0);
2528 for (
uint32 col = 1; col < shape_.cols; ++col)
2530 returnArray(row, col) = returnArray(row, col - 1) + operator()(row, col);
2538 return transpose().cumsum(Axis::COL).transpose();
2598 std::vector<dtype> diagnolValues;
2600 for (
index_type row = inOffset; row < static_cast<index_type>(shape_.rows); ++row)
2607 if (col >= shape_.cols)
2612 diagnolValues.push_back(
operator()(
static_cast<size_type>(row), col));
2620 return transpose().diagonal(inOffset, Axis::COL);
2676 if (shape_ == inOtherArray.shape_ && (shape_.rows == 1 || shape_.cols == 1))
2678 dtype dotProduct = std::inner_product(cbegin(), cend(), inOtherArray.
cbegin(), dtype{ 0 });
2682 if (shape_.cols == inOtherArray.shape_.
rows)
2685 self_type returnArray(shape_.rows, inOtherArray.shape_.
cols);
2686 auto otherArrayT = inOtherArray.
transpose();
2688 for (
uint32 i = 0; i < shape_.rows; ++i)
2690 for (
uint32 j = 0;
j < otherArrayT.shape_.rows; ++
j)
2693 std::inner_product(otherArrayT.cbegin(
j), otherArrayT.cend(
j), cbegin(i), dtype{ 0 });
2703 errStr +=
" are not consistent.";
2718 void dump(
const std::string& inFilename)
const
2720 std::filesystem::path
f(inFilename);
2721 if (!
f.has_extension())
2723 f.replace_extension(
"bin");
2726 std::ofstream ofile(
f.c_str(), std::ios::binary);
2732 if (array_ !=
nullptr)
2734 ofile.write(
reinterpret_cast<const char*
>(array_), size_ *
sizeof(dtype));
2778 std::vector<size_type> indices;
2780 for (
auto value : *
this)
2784 indices.push_back(idx);
2837 return *cbegin(row);
2860 return operator[](inIndices);
2874 return operator[](inMask);
2900 return !isscalar() && (shape_.rows == 1 || shape_.cols == 1);
2925 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
2936 for (
uint32 row = 0; row < shape_.rows; ++row)
2964 return shape_.issquare();
2998 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
3010 for (
uint32 row = 0; row < shape_.rows; ++row)
3042 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
3054 for (
uint32 row = 0; row < shape_.rows; ++row)
3088 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
3103 copyArray.
begin() + middleIdx,
3107 dtype medianValue = copyArray.array_[middleIdx];
3110 const size_type lhsIndex = middleIdx - 1;
3112 copyArray.
begin() + lhsIndex,
3116 (medianValue + copyArray.array_[lhsIndex]) / dtype{ 2 };
3119 return { medianValue };
3126 const bool isEven = shape_.cols % 2 == 0;
3127 for (
uint32 row = 0; row < shape_.rows; ++row)
3129 const uint32 middleIdx = shape_.cols / 2;
3131 copyArray.
begin(row) + middleIdx,
3135 dtype medianValue = copyArray(row, middleIdx);
3138 const size_type lhsIndex = middleIdx - 1;
3140 copyArray.
begin(row) + lhsIndex,
3143 medianValue = (medianValue + copyArray(row, lhsIndex)) /
3147 returnArray(0, row) = medianValue;
3188 return static_cast<uint64>(
sizeof(dtype) * size_);
3209 case Endian::NATIVE:
3211 switch (inEndianess)
3213 case Endian::NATIVE:
3225 outArray.endianess_ = Endian::BIG;
3230 auto outArray =
NdArray(*
this);
3231 outArray.endianess_ = Endian::BIG;
3235 case Endian::LITTLE:
3239 auto outArray =
NdArray(*
this);
3240 outArray.endianess_ = Endian::LITTLE;
3249 outArray.endianess_ = Endian::LITTLE;
3263 switch (inEndianess)
3265 case Endian::NATIVE:
3273 outArray.endianess_ = Endian::NATIVE;
3278 auto outArray =
NdArray(*
this);
3279 outArray.endianess_ = Endian::NATIVE;
3287 case Endian::LITTLE:
3293 outArray.endianess_ = Endian::LITTLE;
3304 case Endian::LITTLE:
3306 switch (inEndianess)
3308 case Endian::NATIVE:
3312 auto outArray =
NdArray(*
this);
3313 outArray.endianess_ = Endian::NATIVE;
3322 outArray.endianess_ = Endian::NATIVE;
3332 outArray.endianess_ = Endian::BIG;
3335 case Endian::LITTLE:
3380 for (
uint32 row = 0; row < shape_.rows; ++row)
3478 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3479 {
return lhs < rhs; };
3497 if (inKth >= shape_.cols)
3500 errStr +=
") out of bounds (" +
utils::num2str(shape_.cols) +
")";
3504 for (
uint32 row = 0; row < shape_.rows; ++row)
3512 if (inKth >= shape_.rows)
3515 errStr +=
") out of bounds (" +
utils::num2str(shape_.rows) +
")";
3520 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3523 transposedArray.
begin(row) + inKth,
3524 transposedArray.
end(row),
3564 dtype product = std::accumulate(cbegin(), cend(), dtype{ 1 }, std::multiplies<dtype>());
3571 for (
uint32 row = 0; row < shape_.rows; ++row)
3573 returnArray(0, row) =
3574 std::accumulate(cbegin(row), cend(row), dtype{ 1 }, std::multiplies<dtype>());
3604 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool {
return lhs < rhs; };
3611 self_type returnArray = { *result.second - *result.first };
3617 for (
uint32 row = 0; row < shape_.rows; ++row)
3620 returnArray(0, row) = *result.second - *result.first;
3648 at(inIndex) = inValue;
3665 at(inRow, inCol) = inValue;
3680 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3683 for (
auto index : inIndices)
3685 put(index, inValue);
3701 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3706 return put(inIndices, inValues.
item());
3708 else if (inIndices.size() != inValues.
size())
3714 for (
auto index : inIndices)
3716 put(index, inValues[counter++]);
3734 return put(toIndices(inSlice, Axis::NONE), inValue);
3749 return put(toIndices(inSlice, Axis::NONE), inValues);
3763 template<
typename RowIndices,
3764 typename ColIndices,
3771 [
this, &inColIndices, &inValue](
const auto row)
3773 stl_algorithms::for_each(inColIndices.begin(),
3775 [this, row, &inValue](const auto col)
3776 { this->put(row, col, inValue); });
3793 template<
typename RowIndices, type_traits::ndarray_
int_concept<RowIndices> = 0>
3796 return put(inRowIndices, toIndices(inColSlice, Axis::COL), inValue);
3810 template<
typename ColIndices, type_traits::ndarray_
int_concept<ColIndices> = 0>
3813 return put(toIndices(inRowSlice, Axis::ROW), inColIndices, inValue);
3829 return put(toIndices(inRowSlice, Axis::ROW), toIndices(inColSlice, Axis::COL), inValue);
3843 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3847 return put(inRowIndices, colIndices, inValue);
3864 return put(toIndices(inRowSlice, Axis::ROW), colIndices, inValue);
3878 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3882 return put(rowIndices, inColIndices, inValue);
3899 return put(rowIndices, toIndices(inColSlice, Axis::COL), inValue);
3913 template<
typename RowIndices,
3914 typename ColIndices,
3919 std::vector<size_type> indices;
3920 indices.reserve(inRowIndices.size() * inColIndices.size());
3923 [
this, &inColIndices, &indices](
auto row)
3925 if constexpr (std::is_signed_v<decltype(row)>)
3934 THROW_INVALID_ARGUMENT_ERROR(
"row index exceeds matrix dimensions");
3939 [
this, row, &indices](
auto col)
3941 if constexpr (std::is_signed_v<decltype(col)>)
3950 THROW_INVALID_ARGUMENT_ERROR(
3951 "col index exceeds matrix dimensions");
3954 indices.push_back(row * shape_.cols + col);
3958 return put(NdArray<size_type>(indices.data(), indices.size(),
false), inValues);
3972 template<
typename RowIndices, type_traits::ndarray_
int_concept<RowIndices> = 0>
3975 return put(inRowIndices, toIndices(inColSlice, Axis::COL), inValues);
3989 template<
typename ColIndices, type_traits::ndarray_
int_concept<ColIndices> = 0>
3992 return put(toIndices(inRowSlice, Axis::ROW), inColIndices, inValues);
4008 return put(toIndices(inRowSlice, Axis::ROW), toIndices(inColSlice, Axis::COL), inValues);
4022 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
4026 return put(inRowIndices, colIndices, inValues);
4043 return put(toIndices(inRowSlice, Axis::ROW), colIndices, inValues);
4057 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
4061 return put(rowIndices, inColIndices, inValues);
4078 return put(rowIndices, toIndices(inColSlice, Axis::COL), inValues);
4090 if (inMask.
shape() != shape_)
4107 if (inMask.
shape() != shape_)
4150 self_type returnArray(shape_.rows * inNumRows, shape_.cols * inNumCols);
4152 for (
size_type row = 0; row < inNumRows; ++row)
4154 for (
size_type col = 0; col < inNumCols; ++col)
4156 std::vector<size_type> indices(shape_.size());
4158 const size_type rowStart = row * shape_.rows;
4159 const size_type colStart = col * shape_.cols;
4161 const size_type rowEnd = (row + 1) * shape_.rows;
4162 const size_type colEnd = (col + 1) * shape_.cols;
4165 for (
size_type rowIdx = rowStart; rowIdx < rowEnd; ++rowIdx)
4167 for (
size_type colIdx = colStart; colIdx < colEnd; ++colIdx)
4169 indices[counter++] = rowIdx * returnArray.shape_.
cols + colIdx;
4226 if (inSize != size_)
4228 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4234 shape_.cols = inSize;
4259 if (size_ % inNumCols == 0)
4261 return reshape(size_ / inNumCols, inNumCols);
4264 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4271 if (size_ % inNumRows == 0)
4273 return reshape(inNumRows, size_ / inNumRows);
4276 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4281 if (
static_cast<size_type>(inNumRows * inNumCols) != size_)
4283 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4288 shape_.rows =
static_cast<size_type>(inNumRows);
4289 shape_.cols =
static_cast<size_type>(inNumCols);
4326 newArray(
Shape(inNumRows, inNumCols));
4358 std::vector<dtype> oldData(size_);
4361 const Shape inShape(inNumRows, inNumCols);
4362 const Shape oldShape = shape_;
4366 for (
uint32 row = 0; row < inShape.
rows; ++row)
4368 for (
uint32 col = 0; col < inShape.
cols; ++col)
4370 if (row >= oldShape.
rows || col >= oldShape.
cols)
4372 operator()(row, col) = dtype{ 0 };
4376 operator()(row, col) = oldData[row * oldShape.
cols + col];
4415 const double multFactor =
utils::power(10., inNumDecimals);
4416 const auto function = [multFactor](dtype value) noexcept -> dtype
4417 {
return static_cast<dtype
>(std::nearbyint(
static_cast<double>(value) * multFactor) / multFactor); };
4433 return self_type(cbegin(inRow), cend(inRow));
4446 const auto cSlice = returnArray.cSlice();
4450 returnArray.put(i, cSlice, row(inRows[i]));
4495 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
4496 {
return lhs < rhs; };
4507 for (
uint32 row = 0; row < shape_.rows; ++row)
4516 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
4535 [[nodiscard]] std::string
str()
const
4541 for (
uint32 row = 0; row < shape_.rows; ++row)
4544 for (
uint32 col = 0; col < shape_.cols; ++col)
4549 if (row == shape_.rows - 1)
4579 self_type returnArray = { std::accumulate(cbegin(), cend(), dtype{ 0 }) };
4585 for (
uint32 row = 0; row < shape_.rows; ++row)
4587 returnArray(0, row) = std::accumulate(cbegin(row), cend(row), dtype{ 0 });
4627 for (
index_type row = 0; row < static_cast<index_type>(shape_.rows); ++row)
4629 std::swap(
operator()(row, colIdx1),
operator()(row, colIdx2));
4645 for (
index_type col = 0; col < static_cast<index_type>(shape_.cols); ++col)
4647 std::swap(
operator()(rowIdx1, col),
operator()(rowIdx2, col));
4664 void tofile(
const std::string& inFilename)
const
4681 void tofile(
const std::string& inFilename,
const char inSep)
const
4685 std::filesystem::path
f(inFilename);
4686 if (!
f.has_extension())
4688 f.replace_extension(
"txt");
4691 std::ofstream ofile(
f.c_str());
4698 for (
auto value : *
this)
4701 if (counter++ != size_ - 1)
4745 if (numElements == 0)
4769 return std::vector<dtype>(cbegin(), cend());
4794 rowStart += inOffset;
4799 colStart += inOffset;
4810 if (rowStart >= shape_.rows || colStart >= shape_.cols)
4817 for (
size_type row = rowStart; row < shape_.rows; ++row)
4819 if (col >= shape_.cols)
4823 sum += operator()(row, col++);
4839 self_type transArray(shape_.cols, shape_.rows);
4840 for (
uint32 row = 0; row < shape_.rows; ++row)
4842 for (
uint32 col = 0; col < shape_.cols; ++col)
4844 transArray(col, row) = operator()(row, col);
4865 allocator_type allocator_{};
4866 Shape shape_{ 0, 0 };
4867 size_type size_{ 0 };
4868 Endian endianess_{ Endian::NATIVE };
4869 pointer array_{
nullptr };
4870 bool ownsPtr_{
false };
4876 void deleteArray() noexcept
4878 if (ownsPtr_ && array_ !=
nullptr)
4880 allocator_.deallocate(array_, size_);
4884 shape_.rows = shape_.cols = 0;
4887 endianess_ = Endian::NATIVE;
4898 array_ = allocator_.allocate(size_);
4909 void newArray(
const Shape& inShape)
4914 size_ = inShape.size();
4921 template<
typename dtype,
class Alloc_>
4926 std::vector<size_type> rowIndices;
4927 std::vector<size_type> colIndices;
4929 for (
uint32 row = 0; row < shape_.rows; ++row)
4931 for (
uint32 col = 0; col < shape_.cols; ++col)
4935 rowIndices.push_back(row);
4936 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: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: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:1526
size_type dimSize(Axis inAxis) const noexcept
Definition: NdArrayCore.hpp:2637
NdArray< dtypeOut > astype() const
Definition: NdArrayCore.hpp:2134
self_type operator[](Slice inSlice) const
Definition: NdArrayCore.hpp:776
self_type & fill(value_type inFillValue) noexcept
Definition: NdArrayCore.hpp:2761
self_type max(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2994
size_type size() const noexcept
Definition: NdArrayCore.hpp:4477
self_type & resizeFast(size_type inNumRows, size_type inNumCols)
Definition: NdArrayCore.hpp:4324
self_type & zeros() noexcept
Definition: NdArrayCore.hpp:4855
reverse_iterator rbegin() noexcept
Definition: NdArrayCore.hpp:1422
self_type at(index_type inRowIndex, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1150
self_type columns(const NdArray< size_type > &inCols) const
Definition: NdArrayCore.hpp:2377
self_type & reshape(size_type inSize)
Definition: NdArrayCore.hpp:4224
self_type & put(const Indices &inRowIndices, index_type inColIndex, const self_type &inValues)
Definition: NdArrayCore.hpp:4023
NdArray< bool > issorted(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2921
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1318
self_type at(const RowIndices &rowIndices, const ColIndices &colIndices) const
Definition: NdArrayCore.hpp:1226
self_type & put(const Slice &inRowSlice, index_type inColIndex, const self_type &inValues)
Definition: NdArrayCore.hpp:4040
self_type & put(const Indices &inRowIndices, index_type inColIndex, const value_type &inValue)
Definition: NdArrayCore.hpp:3844
const_column_iterator ccolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1407
self_type & put(index_type inRowIndex, const Slice &inColSlice, const self_type &inValues)
Definition: NdArrayCore.hpp:4075
NdArray< bool > any(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1932
self_type & put(index_type inRowIndex, const Indices &inColIndices, const value_type &inValue)
Definition: NdArrayCore.hpp:3879
const_pointer data() const noexcept
Definition: NdArrayCore.hpp:2563
iterator end() noexcept
Definition: NdArrayCore.hpp:1576
NdArray(std::vector< dtype > &inVector, bool copy=true)
Definition: NdArrayCore.hpp:331
self_type & ones() noexcept
Definition: NdArrayCore.hpp:3440
self_type & put(index_type inIndex, const value_type &inValue)
Definition: NdArrayCore.hpp:3646
reference at(index_type inRowIndex, index_type inColIndex)
Definition: NdArrayCore.hpp:1021
self_type & resizeFast(const Shape &inShape)
Definition: NdArrayCore.hpp:4339
self_type & swapCols(index_type colIdx1, index_type colIdx2) noexcept
Definition: NdArrayCore.hpp:4625
self_type repeat(const Shape &inRepeatShape) const
Definition: NdArrayCore.hpp:4189
self_type at(Slice rowSlice, const Indices &colIndices) const
Definition: NdArrayCore.hpp:1209
std::vector< dtype > toStlVector() const
Definition: NdArrayCore.hpp:4767
reference back(size_type row)
Definition: NdArrayCore.hpp:2273
iterator end(size_type inRow)
Definition: NdArrayCore.hpp:1588
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:933
void tofile(const std::string &inFilename, const char inSep) const
Definition: NdArrayCore.hpp:4681
const_column_iterator ccolbegin() const noexcept
Definition: NdArrayCore.hpp:1395
NdArray< size_type > argmin(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2024
typename AllocTraits::pointer pointer
Definition: NdArrayCore.hpp:151
self_type transpose() const
Definition: NdArrayCore.hpp:4837
reverse_iterator rbegin(size_type inRow)
Definition: NdArrayCore.hpp:1434
self_type & ravel()
Definition: NdArrayCore.hpp:4132
NdArray< size_type > toIndices(Slice inSlice, Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:4718
const_reverse_column_iterator rcolend() const noexcept
Definition: NdArrayCore.hpp:1834
self_type rows(const NdArray< size_type > &inRows) const
Definition: NdArrayCore.hpp:4443
const dtype & const_reference
Definition: NdArrayCore.hpp:154
bool issquare() const noexcept
Definition: NdArrayCore.hpp:2962
bool isflat() const noexcept
Definition: NdArrayCore.hpp:2898
Endian endianess() const noexcept
Definition: NdArrayCore.hpp:2745
self_type dot(const self_type &inOtherArray) const
Definition: NdArrayCore.hpp:2672
void tofile(const std::string &inFilename) const
Definition: NdArrayCore.hpp:4664
const_reverse_column_iterator crcolbegin() const noexcept
Definition: NdArrayCore.hpp:1549
const_reverse_column_iterator crcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1869
size_type numCols() const noexcept
Definition: NdArrayCore.hpp:3418
column_iterator colbegin(size_type inCol)
Definition: NdArrayCore.hpp:1357
NdArray< bool > none(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3364
self_type median(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3084
const_reference at(index_type inRowIndex, index_type inColIndex) const
Definition: NdArrayCore.hpp:1034
self_type at(const Slice &inSlice) const
Definition: NdArrayCore.hpp:1064
pointer data() noexcept
Definition: NdArrayCore.hpp:2553
bool isempty() const noexcept
Definition: NdArrayCore.hpp:2885
column_iterator colbegin() noexcept
Definition: NdArrayCore.hpp:1345
const_reference front(size_type row) const
Definition: NdArrayCore.hpp:2835
reverse_column_iterator rcolend(size_type inCol)
Definition: NdArrayCore.hpp:1819
self_type column(size_type inColumn) const
Definition: NdArrayCore.hpp:2365
self_type & put(const Slice &inRowSlice, const Slice &inColSlice, const value_type &inValue)
Definition: NdArrayCore.hpp:3827
self_type prod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3556
NdArray(Iterator inFirst, Iterator inLast)
Definition: NdArrayCore.hpp:487
reference at(index_type inIndex)
Definition: NdArrayCore.hpp:987
reverse_column_iterator rcolbegin() noexcept
Definition: NdArrayCore.hpp:1499
self_type & reshape(const Shape &inShape)
Definition: NdArrayCore.hpp:4309
self_type at(const Indices &inIndices) const
Definition: NdArrayCore.hpp:1094
const_iterator cbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1330
const_column_iterator ccolend(size_type inCol) const
Definition: NdArrayCore.hpp:1792
self_type at(index_type rowIndex, const Indices &colIndices) const
Definition: NdArrayCore.hpp:1194
const_iterator cend(size_type inRow) const
Definition: NdArrayCore.hpp:1638
self_type & reshape(index_type inNumRows, index_type inNumCols)
Definition: NdArrayCore.hpp:4255
self_type getByIndices(const NdArray< size_type > &inIndices) const
Definition: NdArrayCore.hpp:2858
const_reverse_column_iterator rcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1846
const_iterator end(size_type inRow) const
Definition: NdArrayCore.hpp:1615
self_type flatten() const
Definition: NdArrayCore.hpp:2800
reference back() noexcept
Definition: NdArrayCore.hpp:2251
const_reverse_column_iterator crcolend() const noexcept
Definition: NdArrayCore.hpp:1857
const_reference back(size_type row) const
Definition: NdArrayCore.hpp:2262
reverse_column_iterator rcolbegin(size_type inCol)
Definition: NdArrayCore.hpp:1511
NdArray(const std::deque< std::deque< dtype >> &in2dDeque)
Definition: NdArrayCore.hpp:435
iterator begin(size_type inRow)
Definition: NdArrayCore.hpp:1280
const_reverse_iterator rend() const noexcept
Definition: NdArrayCore.hpp:1680
self_type copy() const
Definition: NdArrayCore.hpp:2439
self_type round(uint8 inNumDecimals=0) const
Definition: NdArrayCore.hpp:4410
self_type swapaxes() const
Definition: NdArrayCore.hpp:4612
const_reverse_column_iterator rcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1538
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:3811
const_iterator end() const noexcept
Definition: NdArrayCore.hpp:1603
bool ownsInternalData() noexcept
Definition: NdArrayCore.hpp:3454
self_type operator[](const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:788
column_iterator colend() noexcept
Definition: NdArrayCore.hpp:1730
NdArray(std::initializer_list< dtype > inList)
Definition: NdArrayCore.hpp:221
self_type & operator=(self_type &&rhs) noexcept
Definition: NdArrayCore.hpp:684
self_type at(const Indices &rowIndices, Slice colSlice) const
Definition: NdArrayCore.hpp:1180
self_type & put(const Slice &inSlice, const self_type &inValues)
Definition: NdArrayCore.hpp:3747
const_reference back() const noexcept
Definition: NdArrayCore.hpp:2240
self_type & operator=(const self_type &rhs)
Definition: NdArrayCore.hpp:643
std::pair< NdArray< size_type >, NdArray< size_type > > nonzero() const
Definition: NdArrayCore.hpp:4922
self_type diagonal(index_type inOffset=0, Axis inAxis=Axis::ROW) const
Definition: NdArrayCore.hpp:2592
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:1136
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:3663
uint64 nbytes() const noexcept
Definition: NdArrayCore.hpp:3186
self_type & put(const RowIndices &inRowIndices, const ColIndices &inColIndices, const self_type &inValues)
Definition: NdArrayCore.hpp:3917
self_type & putMask(const NdArray< bool > &inMask, const self_type &inValues)
Definition: NdArrayCore.hpp:4105
self_type at(const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:1076
NdArray(const std::list< dtype > &inList)
Definition: NdArrayCore.hpp:467
const_reference front() const noexcept
Definition: NdArrayCore.hpp:2813
~NdArray() noexcept
Definition: NdArrayCore.hpp:621
Slice rSlice(index_type inStartIdx=0, size_type inStepSize=1) const
Definition: NdArrayCore.hpp:975
reference front() noexcept
Definition: NdArrayCore.hpp:2824
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:3681
void print() const
Definition: NdArrayCore.hpp:3540
self_type & byteswap() noexcept
Definition: NdArrayCore.hpp:2286
const_reverse_column_iterator crcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1561
self_type & put(const RowIndices &inRowIndices, const ColIndices &inColIndices, const value_type &inValue)
Definition: NdArrayCore.hpp:3767
size_type numRows() const noexcept
Definition: NdArrayCore.hpp:3430
reverse_iterator rend(size_type inRow)
Definition: NdArrayCore.hpp:1665
NdArray(size_type inSquareSize)
Definition: NdArrayCore.hpp:181
self_type at(const Indices &rowIndices, index_type colIndex) const
Definition: NdArrayCore.hpp:1165
reverse_iterator rend() noexcept
Definition: NdArrayCore.hpp:1653
const_reverse_iterator rend(size_type inRow) const
Definition: NdArrayCore.hpp:1692
typename AllocTraits::const_pointer const_pointer
Definition: NdArrayCore.hpp:152
const_reverse_iterator crbegin() const noexcept
Definition: NdArrayCore.hpp:1472
const_column_iterator colend(size_type inCol) const
Definition: NdArrayCore.hpp:1769
self_type & operator=(value_type inValue) noexcept
Definition: NdArrayCore.hpp:667
self_type & put(const RowIndices &inRowIndices, Slice inColSlice, const self_type &inValues)
Definition: NdArrayCore.hpp:3973
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:3861
self_type & put(Slice inRowSlice, const ColIndices &inColIndices, const self_type &inValues)
Definition: NdArrayCore.hpp:3990
NdArray(const std::vector< std::vector< dtype >> &in2dVector)
Definition: NdArrayCore.hpp:356
const_reverse_iterator rbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1461
self_type operator[](const Indices &inIndices) const
Definition: NdArrayCore.hpp:802
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1626
self_type & put(index_type inRowIndex, const Slice &inColSlice, const value_type &inValue)
Definition: NdArrayCore.hpp:3896
std::string str() const
Definition: NdArrayCore.hpp:4535
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:2505
self_type & put(Slice inRowSlice, Slice inColSlice, const self_type &inValues)
Definition: NdArrayCore.hpp:4006
reference front(size_type row)
Definition: NdArrayCore.hpp:2846
self_type & nans() noexcept
Definition: NdArrayCore.hpp:3169
self_type & partition(size_type inKth, Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:3474
self_type repeat(size_type inNumRows, size_type inNumCols) const
Definition: NdArrayCore.hpp:4148
NdArray< size_type > argmax(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1977
NdArray(pointer inPtr, size_type numRows, size_type numCols, BoolType takeOwnership) noexcept
Definition: NdArrayCore.hpp:572
NdArray< size_type > flatnonzero() const
Definition: NdArrayCore.hpp:2774
const_iterator begin(size_type inRow) const
Definition: NdArrayCore.hpp:1307
iterator begin() noexcept
Definition: NdArrayCore.hpp:1268
self_type & put(const RowIndices &inRowIndices, const Slice &inColSlice, const value_type &inValue)
Definition: NdArrayCore.hpp:3794
const_column_iterator colbegin() const noexcept
Definition: NdArrayCore.hpp:1372
bool isscalar() const noexcept
Definition: NdArrayCore.hpp:2909
std::reverse_iterator< column_iterator > reverse_column_iterator
Definition: NdArrayCore.hpp:166
self_type operator()(Slice inRowSlice, Slice inColSlice) const
Definition: NdArrayCore.hpp:823
self_type newbyteorder(Endian inEndianess) const
Definition: NdArrayCore.hpp:3201
value_type item() const
Definition: NdArrayCore.hpp:2975
const_reference at(index_type inIndex) const
Definition: NdArrayCore.hpp:999
const_column_iterator colend() const noexcept
Definition: NdArrayCore.hpp:1757
self_type row(size_type inRow) const
Definition: NdArrayCore.hpp:4431
self_type operator()(const Indices &rowIndices, index_type colIndex) const
Definition: NdArrayCore.hpp:868
self_type at(const Slice &inRowSlice, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1123
self_type operator()(Slice inRowSlice, index_type inColIndex) const
Definition: NdArrayCore.hpp:837
const_reverse_iterator crend() const noexcept
Definition: NdArrayCore.hpp:1703
self_type & sort(Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:4491
self_type operator()(index_type rowIndex, const Indices &colIndices) const
Definition: NdArrayCore.hpp:899
NdArray< dtype, Allocator > self_type
Definition: NdArrayCore.hpp:148
const_column_iterator colbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1384
self_type cumprod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2453
NdArray< bool > contains(value_type inValue, Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2398
const_column_iterator ccolend() const noexcept
Definition: NdArrayCore.hpp:1780
reference operator()(index_type inRowIndex, index_type inColIndex) noexcept
Definition: NdArrayCore.hpp:740
self_type operator()(index_type inRowIndex, Slice inColSlice) const
Definition: NdArrayCore.hpp:852
reverse_column_iterator rcolend() noexcept
Definition: NdArrayCore.hpp:1807
NdArray(std::array< dtype, ArraySize > &inArray, bool copy=true)
Definition: NdArrayCore.hpp:274
const_reverse_iterator rbegin() const noexcept
Definition: NdArrayCore.hpp:1449
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:4201
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:3702
void dump(const std::string &inFilename) const
Definition: NdArrayCore.hpp:2718
dtype & reference
Definition: NdArrayCore.hpp:153
value_type trace(size_type inOffset=0, Axis inAxis=Axis::ROW) const noexcept
Definition: NdArrayCore.hpp:4784
pointer dataRelease() noexcept
Definition: NdArrayCore.hpp:2575
self_type ptp(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3600
self_type & put(const Slice &inSlice, const value_type &inValue)
Definition: NdArrayCore.hpp:3732
self_type clip(value_type inMin, value_type inMax) const
Definition: NdArrayCore.hpp:2326
self_type getByMask(const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:2872
self_type & swapRows(index_type rowIdx1, index_type rowIdx2) noexcept
Definition: NdArrayCore.hpp:4643
uint32 size_type
Definition: NdArrayCore.hpp:155
const_iterator begin() const noexcept
Definition: NdArrayCore.hpp:1295
column_iterator colend(size_type inCol)
Definition: NdArrayCore.hpp:1742
const_reference operator[](index_type inIndex) const noexcept
Definition: NdArrayCore.hpp:722
self_type operator()(Slice rowSlice, const Indices &colIndices) const
Definition: NdArrayCore.hpp:915
const_reference operator()(index_type inRowIndex, index_type inColIndex) const noexcept
Definition: NdArrayCore.hpp:753
self_type min(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3038
dtype value_type
Definition: NdArrayCore.hpp:149
const Shape & shape() const noexcept
Definition: NdArrayCore.hpp:4464
reference operator[](index_type inIndex) noexcept
Definition: NdArrayCore.hpp:710
Slice cSlice(index_type inStartIdx=0, size_type inStepSize=1) const
Definition: NdArrayCore.hpp:961
self_type & put(index_type inRowIndex, const Indices &inColIndices, const self_type &inValues)
Definition: NdArrayCore.hpp:4058
NdArray< size_type > argsort(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2070
const_reverse_iterator crend(size_type inRow) const
Definition: NdArrayCore.hpp:1715
const_reverse_iterator crbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1484
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:4571
self_type operator()(const Indices &rowIndices, Slice colSlice) const
Definition: NdArrayCore.hpp:884
NdArray< bool > all(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1888
self_type & resizeSlow(size_type inNumRows, size_type inNumCols)
Definition: NdArrayCore.hpp:4356
self_type & resizeSlow(const Shape &inShape)
Definition: NdArrayCore.hpp:4395
self_type & putMask(const NdArray< bool > &inMask, const value_type &inValue)
Definition: NdArrayCore.hpp:4088
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
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: Core/Constants.hpp:42
const double nan
NaN.
Definition: Core/Constants.hpp:41
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: Cartesian.hpp:40
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