34#include <forward_list>
36#include <initializer_list>
86 template<
typename dtype,
typename Allocator>
89 static constexpr bool value = std::is_integral_v<dtype>;
113 template<
typename dtype,
typename Allocator>
116 static constexpr bool value = std::is_signed_v<dtype>;
137 template<
typename dtype,
class Allocator = std::allocator<dtype>>
141 STATIC_ASSERT_VALID_DTYPE(dtype);
142 static_assert(std::is_same_v<dtype, typename Allocator::value_type>,
143 "value_type and Allocator::value_type must match");
145 using AllocType =
typename std::allocator_traits<Allocator>::template rebind_alloc<dtype>;
146 using AllocTraits = std::allocator_traits<AllocType>;
152 using pointer =
typename AllocTraits::pointer;
183 shape_{ inSquareSize, inSquareSize },
184 size_{ inSquareSize * inSquareSize }
197 shape_{ inNumRows, inNumCols },
198 size_{ inNumRows * inNumCols }
211 size_{ shape_.
size() }
222 NdArray(std::initializer_list<dtype> inList) :
223 shape_{ 1, static_cast<
uint32>(inList.
size()) },
224 size_{ shape_.
size() }
239 NdArray(
const std::initializer_list<std::initializer_list<dtype>>& inList) :
240 shape_{ static_cast<
uint32>(inList.
size()), 0 }
242 for (
const auto& list : inList)
244 if (shape_.
cols == 0)
246 shape_.
cols =
static_cast<uint32>(list.size());
248 else if (list.size() != shape_.
cols)
251 "All rows of the initializer list needs to have the same number of elements");
255 size_ = shape_.
size();
258 for (
const auto& list : inList)
273 template<
size_t ArraySize, std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
275 shape_{ 1, static_cast<
uint32>(ArraySize) },
276 size_{ shape_.
size() }
291 array_ = inArray.data();
309 template<
size_t Dim0Size,
size_t Dim1Size>
310 NdArray(std::array<std::array<dtype, Dim1Size>, Dim0Size>& in2dArray,
312 shape_{ static_cast<
uint32>(Dim0Size), static_cast<
uint32>(Dim1Size) },
313 size_{ shape_.
size() }
322 const auto start = in2dArray.front().begin();
329 array_ = in2dArray.front().data();
347 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
349 shape_{ 1, static_cast<
uint32>(inVector.
size()) },
350 size_{ shape_.
size() }
365 array_ = inVector.data();
382 explicit NdArray(
const std::vector<std::vector<dtype>>& in2dVector) :
383 shape_{ static_cast<
uint32>(in2dVector.
size()), 0 }
385 for (
const auto&
row : in2dVector)
387 if (shape_.
cols == 0)
397 size_ = shape_.
size();
400 auto currentPosition =
begin();
401 for (
const auto&
row : in2dVector)
404 currentPosition += shape_.
cols;
415 template<
size_t Dim1Size>
417 shape_{ static_cast<
uint32>(in2dArray.
size()), static_cast<
uint32>(Dim1Size) },
418 size_{ shape_.
size() }
427 const auto start = in2dArray.front().begin();
434 array_ = in2dArray.front().data();
451 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
452 explicit NdArray(
const std::deque<dtype>& inDeque) :
453 shape_{ 1, static_cast<
uint32>(inDeque.
size()) },
454 size_{ shape_.
size() }
469 explicit NdArray(
const std::deque<std::deque<dtype>>& in2dDeque) :
470 shape_{ static_cast<
uint32>(in2dDeque.
size()), 0 }
472 for (
const auto&
row : in2dDeque)
474 if (shape_.
cols == 0)
484 size_ = shape_.
size();
487 auto currentPosition =
begin();
488 for (
const auto&
row : in2dDeque)
491 currentPosition += shape_.
cols;
501 explicit NdArray(
const std::list<dtype>& inList) :
502 shape_{ 1, static_cast<
uint32>(inList.
size()) },
503 size_{ shape_.
size() }
519 template<
typename Iterator,
520 std::enable_if_t<std::is_same_v<typename std::iterator_traits<Iterator>::value_type, dtype>,
int> = 0>
522 shape_{ 1, static_cast<
uint32>(std::distance(inFirst, inLast)) },
523 size_{ shape_.
size() }
539 template<
typename UIntType,
540 std::enable_if_t<std::is_integral_v<UIntType> && !std::is_same_v<UIntType, bool>,
int> = 0>
554 template<
typename UIntType1,
556 std::enable_if_t<std::is_integral_v<UIntType1> && !std::is_same_v<UIntType1, bool>,
int> = 0,
557 std::enable_if_t<std::is_integral_v<UIntType2> && !std::is_same_v<UIntType2, bool>,
int> = 0>
560 size_{ shape_.
size() }
563 if (inPtr !=
nullptr && size_ > 0)
578 template<
typename UIntType,
579 std::enable_if_t<std::is_integral_v<UIntType> && !std::is_same_v<UIntType, bool>,
int> = 0>
595 template<
typename UIntType1,
597 std::enable_if_t<std::is_integral_v<UIntType1> && !std::is_same_v<UIntType1, bool>,
int> = 0,
598 std::enable_if_t<std::is_integral_v<UIntType2> && !std::is_same_v<UIntType2, bool>,
int> = 0>
601 size_{ shape_.
size() }
608 if (inPtr !=
nullptr && size_ > 0)
634 shape_{ inOtherArray.shape_ },
635 size_{ inOtherArray.size_ },
636 endianess_{ inOtherArray.endianess_ }
652 shape_{ inOtherArray.shape_ },
653 size_{ inOtherArray.size_ },
654 endianess_{ inOtherArray.endianess_ },
655 array_{ inOtherArray.array_ },
656 ownsPtr_{ inOtherArray.ownsPtr_ }
658 inOtherArray.shape_.rows = inOtherArray.shape_.cols = 0;
659 inOtherArray.size_ = 0;
660 inOtherArray.ownsPtr_ =
false;
661 inOtherArray.array_ =
nullptr;
678 explicit operator bool() const noexcept
696 newArray(rhs.shape_);
697 endianess_ = rhs.endianess_;
716 if (array_ !=
nullptr)
738 endianess_ = rhs.endianess_;
740 ownsPtr_ = rhs.ownsPtr_;
742 rhs.shape_.rows = rhs.shape_.cols = rhs.size_ = 0;
743 rhs.array_ =
nullptr;
744 rhs.ownsPtr_ =
false;
759 return const_cast<reference>(
const_cast<const self_type*
>(
this)->
operator[](inIndex));
776 return array_[inIndex];
789 return const_cast<reference>(
const_cast<const self_type*
>(
this)->
operator()(inRowIndex, inColIndex));
804 inRowIndex += shape_.
rows;
809 inColIndex += shape_.
cols;
812 return array_[inRowIndex * shape_.
cols + inColIndex];
848 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
853 for (
auto& index : inIndices)
914 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
930 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
945 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
961 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
976 template<
typename RowIndices,
982 self_type returnArray(rowIndices.size(), colIndices.size());
985 for (
auto rowIter = rowIndices.begin(); rowIter != rowIndices.end(); ++rowIter)
988 for (
auto colIter = colIndices.begin(); colIter != colIndices.end(); ++colIter)
990 returnArray(rowCounter, colCounter++) =
operator()(*rowIter, *colIter);
1010 return Slice(inStartIdx, shape_.
cols, inStepSize);
1024 return Slice(inStartIdx, shape_.
rows, inStepSize);
1053 errStr +=
" is out of bounds for array of size " +
utils::num2str(size_) +
".";
1088 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
rows) +
".";
1096 std::string errStr =
"Column index " +
utils::num2str(inColIndex);
1097 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
cols) +
".";
1125 if (inMask.
shape() != shape_)
1140 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1147 auto indexSigned = static_cast<index_type>(index);
1148 if (indexSigned < 0)
1150 indexSigned += size_;
1153 if (indexSigned < 0 || indexSigned >
static_cast<index_type>(size_ - 1))
1186 return at(toIndices(inRowSlice,
Axis::ROW), colIndices);
1200 return at(rowIndices, toIndices(inColSlice,
Axis::COL));
1211 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1215 return at(rowIndices, colIndices);
1226 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1229 return at(rowIndices, toIndices(colSlice,
Axis::COL));
1240 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1244 return at(rowIndices, colIndices);
1255 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1258 return at(toIndices(rowSlice,
Axis::ROW), colIndices);
1269 template<
typename RowIndices,
1270 typename ColIndices,
1273 [[nodiscard]]
self_type at(
const RowIndices& rowIndices,
const ColIndices& colIndices)
const
1279 auto rowSigned = static_cast<index_type>(row);
1282 rowSigned += shape_.rows;
1285 if (rowSigned < 0 || rowSigned >
static_cast<index_type>(shape_.rows - 1))
1287 THROW_INVALID_ARGUMENT_ERROR(
"Row index exceeds matrix dimensions");
1295 auto colSigned = static_cast<index_type>(col);
1298 colSigned += shape_.cols;
1301 if (colSigned < 0 || colSigned >
static_cast<index_type
>(shape_.cols - 1))
1303 THROW_INVALID_ARGUMENT_ERROR(
"Column index exceeds matrix dimensions");
1307 return operator()(rowIndices, colIndices);
1329 if (inRow >= shape_.rows)
1334 return begin() += (inRow * shape_.cols);
1356 return cbegin(inRow);
1379 if (inRow >= shape_.rows)
1384 return cbegin() += (inRow * shape_.cols);
1406 if (inCol >= shape_.cols)
1411 return colbegin() += (inCol * shape_.rows);
1433 return ccolbegin(inCol);
1456 if (inCol >= shape_.cols)
1461 return ccolbegin() += (inCol * shape_.rows);
1483 if (inRow >= shape_.rows)
1488 return rbegin() += (shape_.rows - inRow - 1) * shape_.cols;
1510 return crbegin(inRow);
1533 if (inRow >= shape_.rows)
1538 return crbegin() += (shape_.rows - inRow - 1) * shape_.cols;
1560 if (inCol >= shape_.cols)
1565 return rcolbegin() += (shape_.cols - inCol - 1) * shape_.rows;
1575 return crcolbegin();
1587 return crcolbegin(inCol);
1610 if (inCol >= shape_.cols)
1615 return crcolbegin() += (shape_.cols - inCol - 1) * shape_.rows;
1625 return begin() += size_;
1637 if (inRow >= shape_.rows)
1642 return begin(inRow) += shape_.cols;
1675 return cbegin() += size_;
1687 if (inRow >= shape_.rows)
1692 return cbegin(inRow) += shape_.cols;
1702 return rbegin() += size_;
1714 if (inRow >= shape_.rows)
1719 return rbegin(inRow) += shape_.cols;
1741 return crend(inRow);
1752 return crbegin() += size_;
1764 if (inRow >= shape_.rows)
1769 return crbegin(inRow) += shape_.cols;
1779 return colbegin() += size_;
1791 if (inCol >= shape_.cols)
1796 return colbegin(inCol) += shape_.rows;
1818 return ccolend(inCol);
1829 return ccolbegin() += size_;
1841 if (inCol >= shape_.cols)
1846 return ccolbegin(inCol) += shape_.rows;
1856 return rcolbegin() += size_;
1868 if (inCol >= shape_.cols)
1873 return rcolbegin(inCol) += shape_.rows;
1895 return crcolend(inCol);
1906 return crcolbegin() += size_;
1918 if (inCol >= shape_.cols)
1923 return crcolbegin(inCol) += shape_.rows;
1951 for (
uint32 row = 0; row < shape_.rows; ++row)
1995 for (
uint32 row = 0; row < shape_.rows; ++row)
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>(
2075 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
2088 for (
size_type row = 0; row < shape_.rows; ++row)
2090 returnArray(0, row) =
static_cast<size_type>(
2135 std::vector<size_type> idx(size_);
2136 std::iota(idx.begin(), idx.end(), 0);
2139 {
return (*
this)[i1] < (*this)[i2]; };
2146 if (inKth >= shape_.cols)
2149 errStr +=
") out of bounds (" +
utils::num2str(shape_.cols) +
")";
2154 std::vector<size_type> idx(shape_.cols);
2156 for (
uint32 row = 0; row < shape_.rows; ++row)
2158 std::iota(idx.begin(), idx.end(), 0);
2161 {
return operator()(row, i1) < operator()(row, i2); };
2165 for (
index_type col = 0; col < static_cast<index_type>(shape_.cols); ++col)
2167 returnArray(row, col) = idx[
static_cast<size_type>(col)];
2174 return transpose().argpartition(inKth, Axis::COL).transpose();
2201 std::vector<size_type> idx(size_);
2202 std::iota(idx.begin(), idx.end(), 0);
2205 {
return (*
this)[i1] < (*this)[i2]; };
2213 std::vector<size_type> idx(shape_.cols);
2215 for (
index_type row = 0; row < static_cast<index_type>(shape_.rows); ++row)
2217 std::iota(idx.begin(), idx.end(), 0);
2220 {
return operator()(row, i1) < operator()(row, i2); };
2224 for (
index_type col = 0; col < static_cast<index_type>(shape_.cols); ++col)
2226 returnArray(row, col) = idx[
static_cast<size_type>(col)];
2233 return transpose().argsort(Axis::COL).transpose();
2252 template<
typename dtypeOut,
2253 typename dtype_ = dtype,
2254 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2255 std::enable_if_t<std::is_arithmetic_v<dtype_>,
int> = 0,
2256 std::enable_if_t<std::is_arithmetic_v<dtypeOut>,
int> = 0>
2259 if constexpr (std::is_same_v<dtypeOut, dtype>)
2269 [](dtype value) -> dtypeOut { return static_cast<dtypeOut>(value); });
2284 template<
typename dtypeOut,
2285 typename dtype_ = dtype,
2286 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2287 std::enable_if_t<std::is_arithmetic_v<dtype_>,
int> = 0,
2288 std::enable_if_t<is_complex_v<dtypeOut>,
int> = 0>
2294 {
return std::complex<typename dtypeOut::value_type>(value); };
2310 template<
typename dtypeOut,
2311 typename dtype_ = dtype,
2312 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2313 std::enable_if_t<is_complex_v<dtype_>,
int> = 0,
2314 std::enable_if_t<is_complex_v<dtypeOut>,
int> = 0>
2317 if constexpr (std::is_same_v<dtypeOut, dtype>)
2324 {
return complex_cast<typename dtypeOut::value_type>(value); };
2341 template<
typename dtypeOut,
2342 typename dtype_ = dtype,
2343 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2344 std::enable_if_t<is_complex_v<dtype_>,
int> = 0,
2345 std::enable_if_t<std::is_arithmetic_v<dtypeOut>,
int> = 0>
2350 const auto function = [](
const_reference value) -> dtypeOut {
return static_cast<dtypeOut
>(value.real()); };
2365 return *(cend() - 1);
2376 return *(end() - 1);
2387 return *(cend(row) - 1);
2398 return *(end(row) - 1);
2419 case Endian::NATIVE:
2424 case Endian::LITTLE:
2426 endianess_ = Endian::BIG;
2431 endianess_ = Endian::LITTLE;
2457 [inMin, inMax](dtype value) noexcept -> dtype
2459#ifdef __cpp_lib_clamp
2460 const auto comparitor = [](dtype lhs, dtype rhs) noexcept -> bool
2461 { return lhs < rhs; };
2463 return std::clamp(value, inMin, inMax, comparitor);
2469 else if (value > inMax)
2490 return operator()(rSlice(), inColumn);
2503 const auto rSlice = returnArray.rSlice();
2507 returnArray.put(rSlice, i, column(inCols[i]));
2535 for (
size_type row = 0; row < shape_.rows; ++row)
2544 return transpose().contains(inValue, Axis::COL);
2585 returnArray[0] = front();
2588 returnArray[i] = returnArray[i - 1] * array_[i];
2596 for (
uint32 row = 0; row < shape_.rows; ++row)
2598 returnArray(row, 0) = operator()(row, 0);
2599 for (
uint32 col = 1; col < shape_.cols; ++col)
2601 returnArray(row, col) = returnArray(row, col - 1) * operator()(row, col);
2609 return transpose().cumprod(Axis::COL).transpose();
2637 returnArray[0] = front();
2640 returnArray[i] = returnArray[i - 1] + array_[i];
2648 for (
uint32 row = 0; row < shape_.rows; ++row)
2650 returnArray(row, 0) = operator()(row, 0);
2651 for (
uint32 col = 1; col < shape_.cols; ++col)
2653 returnArray(row, col) = returnArray(row, col - 1) + operator()(row, col);
2661 return transpose().cumsum(Axis::COL).transpose();
2721 std::vector<dtype> diagnolValues;
2723 for (
index_type row = inOffset; row < static_cast<index_type>(shape_.rows); ++row)
2730 if (col >= shape_.cols)
2735 diagnolValues.push_back(
operator()(
static_cast<size_type>(row), col));
2743 return transpose().diagonal(inOffset, Axis::COL);
2799 if (shape_ == inOtherArray.shape_ && (shape_.rows == 1 || shape_.cols == 1))
2807 if (shape_.cols == inOtherArray.shape_.
rows)
2810 self_type returnArray(shape_.rows, inOtherArray.shape_.
cols);
2811 auto otherArrayT = inOtherArray.
transpose();
2813 for (
uint32 i = 0; i < shape_.rows; ++i)
2815 for (
uint32 j = 0;
j < otherArrayT.shape_.rows; ++
j)
2818 otherArrayT.cend(
j),
2830 errStr +=
" are not consistent.";
2845 void dump(
const std::string& inFilename)
const
2847 std::filesystem::path
f(inFilename);
2848 if (!
f.has_extension())
2850 f.replace_extension(
"bin");
2853 std::ofstream ofile(
f.c_str(), std::ios::binary);
2859 if (array_ !=
nullptr)
2861 ofile.write(
reinterpret_cast<const char*
>(array_), size_ *
sizeof(dtype));
2905 std::vector<size_type> indices;
2907 for (
auto value : *
this)
2911 indices.push_back(idx);
2964 return *cbegin(row);
2987 return operator[](inIndices);
3001 return operator[](inMask);
3027 return !isscalar() && (shape_.rows == 1 || shape_.cols == 1);
3052 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3063 for (
uint32 row = 0; row < shape_.rows; ++row)
3091 return shape_.issquare();
3125 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3137 for (
uint32 row = 0; row < shape_.rows; ++row)
3169 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3181 for (
uint32 row = 0; row < shape_.rows; ++row)
3215 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3230 copyArray.
begin() + middleIdx,
3234 dtype medianValue = copyArray.array_[middleIdx];
3237 const size_type lhsIndex = middleIdx - 1;
3239 copyArray.
begin() + lhsIndex,
3243 (medianValue + copyArray.array_[lhsIndex]) / dtype{ 2 };
3246 return { medianValue };
3253 const bool isEven = shape_.cols % 2 == 0;
3254 for (
uint32 row = 0; row < shape_.rows; ++row)
3256 const uint32 middleIdx = shape_.cols / 2;
3258 copyArray.
begin(row) + middleIdx,
3262 dtype medianValue = copyArray(row, middleIdx);
3265 const size_type lhsIndex = middleIdx - 1;
3267 copyArray.
begin(row) + lhsIndex,
3270 medianValue = (medianValue + copyArray(row, lhsIndex)) /
3274 returnArray(0, row) = medianValue;
3315 return static_cast<uint64>(
sizeof(dtype) * size_);
3336 case Endian::NATIVE:
3338 switch (inEndianess)
3340 case Endian::NATIVE:
3352 outArray.endianess_ = Endian::BIG;
3357 auto outArray =
NdArray(*
this);
3358 outArray.endianess_ = Endian::BIG;
3362 case Endian::LITTLE:
3366 auto outArray =
NdArray(*
this);
3367 outArray.endianess_ = Endian::LITTLE;
3376 outArray.endianess_ = Endian::LITTLE;
3390 switch (inEndianess)
3392 case Endian::NATIVE:
3400 outArray.endianess_ = Endian::NATIVE;
3405 auto outArray =
NdArray(*
this);
3406 outArray.endianess_ = Endian::NATIVE;
3414 case Endian::LITTLE:
3420 outArray.endianess_ = Endian::LITTLE;
3431 case Endian::LITTLE:
3433 switch (inEndianess)
3435 case Endian::NATIVE:
3439 auto outArray =
NdArray(*
this);
3440 outArray.endianess_ = Endian::NATIVE;
3449 outArray.endianess_ = Endian::NATIVE;
3459 outArray.endianess_ = Endian::BIG;
3462 case Endian::LITTLE:
3507 for (
uint32 row = 0; row < shape_.rows; ++row)
3605 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool
3606 {
return lhs < rhs; };
3624 if (inKth >= shape_.cols)
3627 errStr +=
") out of bounds (" +
utils::num2str(shape_.cols) +
")";
3631 for (
uint32 row = 0; row < shape_.rows; ++row)
3639 if (inKth >= shape_.rows)
3642 errStr +=
") out of bounds (" +
utils::num2str(shape_.rows) +
")";
3647 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3650 transposedArray.
begin(row) + inKth,
3651 transposedArray.
end(row),
3691 dtype product = std::accumulate(cbegin(), cend(), dtype{ 1 }, std::multiplies<dtype>());
3698 for (
uint32 row = 0; row < shape_.rows; ++row)
3700 returnArray(0, row) =
3701 std::accumulate(cbegin(row), cend(row), dtype{ 1 }, std::multiplies<dtype>());
3731 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3738 self_type returnArray = { *result.second - *result.first };
3744 for (
uint32 row = 0; row < shape_.rows; ++row)
3747 returnArray(0, row) = *result.second - *result.first;
3775 at(inIndex) = inValue;
3792 at(inRow, inCol) = inValue;
3807 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3810 for (
auto index : inIndices)
3812 put(index, inValue);
3828 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3833 return put(inIndices, inValues.
item());
3835 else if (inIndices.size() != inValues.
size())
3841 for (
auto index : inIndices)
3843 put(index, inValues[counter++]);
3861 return put(toIndices(inSlice, Axis::NONE), inValue);
3876 return put(toIndices(inSlice, Axis::NONE), inValues);
3890 template<
typename RowIndices,
3891 typename ColIndices,
3898 [
this, &inColIndices, &inValue](
const auto row)
3900 stl_algorithms::for_each(inColIndices.begin(),
3902 [this, row, &inValue](const auto col)
3903 { this->put(row, col, inValue); });
3920 template<
typename RowIndices, type_traits::ndarray_
int_concept<RowIndices> = 0>
3923 return put(inRowIndices, toIndices(inColSlice, Axis::COL), inValue);
3937 template<
typename ColIndices, type_traits::ndarray_
int_concept<ColIndices> = 0>
3940 return put(toIndices(inRowSlice, Axis::ROW), inColIndices, inValue);
3956 return put(toIndices(inRowSlice, Axis::ROW), toIndices(inColSlice, Axis::COL), inValue);
3970 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3974 return put(inRowIndices, colIndices, inValue);
3991 return put(toIndices(inRowSlice, Axis::ROW), colIndices, inValue);
4005 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
4009 return put(rowIndices, inColIndices, inValue);
4026 return put(rowIndices, toIndices(inColSlice, Axis::COL), inValue);
4040 template<
typename RowIndices,
4041 typename ColIndices,
4046 std::vector<size_type> indices;
4047 indices.reserve(inRowIndices.size() * inColIndices.size());
4050 [
this, &inColIndices, &indices](
auto row)
4052 if constexpr (std::is_signed_v<decltype(row)>)
4061 THROW_INVALID_ARGUMENT_ERROR(
"row index exceeds matrix dimensions");
4066 [
this, row, &indices](
auto col)
4068 if constexpr (std::is_signed_v<decltype(col)>)
4077 THROW_INVALID_ARGUMENT_ERROR(
4078 "col index exceeds matrix dimensions");
4081 indices.push_back(row * shape_.cols + col);
4085 return put(NdArray<size_type>(indices.data(), indices.size(), PointerPolicy::SHELL), inValues);
4099 template<
typename RowIndices, type_traits::ndarray_
int_concept<RowIndices> = 0>
4102 return put(inRowIndices, toIndices(inColSlice, Axis::COL), inValues);
4116 template<
typename ColIndices, type_traits::ndarray_
int_concept<ColIndices> = 0>
4119 return put(toIndices(inRowSlice, Axis::ROW), inColIndices, inValues);
4135 return put(toIndices(inRowSlice, Axis::ROW), toIndices(inColSlice, Axis::COL), inValues);
4149 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
4153 return put(inRowIndices, colIndices, inValues);
4170 return put(toIndices(inRowSlice, Axis::ROW), colIndices, inValues);
4184 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
4188 return put(rowIndices, inColIndices, inValues);
4205 return put(rowIndices, toIndices(inColSlice, Axis::COL), inValues);
4217 if (inMask.
shape() != shape_)
4234 if (inMask.
shape() != shape_)
4277 self_type returnArray(shape_.rows * inNumRows, shape_.cols * inNumCols);
4279 for (
size_type row = 0; row < inNumRows; ++row)
4281 for (
size_type col = 0; col < inNumCols; ++col)
4283 std::vector<size_type> indices(shape_.size());
4285 const size_type rowStart = row * shape_.rows;
4286 const size_type colStart = col * shape_.cols;
4288 const size_type rowEnd = (row + 1) * shape_.rows;
4289 const size_type colEnd = (col + 1) * shape_.cols;
4292 for (
size_type rowIdx = rowStart; rowIdx < rowEnd; ++rowIdx)
4294 for (
size_type colIdx = colStart; colIdx < colEnd; ++colIdx)
4296 indices[counter++] = rowIdx * returnArray.shape_.
cols + colIdx;
4353 if (inSize != size_)
4355 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4361 shape_.cols = inSize;
4386 if (size_ % inNumCols == 0)
4388 return reshape(size_ / inNumCols, inNumCols);
4391 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4398 if (size_ % inNumRows == 0)
4400 return reshape(inNumRows, size_ / inNumRows);
4403 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4408 if (
static_cast<size_type>(inNumRows * inNumCols) != size_)
4410 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4415 shape_.rows =
static_cast<size_type>(inNumRows);
4416 shape_.cols =
static_cast<size_type>(inNumCols);
4453 newArray(
Shape(inNumRows, inNumCols));
4485 std::vector<dtype> oldData(size_);
4488 const Shape inShape(inNumRows, inNumCols);
4489 const Shape oldShape = shape_;
4493 for (
uint32 row = 0; row < inShape.
rows; ++row)
4495 for (
uint32 col = 0; col < inShape.
cols; ++col)
4497 if (row >= oldShape.
rows || col >= oldShape.
cols)
4499 operator()(row, col) = dtype{ 0 };
4503 operator()(row, col) = oldData[row * oldShape.
cols + col];
4542 const double multFactor =
utils::power(10., inNumDecimals);
4543 const auto function = [multFactor](dtype value)
noexcept -> dtype
4544 {
return static_cast<dtype
>(std::nearbyint(
static_cast<double>(value) * multFactor) / multFactor); };
4560 return self_type(cbegin(inRow), cend(inRow));
4573 const auto cSlice = returnArray.cSlice();
4577 returnArray.put(i, cSlice, row(inRows[i]));
4622 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool
4623 {
return lhs < rhs; };
4634 for (
uint32 row = 0; row < shape_.rows; ++row)
4643 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
4662 [[nodiscard]] std::string
str()
const
4668 for (
uint32 row = 0; row < shape_.rows; ++row)
4671 for (
uint32 col = 0; col < shape_.cols; ++col)
4676 if (row == shape_.rows - 1)
4706 self_type returnArray = { std::accumulate(cbegin(), cend(), dtype{ 0 }) };
4712 for (
uint32 row = 0; row < shape_.rows; ++row)
4714 returnArray(0, row) = std::accumulate(cbegin(row), cend(row), dtype{ 0 });
4754 for (
index_type row = 0; row < static_cast<index_type>(shape_.rows); ++row)
4756 std::swap(
operator()(row, colIdx1),
operator()(row, colIdx2));
4772 for (
index_type col = 0; col < static_cast<index_type>(shape_.cols); ++col)
4774 std::swap(
operator()(rowIdx1, col),
operator()(rowIdx2, col));
4790 void tofile(
const std::string& inFilename)
const
4806 void tofile(
const std::string& inFilename,
const char inSep)
const
4810 std::filesystem::path
f(inFilename);
4811 if (!
f.has_extension())
4813 f.replace_extension(
"txt");
4816 std::ofstream ofile(
f.c_str());
4823 for (
auto value : *
this)
4826 if (counter++ != size_ - 1)
4871 if (numElements == 0)
4895 return std::vector<dtype>(cbegin(), cend());
4920 rowStart += inOffset;
4925 colStart += inOffset;
4936 if (rowStart >= shape_.rows || colStart >= shape_.cols)
4943 for (
size_type row = rowStart; row < shape_.rows; ++row)
4945 if (col >= shape_.cols)
4949 sum += operator()(row, col++);
4965 self_type transArray(shape_.cols, shape_.rows);
4966 for (
uint32 row = 0; row < shape_.rows; ++row)
4968 for (
uint32 col = 0; col < shape_.cols; ++col)
4970 transArray(col, row) = operator()(row, col);
4991 allocator_type allocator_{};
4992 Shape shape_{ 0, 0 };
4993 size_type size_{ 0 };
4994 Endian endianess_{ Endian::NATIVE };
4995 pointer array_{
nullptr };
4996 bool ownsPtr_{
false };
5002 void deleteArray() noexcept
5004 if (ownsPtr_ && array_ !=
nullptr)
5006 allocator_.deallocate(array_, size_);
5010 shape_.rows = shape_.cols = 0;
5013 endianess_ = Endian::NATIVE;
5024 array_ = allocator_.allocate(size_);
5035 void newArray(
const Shape& inShape)
5040 size_ = inShape.size();
5047 template<
typename dtype,
class Alloc_>
5052 std::vector<size_type> rowIndices;
5053 std::vector<size_type> colIndices;
5055 for (
uint32 row = 0; row < shape_.rows; ++row)
5057 for (
uint32 col = 0; col < shape_.cols; ++col)
5061 rowIndices.push_back(row);
5062 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:139
NdArray(pointer inPtr, UIntType size, PointerPolicy policy)
Definition: NdArrayCore.hpp:580
const_reverse_column_iterator rcolbegin() const noexcept
Definition: NdArrayCore.hpp:1573
size_type dimSize(Axis inAxis) const noexcept
Definition: NdArrayCore.hpp:2760
NdArray< size_type > toIndices(Slice inSlice, Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:4844
self_type operator[](Slice inSlice) const
Definition: NdArrayCore.hpp:823
self_type max(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3121
size_type size() const noexcept
Definition: NdArrayCore.hpp:4604
reverse_iterator rbegin() noexcept
Definition: NdArrayCore.hpp:1469
self_type at(index_type inRowIndex, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1197
self_type columns(const NdArray< size_type > &inCols) const
Definition: NdArrayCore.hpp:2500
self_type & put(const RowIndices &inRowIndices, const ColIndices &inColIndices, const self_type &inValues)
Definition: NdArrayCore.hpp:4044
self_type & resizeSlow(size_type inNumRows, size_type inNumCols)
Definition: NdArrayCore.hpp:4483
self_type & put(const Slice &inRowSlice, const ColIndices &inColIndices, const value_type &inValue)
Definition: NdArrayCore.hpp:3938
self_type & zeros() noexcept
Definition: NdArrayCore.hpp:4981
self_type & ones() noexcept
Definition: NdArrayCore.hpp:3567
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1365
self_type at(const RowIndices &rowIndices, const ColIndices &colIndices) const
Definition: NdArrayCore.hpp:1273
const_column_iterator ccolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1454
NdArray< bool > contains(value_type inValue, Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2521
const_pointer data() const noexcept
Definition: NdArrayCore.hpp:2686
iterator end() noexcept
Definition: NdArrayCore.hpp:1623
self_type & swapCols(index_type colIdx1, index_type colIdx2) noexcept
Definition: NdArrayCore.hpp:4752
NdArray(const std::initializer_list< std::initializer_list< dtype > > &inList)
Definition: NdArrayCore.hpp:239
reference at(index_type inRowIndex, index_type inColIndex)
Definition: NdArrayCore.hpp:1068
self_type & put(const RowIndices &inRowIndices, const ColIndices &inColIndices, const value_type &inValue)
Definition: NdArrayCore.hpp:3894
self_type repeat(const Shape &inRepeatShape) const
Definition: NdArrayCore.hpp:4316
self_type at(Slice rowSlice, const Indices &colIndices) const
Definition: NdArrayCore.hpp:1256
reference back(size_type row)
Definition: NdArrayCore.hpp:2396
iterator end(size_type inRow)
Definition: NdArrayCore.hpp:1635
self_type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) const
Definition: NdArrayCore.hpp:980
void tofile(const std::string &inFilename, const char inSep) const
Definition: NdArrayCore.hpp:4806
const_column_iterator ccolbegin() const noexcept
Definition: NdArrayCore.hpp:1442
NdArray(std::array< dtype, ArraySize > &inArray, PointerPolicy policy=PointerPolicy::COPY)
Definition: NdArrayCore.hpp:274
NdArray(const std::deque< std::deque< dtype > > &in2dDeque)
Definition: NdArrayCore.hpp:469
self_type & reshape(size_type inSize)
Definition: NdArrayCore.hpp:4351
typename AllocTraits::pointer pointer
Definition: NdArrayCore.hpp:152
self_type transpose() const
Definition: NdArrayCore.hpp:4963
reverse_iterator rbegin(size_type inRow)
Definition: NdArrayCore.hpp:1481
NdArray(std::vector< dtype > &inVector, PointerPolicy policy=PointerPolicy::COPY)
Definition: NdArrayCore.hpp:348
NdArray< size_type > argsort(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2193
const_reverse_column_iterator rcolend() const noexcept
Definition: NdArrayCore.hpp:1881
self_type rows(const NdArray< size_type > &inRows) const
Definition: NdArrayCore.hpp:4570
const dtype & const_reference
Definition: NdArrayCore.hpp:155
bool issquare() const noexcept
Definition: NdArrayCore.hpp:3089
bool isflat() const noexcept
Definition: NdArrayCore.hpp:3025
Endian endianess() const noexcept
Definition: NdArrayCore.hpp:2872
self_type dot(const self_type &inOtherArray) const
Definition: NdArrayCore.hpp:2795
void tofile(const std::string &inFilename) const
Definition: NdArrayCore.hpp:4790
const_reverse_column_iterator crcolbegin() const noexcept
Definition: NdArrayCore.hpp:1596
self_type & swapRows(index_type rowIdx1, index_type rowIdx2) noexcept
Definition: NdArrayCore.hpp:4770
const_reverse_column_iterator crcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1916
size_type numCols() const noexcept
Definition: NdArrayCore.hpp:3545
column_iterator colbegin(size_type inCol)
Definition: NdArrayCore.hpp:1404
self_type median(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3211
const_reference at(index_type inRowIndex, index_type inColIndex) const
Definition: NdArrayCore.hpp:1081
self_type at(const Slice &inSlice) const
Definition: NdArrayCore.hpp:1111
NdArray< bool > none(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3491
pointer data() noexcept
Definition: NdArrayCore.hpp:2676
bool isempty() const noexcept
Definition: NdArrayCore.hpp:3012
column_iterator colbegin() noexcept
Definition: NdArrayCore.hpp:1392
NdArray(std::vector< std::array< dtype, Dim1Size > > &in2dArray, PointerPolicy policy=PointerPolicy::COPY)
Definition: NdArrayCore.hpp:416
const_reference front(size_type row) const
Definition: NdArrayCore.hpp:2962
reverse_column_iterator rcolend(size_type inCol)
Definition: NdArrayCore.hpp:1866
self_type column(size_type inColumn) const
Definition: NdArrayCore.hpp:2488
self_type prod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3683
NdArray(Iterator inFirst, Iterator inLast)
Definition: NdArrayCore.hpp:521
reference at(index_type inIndex)
Definition: NdArrayCore.hpp:1034
const Shape & shape() const noexcept
Definition: NdArrayCore.hpp:4591
reverse_column_iterator rcolbegin() noexcept
Definition: NdArrayCore.hpp:1546
self_type at(const Indices &inIndices) const
Definition: NdArrayCore.hpp:1141
const_iterator cbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1377
const_column_iterator ccolend(size_type inCol) const
Definition: NdArrayCore.hpp:1839
self_type at(index_type rowIndex, const Indices &colIndices) const
Definition: NdArrayCore.hpp:1241
self_type & resizeFast(size_type inNumRows, size_type inNumCols)
Definition: NdArrayCore.hpp:4451
const_iterator cend(size_type inRow) const
Definition: NdArrayCore.hpp:1685
NdArray< size_type > flatnonzero() const
Definition: NdArrayCore.hpp:2901
self_type & byteswap() noexcept
Definition: NdArrayCore.hpp:2409
self_type & ravel()
Definition: NdArrayCore.hpp:4259
self_type getByIndices(const NdArray< size_type > &inIndices) const
Definition: NdArrayCore.hpp:2985
const_reverse_column_iterator rcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1893
NdArray(const std::vector< std::vector< dtype > > &in2dVector)
Definition: NdArrayCore.hpp:382
self_type & partition(size_type inKth, Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:3601
self_type & put(const Indices &inRowIndices, index_type inColIndex, const value_type &inValue)
Definition: NdArrayCore.hpp:3971
const_iterator end(size_type inRow) const
Definition: NdArrayCore.hpp:1662
self_type flatten() const
Definition: NdArrayCore.hpp:2927
self_type & replace(value_type oldValue, value_type newValue)
Definition: NdArrayCore.hpp:4328
reference back() noexcept
Definition: NdArrayCore.hpp:2374
const_reverse_column_iterator crcolend() const noexcept
Definition: NdArrayCore.hpp:1904
const_reference back(size_type row) const
Definition: NdArrayCore.hpp:2385
reverse_column_iterator rcolbegin(size_type inCol)
Definition: NdArrayCore.hpp:1558
self_type & put(Slice inRowSlice, Slice inColSlice, const self_type &inValues)
Definition: NdArrayCore.hpp:4133
iterator begin(size_type inRow)
Definition: NdArrayCore.hpp:1327
const_reverse_iterator rend() const noexcept
Definition: NdArrayCore.hpp:1727
self_type copy() const
Definition: NdArrayCore.hpp:2562
self_type round(uint8 inNumDecimals=0) const
Definition: NdArrayCore.hpp:4537
std::vector< dtype > toStlVector() const
Definition: NdArrayCore.hpp:4893
self_type swapaxes() const
Definition: NdArrayCore.hpp:4739
const_reverse_column_iterator rcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1585
typename AllocTraits::difference_type difference_type
Definition: NdArrayCore.hpp:158
const_iterator end() const noexcept
Definition: NdArrayCore.hpp:1650
NdArray< dtypeOut > astype() const
Definition: NdArrayCore.hpp:2257
self_type & put(index_type inRowIndex, const Slice &inColSlice, const self_type &inValues)
Definition: NdArrayCore.hpp:4202
bool ownsInternalData() noexcept
Definition: NdArrayCore.hpp:3581
self_type operator[](const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:835
self_type & fill(value_type inFillValue) noexcept
Definition: NdArrayCore.hpp:2888
column_iterator colend() noexcept
Definition: NdArrayCore.hpp:1777
NdArray(std::initializer_list< dtype > inList)
Definition: NdArrayCore.hpp:222
self_type at(const Indices &rowIndices, Slice colSlice) const
Definition: NdArrayCore.hpp:1227
const_reference back() const noexcept
Definition: NdArrayCore.hpp:2363
std::pair< NdArray< size_type >, NdArray< size_type > > nonzero() const
Definition: NdArrayCore.hpp:5048
self_type diagonal(index_type inOffset=0, Axis inAxis=Axis::ROW) const
Definition: NdArrayCore.hpp:2715
self_type & put(index_type inRowIndex, const Indices &inColIndices, const self_type &inValues)
Definition: NdArrayCore.hpp:4185
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: NdArrayCore.hpp:163
self_type at(const Slice &inRowSlice, index_type inColIndex) const
Definition: NdArrayCore.hpp:1183
NdArray(const_pointer inPtr, UIntType1 numRows, UIntType2 numCols)
Definition: NdArrayCore.hpp:558
NdArray< bool > any(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1979
NdArray(const self_type &inOtherArray)
Definition: NdArrayCore.hpp:633
NdArray(self_type &&inOtherArray) noexcept
Definition: NdArrayCore.hpp:651
uint64 nbytes() const noexcept
Definition: NdArrayCore.hpp:3313
NdArray< size_type > argmax(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2024
self_type at(const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:1123
NdArray(const std::list< dtype > &inList)
Definition: NdArrayCore.hpp:501
self_type & put(const Indices &inRowIndices, index_type inColIndex, const self_type &inValues)
Definition: NdArrayCore.hpp:4150
const_reference front() const noexcept
Definition: NdArrayCore.hpp:2940
~NdArray() noexcept
Definition: NdArrayCore.hpp:668
Slice rSlice(index_type inStartIdx=0, size_type inStepSize=1) const
Definition: NdArrayCore.hpp:1022
reference front() noexcept
Definition: NdArrayCore.hpp:2951
self_type & put(const Slice &inRowSlice, index_type inColIndex, const self_type &inValues)
Definition: NdArrayCore.hpp:4167
self_type & put(Slice inRowSlice, const ColIndices &inColIndices, const self_type &inValues)
Definition: NdArrayCore.hpp:4117
self_type & put(const Slice &inRowSlice, index_type inColIndex, const value_type &inValue)
Definition: NdArrayCore.hpp:3988
NdArray(size_type inNumRows, size_type inNumCols)
Definition: NdArrayCore.hpp:196
self_type & putMask(const NdArray< bool > &inMask, const value_type &inValue)
Definition: NdArrayCore.hpp:4215
Allocator allocator_type
Definition: NdArrayCore.hpp:151
self_type & nans() noexcept
Definition: NdArrayCore.hpp:3296
NdArray(pointer inPtr, UIntType1 numRows, UIntType2 numCols, PointerPolicy policy)
Definition: NdArrayCore.hpp:599
void print() const
Definition: NdArrayCore.hpp:3667
const_reverse_column_iterator crcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1608
self_type & reshape(const Shape &inShape)
Definition: NdArrayCore.hpp:4436
size_type numRows() const noexcept
Definition: NdArrayCore.hpp:3557
reverse_iterator rend(size_type inRow)
Definition: NdArrayCore.hpp:1712
NdArray(size_type inSquareSize)
Definition: NdArrayCore.hpp:182
self_type at(const Indices &rowIndices, index_type colIndex) const
Definition: NdArrayCore.hpp:1212
reverse_iterator rend() noexcept
Definition: NdArrayCore.hpp:1700
const_reverse_iterator rend(size_type inRow) const
Definition: NdArrayCore.hpp:1739
typename AllocTraits::const_pointer const_pointer
Definition: NdArrayCore.hpp:153
self_type & put(const Indices &inIndices, const self_type &inValues)
Definition: NdArrayCore.hpp:3829
self_type & operator=(value_type inValue) noexcept
Definition: NdArrayCore.hpp:714
const_reverse_iterator crbegin() const noexcept
Definition: NdArrayCore.hpp:1519
NdArray(const_pointer inPtr, UIntType size)
Definition: NdArrayCore.hpp:541
const_column_iterator colend(size_type inCol) const
Definition: NdArrayCore.hpp:1816
std::reverse_iterator< iterator > reverse_iterator
Definition: NdArrayCore.hpp:162
const_reverse_iterator rbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1508
self_type operator[](const Indices &inIndices) const
Definition: NdArrayCore.hpp:849
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1673
self_type & resizeSlow(const Shape &inShape)
Definition: NdArrayCore.hpp:4522
self_type & operator=(self_type &&rhs) noexcept
Definition: NdArrayCore.hpp:731
std::string str() const
Definition: NdArrayCore.hpp:4662
std::reverse_iterator< const_column_iterator > const_reverse_column_iterator
Definition: NdArrayCore.hpp:168
self_type cumsum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2628
NdArray< bool > all(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1935
self_type & resizeFast(const Shape &inShape)
Definition: NdArrayCore.hpp:4466
self_type & put(index_type inRowIndex, const Indices &inColIndices, const value_type &inValue)
Definition: NdArrayCore.hpp:4006
reference front(size_type row)
Definition: NdArrayCore.hpp:2973
self_type & put(const RowIndices &inRowIndices, Slice inColSlice, const self_type &inValues)
Definition: NdArrayCore.hpp:4100
NdArray(std::array< std::array< dtype, Dim1Size >, Dim0Size > &in2dArray, PointerPolicy policy=PointerPolicy::COPY)
Definition: NdArrayCore.hpp:310
self_type repeat(size_type inNumRows, size_type inNumCols) const
Definition: NdArrayCore.hpp:4275
const_iterator begin(size_type inRow) const
Definition: NdArrayCore.hpp:1354
iterator begin() noexcept
Definition: NdArrayCore.hpp:1315
const_column_iterator colbegin() const noexcept
Definition: NdArrayCore.hpp:1419
bool isscalar() const noexcept
Definition: NdArrayCore.hpp:3036
std::reverse_iterator< column_iterator > reverse_column_iterator
Definition: NdArrayCore.hpp:167
self_type operator()(Slice inRowSlice, Slice inColSlice) const
Definition: NdArrayCore.hpp:870
self_type & put(const Slice &inSlice, const value_type &inValue)
Definition: NdArrayCore.hpp:3859
self_type newbyteorder(Endian inEndianess) const
Definition: NdArrayCore.hpp:3328
value_type item() const
Definition: NdArrayCore.hpp:3102
const_reference at(index_type inIndex) const
Definition: NdArrayCore.hpp:1046
self_type & reshape(index_type inNumRows, index_type inNumCols)
Definition: NdArrayCore.hpp:4382
const_column_iterator colend() const noexcept
Definition: NdArrayCore.hpp:1804
self_type row(size_type inRow) const
Definition: NdArrayCore.hpp:4558
self_type operator()(const Indices &rowIndices, index_type colIndex) const
Definition: NdArrayCore.hpp:915
self_type at(const Slice &inRowSlice, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1170
self_type operator()(Slice inRowSlice, index_type inColIndex) const
Definition: NdArrayCore.hpp:884
const_reverse_iterator crend() const noexcept
Definition: NdArrayCore.hpp:1750
self_type operator()(index_type rowIndex, const Indices &colIndices) const
Definition: NdArrayCore.hpp:946
NdArray< dtype, Allocator > self_type
Definition: NdArrayCore.hpp:149
const_column_iterator colbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1431
self_type & put(const Slice &inSlice, const self_type &inValues)
Definition: NdArrayCore.hpp:3874
self_type & put(const Indices &inIndices, const value_type &inValue)
Definition: NdArrayCore.hpp:3808
self_type cumprod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2576
const_column_iterator ccolend() const noexcept
Definition: NdArrayCore.hpp:1827
reference operator()(index_type inRowIndex, index_type inColIndex) noexcept
Definition: NdArrayCore.hpp:787
self_type operator()(index_type inRowIndex, Slice inColSlice) const
Definition: NdArrayCore.hpp:899
reverse_column_iterator rcolend() noexcept
Definition: NdArrayCore.hpp:1854
const_reverse_iterator rbegin() const noexcept
Definition: NdArrayCore.hpp:1496
NdArray(const std::deque< dtype > &inDeque)
Definition: NdArrayCore.hpp:452
void dump(const std::string &inFilename) const
Definition: NdArrayCore.hpp:2845
dtype & reference
Definition: NdArrayCore.hpp:154
self_type & put(const RowIndices &inRowIndices, const Slice &inColSlice, const value_type &inValue)
Definition: NdArrayCore.hpp:3921
self_type & put(index_type inRowIndex, const Slice &inColSlice, const value_type &inValue)
Definition: NdArrayCore.hpp:4023
value_type trace(size_type inOffset=0, Axis inAxis=Axis::ROW) const noexcept
Definition: NdArrayCore.hpp:4910
pointer dataRelease() noexcept
Definition: NdArrayCore.hpp:2698
self_type ptp(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3727
self_type clip(value_type inMin, value_type inMax) const
Definition: NdArrayCore.hpp:2449
self_type getByMask(const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:2999
uint32 size_type
Definition: NdArrayCore.hpp:156
NdArray< bool > issorted(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3048
self_type & operator=(const self_type &rhs)
Definition: NdArrayCore.hpp:690
const_iterator begin() const noexcept
Definition: NdArrayCore.hpp:1342
NdArray< size_type > argpartition(size_type inKth, Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2120
column_iterator colend(size_type inCol)
Definition: NdArrayCore.hpp:1789
NdArray< size_type > argmin(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2071
const_reference operator[](index_type inIndex) const noexcept
Definition: NdArrayCore.hpp:769
self_type operator()(Slice rowSlice, const Indices &colIndices) const
Definition: NdArrayCore.hpp:962
const_reference operator()(index_type inRowIndex, index_type inColIndex) const noexcept
Definition: NdArrayCore.hpp:800
self_type min(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3165
self_type & putMask(const NdArray< bool > &inMask, const self_type &inValues)
Definition: NdArrayCore.hpp:4232
dtype value_type
Definition: NdArrayCore.hpp:150
reference operator[](index_type inIndex) noexcept
Definition: NdArrayCore.hpp:757
Slice cSlice(index_type inStartIdx=0, size_type inStepSize=1) const
Definition: NdArrayCore.hpp:1008
self_type & sort(Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:4618
self_type & put(const Slice &inRowSlice, const Slice &inColSlice, const value_type &inValue)
Definition: NdArrayCore.hpp:3954
const_reverse_iterator crend(size_type inRow) const
Definition: NdArrayCore.hpp:1762
const_reverse_iterator crbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1531
int32 index_type
Definition: NdArrayCore.hpp:157
NdArray(const Shape &inShape)
Definition: NdArrayCore.hpp:209
self_type sum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:4698
self_type operator()(const Indices &rowIndices, Slice colSlice) const
Definition: NdArrayCore.hpp:931
self_type & put(index_type inRow, index_type inCol, const value_type &inValue)
Definition: NdArrayCore.hpp:3790
self_type & put(index_type inIndex, const value_type &inValue)
Definition: NdArrayCore.hpp:3773
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:77
T transform_reduce(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2, T init)
Definition: StlAlgorithms.hpp:825
void sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:697
bool none_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:406
ForwardIt max_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:286
void stable_sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:735
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:776
bool all_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:56
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:226
InputIt find(InputIt first, InputIt last, const T &value) noexcept
Definition: StlAlgorithms.hpp:206
void replace(ForwardIt first, ForwardIt last, const T &oldValue, const T &newValue) noexcept
Definition: StlAlgorithms.hpp:469
std::pair< ForwardIt, ForwardIt > minmax_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:365
bool is_sorted(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:246
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:98
void nth_element(RandomIt first, RandomIt nth, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:426
ForwardIt min_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:325
void fill(ForwardIt first, ForwardIt last, const T &value) noexcept
Definition: StlAlgorithms.hpp:184
constexpr bool is_ndarray_signed_int_v
Definition: NdArrayCore.hpp:124
std::enable_if_t< is_ndarray_int_v< T >, int > ndarray_int_concept
Definition: NdArrayCore.hpp:131
constexpr bool is_ndarray_int_v
Definition: NdArrayCore.hpp:97
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:49
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
std::pair< NdArray< uint32 >, NdArray< uint32 > > nonzero(const NdArray< dtype > &inArray)
Definition: nonzero.hpp:48
NdArray< dtype > & resizeSlow(NdArray< dtype > &inArray, uint32 inNumRows, uint32 inNumCols)
Definition: resizeSlow.hpp:52
void swap(NdArray< dtype > &inArray1, NdArray< dtype > &inArray2) noexcept
Definition: swap.hpp:42
Axis
Enum To describe an axis.
Definition: Enums.hpp:36
std::int64_t int64
Definition: Types.hpp:35
NdArray< dtype > & put(NdArray< dtype > &inArray, int32 inIndex, const dtype &inValue)
Definition: put.hpp:46
auto abs(dtype inValue) noexcept
Definition: abs.hpp:49
std::uint64_t uint64
Definition: Types.hpp:39
NdArray< dtype > & resizeFast(NdArray< dtype > &inArray, uint32 inNumRows, uint32 inNumCols)
Definition: resizeFast.hpp:50
Endian
Enum for endianess.
Definition: Enums.hpp:46
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 > & reshape(NdArray< dtype > &inArray, uint32 inSize)
Definition: reshape.hpp:51
PointerPolicy
Policy for NdArray constructor that takes in a pointer to data.
Definition: Enums.hpp:56
NdArray< dtype > repeat(const NdArray< dtype > &inArray, uint32 inNumRows, uint32 inNumCols)
Definition: repeat.hpp:49
std::uint32_t uint32
Definition: Types.hpp:40
NdArray< dtype > transpose(const NdArray< dtype > &inArray)
Definition: transpose.hpp:45
void dump(const NdArray< dtype > &inArray, const std::string &inFilename)
Definition: dump.hpp:45
Definition: NdArrayCore.hpp:78
Definition: NdArrayCore.hpp:105