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>(
2125 std::vector<size_type> idx(size_);
2126 std::iota(idx.begin(), idx.end(), 0);
2129 {
return (*
this)[i1] < (*this)[i2]; };
2137 std::vector<size_type> idx(shape_.cols);
2139 for (
index_type row = 0; row < static_cast<index_type>(shape_.rows); ++row)
2141 std::iota(idx.begin(), idx.end(), 0);
2144 {
return operator()(row, i1) < operator()(row, i2); };
2148 for (
index_type col = 0; col < static_cast<index_type>(shape_.cols); ++col)
2150 returnArray(row, col) = idx[
static_cast<size_type>(col)];
2157 return transpose().argsort(Axis::COL).transpose();
2176 template<
typename dtypeOut,
2177 typename dtype_ = dtype,
2178 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2179 std::enable_if_t<std::is_arithmetic_v<dtype_>,
int> = 0,
2180 std::enable_if_t<std::is_arithmetic_v<dtypeOut>,
int> = 0>
2183 if constexpr (std::is_same_v<dtypeOut, dtype>)
2193 [](dtype value) -> dtypeOut { return static_cast<dtypeOut>(value); });
2208 template<
typename dtypeOut,
2209 typename dtype_ = dtype,
2210 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2211 std::enable_if_t<std::is_arithmetic_v<dtype_>,
int> = 0,
2212 std::enable_if_t<is_complex_v<dtypeOut>,
int> = 0>
2218 {
return std::complex<typename dtypeOut::value_type>(value); };
2234 template<
typename dtypeOut,
2235 typename dtype_ = dtype,
2236 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2237 std::enable_if_t<is_complex_v<dtype_>,
int> = 0,
2238 std::enable_if_t<is_complex_v<dtypeOut>,
int> = 0>
2241 if constexpr (std::is_same_v<dtypeOut, dtype>)
2248 {
return complex_cast<typename dtypeOut::value_type>(value); };
2265 template<
typename dtypeOut,
2266 typename dtype_ = dtype,
2267 std::enable_if_t<std::is_same_v<dtype_, dtype>,
int> = 0,
2268 std::enable_if_t<is_complex_v<dtype_>,
int> = 0,
2269 std::enable_if_t<std::is_arithmetic_v<dtypeOut>,
int> = 0>
2274 const auto function = [](
const_reference value) -> dtypeOut {
return static_cast<dtypeOut
>(value.real()); };
2289 return *(cend() - 1);
2300 return *(end() - 1);
2311 return *(cend(row) - 1);
2322 return *(end(row) - 1);
2343 case Endian::NATIVE:
2348 case Endian::LITTLE:
2350 endianess_ = Endian::BIG;
2355 endianess_ = Endian::LITTLE;
2381 [inMin, inMax](dtype value) noexcept -> dtype
2383#ifdef __cpp_lib_clamp
2384 const auto comparitor = [](dtype lhs, dtype rhs) noexcept -> bool
2385 { return lhs < rhs; };
2387 return std::clamp(value, inMin, inMax, comparitor);
2393 else if (value > inMax)
2414 return operator()(rSlice(), inColumn);
2427 const auto rSlice = returnArray.rSlice();
2431 returnArray.put(rSlice, i, column(inCols[i]));
2459 for (
size_type row = 0; row < shape_.rows; ++row)
2468 return transpose().contains(inValue, Axis::COL);
2509 returnArray[0] = front();
2512 returnArray[i] = returnArray[i - 1] * array_[i];
2520 for (
uint32 row = 0; row < shape_.rows; ++row)
2522 returnArray(row, 0) = operator()(row, 0);
2523 for (
uint32 col = 1; col < shape_.cols; ++col)
2525 returnArray(row, col) = returnArray(row, col - 1) * operator()(row, col);
2533 return transpose().cumprod(Axis::COL).transpose();
2561 returnArray[0] = front();
2564 returnArray[i] = returnArray[i - 1] + array_[i];
2572 for (
uint32 row = 0; row < shape_.rows; ++row)
2574 returnArray(row, 0) = operator()(row, 0);
2575 for (
uint32 col = 1; col < shape_.cols; ++col)
2577 returnArray(row, col) = returnArray(row, col - 1) + operator()(row, col);
2585 return transpose().cumsum(Axis::COL).transpose();
2645 std::vector<dtype> diagnolValues;
2647 for (
index_type row = inOffset; row < static_cast<index_type>(shape_.rows); ++row)
2654 if (col >= shape_.cols)
2659 diagnolValues.push_back(
operator()(
static_cast<size_type>(row), col));
2667 return transpose().diagonal(inOffset, Axis::COL);
2723 if (shape_ == inOtherArray.shape_ && (shape_.rows == 1 || shape_.cols == 1))
2725 dtype dotProduct = std::inner_product(cbegin(), cend(), inOtherArray.
cbegin(), dtype{ 0 });
2729 if (shape_.cols == inOtherArray.shape_.
rows)
2732 self_type returnArray(shape_.rows, inOtherArray.shape_.
cols);
2733 auto otherArrayT = inOtherArray.
transpose();
2735 for (
uint32 i = 0; i < shape_.rows; ++i)
2737 for (
uint32 j = 0;
j < otherArrayT.shape_.rows; ++
j)
2740 std::inner_product(otherArrayT.cbegin(
j), otherArrayT.cend(
j), cbegin(i), dtype{ 0 });
2750 errStr +=
" are not consistent.";
2765 void dump(
const std::string& inFilename)
const
2767 std::filesystem::path
f(inFilename);
2768 if (!
f.has_extension())
2770 f.replace_extension(
"bin");
2773 std::ofstream ofile(
f.c_str(), std::ios::binary);
2779 if (array_ !=
nullptr)
2781 ofile.write(
reinterpret_cast<const char*
>(array_), size_ *
sizeof(dtype));
2825 std::vector<size_type> indices;
2827 for (
auto value : *
this)
2831 indices.push_back(idx);
2884 return *cbegin(row);
2907 return operator[](inIndices);
2921 return operator[](inMask);
2947 return !isscalar() && (shape_.rows == 1 || shape_.cols == 1);
2972 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
2983 for (
uint32 row = 0; row < shape_.rows; ++row)
3011 return shape_.issquare();
3045 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3057 for (
uint32 row = 0; row < shape_.rows; ++row)
3089 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3101 for (
uint32 row = 0; row < shape_.rows; ++row)
3135 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3150 copyArray.
begin() + middleIdx,
3154 dtype medianValue = copyArray.array_[middleIdx];
3157 const size_type lhsIndex = middleIdx - 1;
3159 copyArray.
begin() + lhsIndex,
3163 (medianValue + copyArray.array_[lhsIndex]) / dtype{ 2 };
3166 return { medianValue };
3173 const bool isEven = shape_.cols % 2 == 0;
3174 for (
uint32 row = 0; row < shape_.rows; ++row)
3176 const uint32 middleIdx = shape_.cols / 2;
3178 copyArray.
begin(row) + middleIdx,
3182 dtype medianValue = copyArray(row, middleIdx);
3185 const size_type lhsIndex = middleIdx - 1;
3187 copyArray.
begin(row) + lhsIndex,
3190 medianValue = (medianValue + copyArray(row, lhsIndex)) /
3194 returnArray(0, row) = medianValue;
3235 return static_cast<uint64>(
sizeof(dtype) * size_);
3256 case Endian::NATIVE:
3258 switch (inEndianess)
3260 case Endian::NATIVE:
3272 outArray.endianess_ = Endian::BIG;
3277 auto outArray =
NdArray(*
this);
3278 outArray.endianess_ = Endian::BIG;
3282 case Endian::LITTLE:
3286 auto outArray =
NdArray(*
this);
3287 outArray.endianess_ = Endian::LITTLE;
3296 outArray.endianess_ = Endian::LITTLE;
3310 switch (inEndianess)
3312 case Endian::NATIVE:
3320 outArray.endianess_ = Endian::NATIVE;
3325 auto outArray =
NdArray(*
this);
3326 outArray.endianess_ = Endian::NATIVE;
3334 case Endian::LITTLE:
3340 outArray.endianess_ = Endian::LITTLE;
3351 case Endian::LITTLE:
3353 switch (inEndianess)
3355 case Endian::NATIVE:
3359 auto outArray =
NdArray(*
this);
3360 outArray.endianess_ = Endian::NATIVE;
3369 outArray.endianess_ = Endian::NATIVE;
3379 outArray.endianess_ = Endian::BIG;
3382 case Endian::LITTLE:
3427 for (
uint32 row = 0; row < shape_.rows; ++row)
3525 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool
3526 {
return lhs < rhs; };
3544 if (inKth >= shape_.cols)
3547 errStr +=
") out of bounds (" +
utils::num2str(shape_.cols) +
")";
3551 for (
uint32 row = 0; row < shape_.rows; ++row)
3559 if (inKth >= shape_.rows)
3562 errStr +=
") out of bounds (" +
utils::num2str(shape_.rows) +
")";
3567 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3570 transposedArray.
begin(row) + inKth,
3571 transposedArray.
end(row),
3611 dtype product = std::accumulate(cbegin(), cend(), dtype{ 1 }, std::multiplies<dtype>());
3618 for (
uint32 row = 0; row < shape_.rows; ++row)
3620 returnArray(0, row) =
3621 std::accumulate(cbegin(row), cend(row), dtype{ 1 }, std::multiplies<dtype>());
3651 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3658 self_type returnArray = { *result.second - *result.first };
3664 for (
uint32 row = 0; row < shape_.rows; ++row)
3667 returnArray(0, row) = *result.second - *result.first;
3695 at(inIndex) = inValue;
3712 at(inRow, inCol) = inValue;
3727 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3730 for (
auto index : inIndices)
3732 put(index, inValue);
3748 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3753 return put(inIndices, inValues.
item());
3755 else if (inIndices.size() != inValues.
size())
3761 for (
auto index : inIndices)
3763 put(index, inValues[counter++]);
3781 return put(toIndices(inSlice, Axis::NONE), inValue);
3796 return put(toIndices(inSlice, Axis::NONE), inValues);
3810 template<
typename RowIndices,
3811 typename ColIndices,
3818 [
this, &inColIndices, &inValue](
const auto row)
3820 stl_algorithms::for_each(inColIndices.begin(),
3822 [this, row, &inValue](const auto col)
3823 { this->put(row, col, inValue); });
3840 template<
typename RowIndices, type_traits::ndarray_
int_concept<RowIndices> = 0>
3843 return put(inRowIndices, toIndices(inColSlice, Axis::COL), inValue);
3857 template<
typename ColIndices, type_traits::ndarray_
int_concept<ColIndices> = 0>
3860 return put(toIndices(inRowSlice, Axis::ROW), inColIndices, inValue);
3876 return put(toIndices(inRowSlice, Axis::ROW), toIndices(inColSlice, Axis::COL), inValue);
3890 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3894 return put(inRowIndices, colIndices, inValue);
3911 return put(toIndices(inRowSlice, Axis::ROW), colIndices, inValue);
3925 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3929 return put(rowIndices, inColIndices, inValue);
3946 return put(rowIndices, toIndices(inColSlice, Axis::COL), inValue);
3960 template<
typename RowIndices,
3961 typename ColIndices,
3966 std::vector<size_type> indices;
3967 indices.reserve(inRowIndices.size() * inColIndices.size());
3970 [
this, &inColIndices, &indices](
auto row)
3972 if constexpr (std::is_signed_v<decltype(row)>)
3981 THROW_INVALID_ARGUMENT_ERROR(
"row index exceeds matrix dimensions");
3986 [
this, row, &indices](
auto col)
3988 if constexpr (std::is_signed_v<decltype(col)>)
3997 THROW_INVALID_ARGUMENT_ERROR(
3998 "col index exceeds matrix dimensions");
4001 indices.push_back(row * shape_.cols + col);
4005 return put(NdArray<size_type>(indices.data(), indices.size(), PointerPolicy::SHELL), inValues);
4019 template<
typename RowIndices, type_traits::ndarray_
int_concept<RowIndices> = 0>
4022 return put(inRowIndices, toIndices(inColSlice, Axis::COL), inValues);
4036 template<
typename ColIndices, type_traits::ndarray_
int_concept<ColIndices> = 0>
4039 return put(toIndices(inRowSlice, Axis::ROW), inColIndices, inValues);
4055 return put(toIndices(inRowSlice, Axis::ROW), toIndices(inColSlice, Axis::COL), inValues);
4069 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
4073 return put(inRowIndices, colIndices, inValues);
4090 return put(toIndices(inRowSlice, Axis::ROW), colIndices, inValues);
4104 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
4108 return put(rowIndices, inColIndices, inValues);
4125 return put(rowIndices, toIndices(inColSlice, Axis::COL), inValues);
4137 if (inMask.
shape() != shape_)
4154 if (inMask.
shape() != shape_)
4197 self_type returnArray(shape_.rows * inNumRows, shape_.cols * inNumCols);
4199 for (
size_type row = 0; row < inNumRows; ++row)
4201 for (
size_type col = 0; col < inNumCols; ++col)
4203 std::vector<size_type> indices(shape_.size());
4205 const size_type rowStart = row * shape_.rows;
4206 const size_type colStart = col * shape_.cols;
4208 const size_type rowEnd = (row + 1) * shape_.rows;
4209 const size_type colEnd = (col + 1) * shape_.cols;
4212 for (
size_type rowIdx = rowStart; rowIdx < rowEnd; ++rowIdx)
4214 for (
size_type colIdx = colStart; colIdx < colEnd; ++colIdx)
4216 indices[counter++] = rowIdx * returnArray.shape_.
cols + colIdx;
4273 if (inSize != size_)
4275 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4281 shape_.cols = inSize;
4306 if (size_ % inNumCols == 0)
4308 return reshape(size_ / inNumCols, inNumCols);
4311 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4318 if (size_ % inNumRows == 0)
4320 return reshape(inNumRows, size_ / inNumRows);
4323 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4328 if (
static_cast<size_type>(inNumRows * inNumCols) != size_)
4330 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4335 shape_.rows =
static_cast<size_type>(inNumRows);
4336 shape_.cols =
static_cast<size_type>(inNumCols);
4373 newArray(
Shape(inNumRows, inNumCols));
4405 std::vector<dtype> oldData(size_);
4408 const Shape inShape(inNumRows, inNumCols);
4409 const Shape oldShape = shape_;
4413 for (
uint32 row = 0; row < inShape.
rows; ++row)
4415 for (
uint32 col = 0; col < inShape.
cols; ++col)
4417 if (row >= oldShape.
rows || col >= oldShape.
cols)
4419 operator()(row, col) = dtype{ 0 };
4423 operator()(row, col) = oldData[row * oldShape.
cols + col];
4462 const double multFactor =
utils::power(10., inNumDecimals);
4463 const auto function = [multFactor](dtype value)
noexcept -> dtype
4464 {
return static_cast<dtype
>(std::nearbyint(
static_cast<double>(value) * multFactor) / multFactor); };
4480 return self_type(cbegin(inRow), cend(inRow));
4493 const auto cSlice = returnArray.cSlice();
4497 returnArray.put(i, cSlice, row(inRows[i]));
4542 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool
4543 {
return lhs < rhs; };
4554 for (
uint32 row = 0; row < shape_.rows; ++row)
4563 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
4582 [[nodiscard]] std::string
str()
const
4588 for (
uint32 row = 0; row < shape_.rows; ++row)
4591 for (
uint32 col = 0; col < shape_.cols; ++col)
4596 if (row == shape_.rows - 1)
4626 self_type returnArray = { std::accumulate(cbegin(), cend(), dtype{ 0 }) };
4632 for (
uint32 row = 0; row < shape_.rows; ++row)
4634 returnArray(0, row) = std::accumulate(cbegin(row), cend(row), dtype{ 0 });
4674 for (
index_type row = 0; row < static_cast<index_type>(shape_.rows); ++row)
4676 std::swap(
operator()(row, colIdx1),
operator()(row, colIdx2));
4692 for (
index_type col = 0; col < static_cast<index_type>(shape_.cols); ++col)
4694 std::swap(
operator()(rowIdx1, col),
operator()(rowIdx2, col));
4710 void tofile(
const std::string& inFilename)
const
4726 void tofile(
const std::string& inFilename,
const char inSep)
const
4730 std::filesystem::path
f(inFilename);
4731 if (!
f.has_extension())
4733 f.replace_extension(
"txt");
4736 std::ofstream ofile(
f.c_str());
4743 for (
auto value : *
this)
4746 if (counter++ != size_ - 1)
4790 if (numElements == 0)
4814 return std::vector<dtype>(cbegin(), cend());
4839 rowStart += inOffset;
4844 colStart += inOffset;
4855 if (rowStart >= shape_.rows || colStart >= shape_.cols)
4862 for (
size_type row = rowStart; row < shape_.rows; ++row)
4864 if (col >= shape_.cols)
4868 sum += operator()(row, col++);
4884 self_type transArray(shape_.cols, shape_.rows);
4885 for (
uint32 row = 0; row < shape_.rows; ++row)
4887 for (
uint32 col = 0; col < shape_.cols; ++col)
4889 transArray(col, row) = operator()(row, col);
4910 allocator_type allocator_{};
4911 Shape shape_{ 0, 0 };
4912 size_type size_{ 0 };
4913 Endian endianess_{ Endian::NATIVE };
4914 pointer array_{
nullptr };
4915 bool ownsPtr_{
false };
4921 void deleteArray() noexcept
4923 if (ownsPtr_ && array_ !=
nullptr)
4925 allocator_.deallocate(array_, size_);
4929 shape_.rows = shape_.cols = 0;
4932 endianess_ = Endian::NATIVE;
4943 array_ = allocator_.allocate(size_);
4954 void newArray(
const Shape& inShape)
4959 size_ = inShape.size();
4966 template<
typename dtype,
class Alloc_>
4971 std::vector<size_type> rowIndices;
4972 std::vector<size_type> colIndices;
4974 for (
uint32 row = 0; row < shape_.rows; ++row)
4976 for (
uint32 col = 0; col < shape_.cols; ++col)
4980 rowIndices.push_back(row);
4981 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:2684
NdArray< size_type > toIndices(Slice inSlice, Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:4763
self_type operator[](Slice inSlice) const
Definition: NdArrayCore.hpp:823
self_type max(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3041
size_type size() const noexcept
Definition: NdArrayCore.hpp:4524
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:2424
self_type & put(const RowIndices &inRowIndices, const ColIndices &inColIndices, const self_type &inValues)
Definition: NdArrayCore.hpp:3964
self_type & resizeSlow(size_type inNumRows, size_type inNumCols)
Definition: NdArrayCore.hpp:4403
self_type & put(const Slice &inRowSlice, const ColIndices &inColIndices, const value_type &inValue)
Definition: NdArrayCore.hpp:3858
self_type & zeros() noexcept
Definition: NdArrayCore.hpp:4900
self_type & ones() noexcept
Definition: NdArrayCore.hpp:3487
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:2445
const_pointer data() const noexcept
Definition: NdArrayCore.hpp:2610
iterator end() noexcept
Definition: NdArrayCore.hpp:1623
self_type & swapCols(index_type colIdx1, index_type colIdx2) noexcept
Definition: NdArrayCore.hpp:4672
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:3814
self_type repeat(const Shape &inRepeatShape) const
Definition: NdArrayCore.hpp:4236
self_type at(Slice rowSlice, const Indices &colIndices) const
Definition: NdArrayCore.hpp:1256
reference back(size_type row)
Definition: NdArrayCore.hpp:2320
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:4726
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:4271
typename AllocTraits::pointer pointer
Definition: NdArrayCore.hpp:152
self_type transpose() const
Definition: NdArrayCore.hpp:4882
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:2117
const_reverse_column_iterator rcolend() const noexcept
Definition: NdArrayCore.hpp:1881
self_type rows(const NdArray< size_type > &inRows) const
Definition: NdArrayCore.hpp:4490
const dtype & const_reference
Definition: NdArrayCore.hpp:155
bool issquare() const noexcept
Definition: NdArrayCore.hpp:3009
bool isflat() const noexcept
Definition: NdArrayCore.hpp:2945
Endian endianess() const noexcept
Definition: NdArrayCore.hpp:2792
self_type dot(const self_type &inOtherArray) const
Definition: NdArrayCore.hpp:2719
void tofile(const std::string &inFilename) const
Definition: NdArrayCore.hpp:4710
const_reverse_column_iterator crcolbegin() const noexcept
Definition: NdArrayCore.hpp:1596
self_type & swapRows(index_type rowIdx1, index_type rowIdx2) noexcept
Definition: NdArrayCore.hpp:4690
const_reverse_column_iterator crcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1916
size_type numCols() const noexcept
Definition: NdArrayCore.hpp:3465
column_iterator colbegin(size_type inCol)
Definition: NdArrayCore.hpp:1404
self_type median(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3131
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:3411
pointer data() noexcept
Definition: NdArrayCore.hpp:2600
bool isempty() const noexcept
Definition: NdArrayCore.hpp:2932
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:2882
reverse_column_iterator rcolend(size_type inCol)
Definition: NdArrayCore.hpp:1866
self_type column(size_type inColumn) const
Definition: NdArrayCore.hpp:2412
self_type prod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3603
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:4511
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:4371
const_iterator cend(size_type inRow) const
Definition: NdArrayCore.hpp:1685
NdArray< size_type > flatnonzero() const
Definition: NdArrayCore.hpp:2821
self_type & byteswap() noexcept
Definition: NdArrayCore.hpp:2333
self_type & ravel()
Definition: NdArrayCore.hpp:4179
self_type getByIndices(const NdArray< size_type > &inIndices) const
Definition: NdArrayCore.hpp:2905
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:3521
self_type & put(const Indices &inRowIndices, index_type inColIndex, const value_type &inValue)
Definition: NdArrayCore.hpp:3891
const_iterator end(size_type inRow) const
Definition: NdArrayCore.hpp:1662
self_type flatten() const
Definition: NdArrayCore.hpp:2847
self_type & replace(value_type oldValue, value_type newValue)
Definition: NdArrayCore.hpp:4248
reference back() noexcept
Definition: NdArrayCore.hpp:2298
const_reverse_column_iterator crcolend() const noexcept
Definition: NdArrayCore.hpp:1904
const_reference back(size_type row) const
Definition: NdArrayCore.hpp:2309
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:4053
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:2486
self_type round(uint8 inNumDecimals=0) const
Definition: NdArrayCore.hpp:4457
std::vector< dtype > toStlVector() const
Definition: NdArrayCore.hpp:4812
self_type swapaxes() const
Definition: NdArrayCore.hpp:4659
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:2181
self_type & put(index_type inRowIndex, const Slice &inColSlice, const self_type &inValues)
Definition: NdArrayCore.hpp:4122
bool ownsInternalData() noexcept
Definition: NdArrayCore.hpp:3501
self_type operator[](const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:835
self_type & fill(value_type inFillValue) noexcept
Definition: NdArrayCore.hpp:2808
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:2287
std::pair< NdArray< size_type >, NdArray< size_type > > nonzero() const
Definition: NdArrayCore.hpp:4967
self_type diagonal(index_type inOffset=0, Axis inAxis=Axis::ROW) const
Definition: NdArrayCore.hpp:2639
self_type & put(index_type inRowIndex, const Indices &inColIndices, const self_type &inValues)
Definition: NdArrayCore.hpp:4105
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:3233
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:4070
const_reference front() const noexcept
Definition: NdArrayCore.hpp:2860
~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:2871
self_type & put(const Slice &inRowSlice, index_type inColIndex, const self_type &inValues)
Definition: NdArrayCore.hpp:4087
self_type & put(Slice inRowSlice, const ColIndices &inColIndices, const self_type &inValues)
Definition: NdArrayCore.hpp:4037
self_type & put(const Slice &inRowSlice, index_type inColIndex, const value_type &inValue)
Definition: NdArrayCore.hpp:3908
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:4135
Allocator allocator_type
Definition: NdArrayCore.hpp:151
self_type & nans() noexcept
Definition: NdArrayCore.hpp:3216
NdArray(pointer inPtr, UIntType1 numRows, UIntType2 numCols, PointerPolicy policy)
Definition: NdArrayCore.hpp:599
void print() const
Definition: NdArrayCore.hpp:3587
const_reverse_column_iterator crcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1608
self_type & reshape(const Shape &inShape)
Definition: NdArrayCore.hpp:4356
size_type numRows() const noexcept
Definition: NdArrayCore.hpp:3477
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:3749
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:4442
self_type & operator=(self_type &&rhs) noexcept
Definition: NdArrayCore.hpp:731
std::string str() const
Definition: NdArrayCore.hpp:4582
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:2552
NdArray< bool > all(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1935
self_type & resizeFast(const Shape &inShape)
Definition: NdArrayCore.hpp:4386
self_type & put(index_type inRowIndex, const Indices &inColIndices, const value_type &inValue)
Definition: NdArrayCore.hpp:3926
reference front(size_type row)
Definition: NdArrayCore.hpp:2893
self_type & put(const RowIndices &inRowIndices, Slice inColSlice, const self_type &inValues)
Definition: NdArrayCore.hpp:4020
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:4195
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:2956
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:3779
self_type newbyteorder(Endian inEndianess) const
Definition: NdArrayCore.hpp:3248
value_type item() const
Definition: NdArrayCore.hpp:3022
const_reference at(index_type inIndex) const
Definition: NdArrayCore.hpp:1046
self_type & reshape(index_type inNumRows, index_type inNumCols)
Definition: NdArrayCore.hpp:4302
const_column_iterator colend() const noexcept
Definition: NdArrayCore.hpp:1804
self_type row(size_type inRow) const
Definition: NdArrayCore.hpp:4478
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:3794
self_type & put(const Indices &inIndices, const value_type &inValue)
Definition: NdArrayCore.hpp:3728
self_type cumprod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2500
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:2765
dtype & reference
Definition: NdArrayCore.hpp:154
self_type & put(const RowIndices &inRowIndices, const Slice &inColSlice, const value_type &inValue)
Definition: NdArrayCore.hpp:3841
self_type & put(index_type inRowIndex, const Slice &inColSlice, const value_type &inValue)
Definition: NdArrayCore.hpp:3943
value_type trace(size_type inOffset=0, Axis inAxis=Axis::ROW) const noexcept
Definition: NdArrayCore.hpp:4829
pointer dataRelease() noexcept
Definition: NdArrayCore.hpp:2622
self_type ptp(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3647
self_type clip(value_type inMin, value_type inMax) const
Definition: NdArrayCore.hpp:2373
self_type getByMask(const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:2919
uint32 size_type
Definition: NdArrayCore.hpp:156
NdArray< bool > issorted(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2968
self_type & operator=(const self_type &rhs)
Definition: NdArrayCore.hpp:690
const_iterator begin() const noexcept
Definition: NdArrayCore.hpp:1342
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:3085
self_type & putMask(const NdArray< bool > &inMask, const self_type &inValues)
Definition: NdArrayCore.hpp:4152
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:4538
self_type & put(const Slice &inRowSlice, const Slice &inColSlice, const value_type &inValue)
Definition: NdArrayCore.hpp:3874
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:4618
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:3710
self_type & put(index_type inIndex, const value_type &inValue)
Definition: NdArrayCore.hpp:3693
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
void replace(ForwardIt first, ForwardIt last, const T &oldValue, const T &newValue) noexcept
Definition: StlAlgorithms.hpp:468
std::pair< ForwardIt, ForwardIt > minmax_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:364
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: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