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>;
70 namespace type_traits {
…}
137 template<
typename dtype,
class Allocator = std::allocator<dtype>>
142 static_assert(std::is_same_v<dtype, typename Allocator::value_type>,
143 "value_type and Allocator::value_type must match");
146 using AllocTraits = std::allocator_traits<AllocType>;
152 using pointer =
typename AllocTraits::pointer;
211 size_{ shape_.
size() }
224 size_{ shape_.
size() }
239 NdArray(
const std::initializer_list<std::initializer_list<dtype>>&
inList) :
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>
276 size_{ shape_.
size() }
309 template<
size_t Dim0Size,
size_t Dim1Size>
313 size_{ shape_.
size() }
322 const auto start =
in2dArray.front().begin();
347 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
350 size_{ shape_.
size() }
387 if (shape_.
cols == 0)
397 size_ = shape_.
size();
415 template<
size_t Dim1Size>
418 size_{ shape_.
size() }
427 const auto start =
in2dArray.front().begin();
451 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
454 size_{ shape_.
size() }
474 if (shape_.
cols == 0)
484 size_ = shape_.
size();
503 size_{ shape_.
size() }
520 std::enable_if_t<std::is_same_v<typename std::iterator_traits<Iterator>::value_type,
dtype>,
int> = 0>
523 size_{ shape_.
size() }
540 std::enable_if_t<std::is_integral_v<UIntType> && !std::is_same_v<UIntType, bool>,
int> = 0>
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)
579 std::enable_if_t<std::is_integral_v<UIntType> && !std::is_same_v<UIntType, bool>,
int> = 0>
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)
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;
848 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
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>
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_;
1211 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1226 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1240 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1255 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
1279 auto rowSigned = static_cast<index_type>(row);
1282 rowSigned += shape_.rows;
1287 THROW_INVALID_ARGUMENT_ERROR(
"Row index exceeds matrix dimensions");
1295 auto colSigned = static_cast<index_type>(col);
1298 colSigned += shape_.cols;
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;
1939 const auto function = [](dtype i) ->
bool {
return !utils::essentiallyEqual(i, dtype{ 0 }); };
1945 NdArray<bool> returnArray = { stl_algorithms::all_of(cbegin(), cend(), function) };
1951 for (
uint32 row = 0; row < shape_.rows; ++row)
1953 returnArray(0, row) = stl_algorithms::all_of(cbegin(row), cend(row), function);
1983 const auto function = [](dtype i) ->
bool {
return !utils::essentiallyEqual(i, dtype{ 0 }); };
1989 NdArray<bool> returnArray = { stl_algorithms::any_of(cbegin(), cend(), function) };
1995 for (
uint32 row = 0; row < shape_.rows; ++row)
1997 returnArray(0, row) = stl_algorithms::any_of(cbegin(row), cend(row), function);
2028 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
2035 stl_algorithms::max_element(cbegin(), cend(), comparitor) - cbegin()) };
2041 for (
size_type row = 0; row < shape_.rows; ++row)
2043 returnArray(0, row) =
static_cast<size_type>(
2044 stl_algorithms::max_element(cbegin(row), cend(row), comparitor) - cbegin(row));
2075 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
2082 stl_algorithms::min_element(cbegin(), cend(), comparitor) - cbegin()) };
2088 for (
size_type row = 0; row < shape_.rows; ++row)
2090 returnArray(0, row) =
static_cast<size_type>(
2091 stl_algorithms::min_element(cbegin(row), cend(row), comparitor) - cbegin(row));
2130 std::string errStr =
"kth(=" + utils::num2str(inKth);
2131 errStr +=
") out of bounds (" + utils::num2str(size_) +
")";
2135 std::vector<size_type> idx(size_);
2136 std::iota(idx.begin(), idx.end(), 0);
2139 {
return (*
this)[i1] < (*this)[i2]; };
2141 stl_algorithms::nth_element(idx.begin(), idx.begin() + inKth, idx.end(), comparitor);
2146 if (inKth >= shape_.cols)
2148 std::string errStr =
"kth(=" + utils::num2str(inKth);
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); };
2163 stl_algorithms::nth_element(idx.begin(), idx.begin() + inKth, idx.end(), comparitor);
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]; };
2207 stl_algorithms::stable_sort(idx.begin(), idx.end(), comparitor);
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); };
2222 stl_algorithms::stable_sort(idx.begin(), idx.end(), comparitor);
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>)
2266 stl_algorithms::transform(cbegin(),
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); };
2296 stl_algorithms::transform(cbegin(), cend(), outArray.
begin(), function);
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); };
2327 stl_algorithms::transform(cbegin(), cend(), outArray.
begin(), function);
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()); };
2352 stl_algorithms::transform(cbegin(), cend(), outArray.
begin(), function);
2365 return *(cend() - 1);
2376 return *(end() - 1);
2387 return *(cend(row) - 1);
2398 return *(end(row) - 1);
2413 stl_algorithms::for_each(begin(),
2415 [](dtype& value)
noexcept ->
void { value = endian::byteSwap(value); });
2419 case Endian::NATIVE:
2421 endianess_ = endian::isLittleEndian() ? Endian::BIG : Endian::LITTLE;
2424 case Endian::LITTLE:
2426 endianess_ = Endian::BIG;
2431 endianess_ = Endian::LITTLE;
2454 stl_algorithms::transform(cbegin(),
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]));
2529 NdArray<bool> returnArray = { stl_algorithms::find(cbegin(), cend(), inValue) != cend() };
2535 for (
size_type row = 0; row < shape_.rows; ++row)
2537 returnArray(0, row) = stl_algorithms::find(cbegin(row), cend(row), inValue) != cend(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))
2801 dtype dotProduct = std::inner_product(cbegin(), cend(), inOtherArray.
cbegin(), dtype{ 0 });
2805 if (shape_.cols == inOtherArray.shape_.
rows)
2808 self_type returnArray(shape_.rows, inOtherArray.shape_.
cols);
2809 auto otherArrayT = inOtherArray.
transpose();
2811 for (
uint32 i = 0; i < shape_.rows; ++i)
2813 for (
uint32 j = 0; j < otherArrayT.shape_.rows; ++j)
2816 std::inner_product(otherArrayT.cbegin(j), otherArrayT.cend(j), cbegin(i), dtype{ 0 });
2823 std::string errStr =
"shapes of [" + utils::num2str(shape_.rows) +
", " + utils::num2str(shape_.cols) +
"]";
2824 errStr +=
" and [" + utils::num2str(inOtherArray.shape_.
rows) +
", " +
2825 utils::num2str(inOtherArray.shape_.
cols) +
"]";
2826 errStr +=
" are not consistent.";
2841 void dump(
const std::string& inFilename)
const
2843 std::filesystem::path f(inFilename);
2844 if (!f.has_extension())
2846 f.replace_extension(
"bin");
2849 std::ofstream ofile(f.c_str(), std::ios::binary);
2855 if (array_ !=
nullptr)
2857 ofile.write(
reinterpret_cast<const char*
>(array_), size_ *
sizeof(dtype));
2841 void dump(
const std::string& inFilename)
const {
…}
2886 stl_algorithms::fill(begin(), end(), inFillValue);
2901 std::vector<size_type> indices;
2903 for (
auto value : *
this)
2905 if (!utils::essentiallyEqual(value, dtype{ 0 }))
2907 indices.push_back(idx);
2926 stl_algorithms::copy(cbegin(), cend(), outArray.
begin());
2960 return *cbegin(row);
2983 return operator[](inIndices);
2997 return operator[](inMask);
3023 return !isscalar() && (shape_.rows == 1 || shape_.cols == 1);
3048 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3054 return { stl_algorithms::is_sorted(cbegin(), cend(), comparitor) };
3059 for (
uint32 row = 0; row < shape_.rows; ++row)
3061 returnArray(0, row) = stl_algorithms::is_sorted(cbegin(row), cend(row), comparitor);
3087 return shape_.issquare();
3121 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3127 self_type returnArray = { *stl_algorithms::max_element(cbegin(), cend(), comparitor) };
3133 for (
uint32 row = 0; row < shape_.rows; ++row)
3135 returnArray(0, row) = *stl_algorithms::max_element(cbegin(row), cend(row), comparitor);
3165 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3171 self_type returnArray = { *stl_algorithms::min_element(cbegin(), cend(), comparitor) };
3177 for (
uint32 row = 0; row < shape_.rows; ++row)
3179 returnArray(0, row) = *stl_algorithms::min_element(cbegin(row), cend(row), comparitor);
3211 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3225 stl_algorithms::nth_element(copyArray.
begin(),
3226 copyArray.
begin() + middleIdx,
3230 dtype medianValue = copyArray.array_[middleIdx];
3233 const size_type lhsIndex = middleIdx - 1;
3234 stl_algorithms::nth_element(copyArray.
begin(),
3235 copyArray.
begin() + lhsIndex,
3239 (medianValue + copyArray.array_[lhsIndex]) / dtype{ 2 };
3242 return { medianValue };
3249 const bool isEven = shape_.cols % 2 == 0;
3250 for (
uint32 row = 0; row < shape_.rows; ++row)
3252 const uint32 middleIdx = shape_.cols / 2;
3253 stl_algorithms::nth_element(copyArray.
begin(row),
3254 copyArray.
begin(row) + middleIdx,
3258 dtype medianValue = copyArray(row, middleIdx);
3261 const size_type lhsIndex = middleIdx - 1;
3262 stl_algorithms::nth_element(copyArray.
begin(row),
3263 copyArray.
begin(row) + lhsIndex,
3266 medianValue = (medianValue + copyArray(row, lhsIndex)) /
3270 returnArray(0, row) = medianValue;
3297 fill(constants::nan);
3311 return static_cast<uint64>(
sizeof(dtype) * size_);
3328 const bool nativeIsLittle = endian::isLittleEndian();
3332 case Endian::NATIVE:
3334 switch (inEndianess)
3336 case Endian::NATIVE:
3346 stl_algorithms::transform(cbegin(), end(), outArray.
begin(), endian::byteSwap<dtype>);
3348 outArray.endianess_ = Endian::BIG;
3353 auto outArray =
NdArray(*
this);
3354 outArray.endianess_ = Endian::BIG;
3358 case Endian::LITTLE:
3362 auto outArray =
NdArray(*
this);
3363 outArray.endianess_ = Endian::LITTLE;
3370 stl_algorithms::transform(cbegin(), end(), outArray.
begin(), endian::byteSwap<dtype>);
3372 outArray.endianess_ = Endian::LITTLE;
3386 switch (inEndianess)
3388 case Endian::NATIVE:
3394 stl_algorithms::transform(cbegin(), end(), outArray.
begin(), endian::byteSwap<dtype>);
3396 outArray.endianess_ = Endian::NATIVE;
3401 auto outArray =
NdArray(*
this);
3402 outArray.endianess_ = Endian::NATIVE;
3410 case Endian::LITTLE:
3414 stl_algorithms::transform(cbegin(), end(), outArray.
begin(), endian::byteSwap<dtype>);
3416 outArray.endianess_ = Endian::LITTLE;
3427 case Endian::LITTLE:
3429 switch (inEndianess)
3431 case Endian::NATIVE:
3435 auto outArray =
NdArray(*
this);
3436 outArray.endianess_ = Endian::NATIVE;
3443 stl_algorithms::transform(cbegin(), end(), outArray.
begin(), endian::byteSwap<dtype>);
3445 outArray.endianess_ = Endian::NATIVE;
3453 stl_algorithms::transform(cbegin(), end(), outArray.
begin(), endian::byteSwap<dtype>);
3455 outArray.endianess_ = Endian::BIG;
3458 case Endian::LITTLE:
3491 const auto function = [](dtype i) ->
bool {
return !utils::essentiallyEqual(i, dtype{ 0 }); };
3497 NdArray<bool> returnArray = { stl_algorithms::none_of(cbegin(), cend(), function) };
3503 for (
uint32 row = 0; row < shape_.rows; ++row)
3505 returnArray(0, row) = stl_algorithms::none_of(cbegin(row), cend(row), function);
3601 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool
3602 {
return lhs < rhs; };
3610 std::string errStr =
"kth(=" + utils::num2str(inKth);
3611 errStr +=
") out of bounds (" + utils::num2str(size_) +
")";
3615 stl_algorithms::nth_element(begin(), begin() + inKth, end(), comparitor);
3620 if (inKth >= shape_.cols)
3622 std::string errStr =
"kth(=" + utils::num2str(inKth);
3623 errStr +=
") out of bounds (" + utils::num2str(shape_.cols) +
")";
3627 for (
uint32 row = 0; row < shape_.rows; ++row)
3629 stl_algorithms::nth_element(begin(row), begin(row) + inKth, end(row), comparitor);
3635 if (inKth >= shape_.rows)
3637 std::string errStr =
"kth(=" + utils::num2str(inKth);
3638 errStr +=
") out of bounds (" + utils::num2str(shape_.rows) +
")";
3643 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3645 stl_algorithms::nth_element(transposedArray.
begin(row),
3646 transposedArray.
begin(row) + inKth,
3647 transposedArray.
end(row),
3687 dtype product = std::accumulate(cbegin(), cend(), dtype{ 1 }, std::multiplies<dtype>());
3694 for (
uint32 row = 0; row < shape_.rows; ++row)
3696 returnArray(0, row) =
3697 std::accumulate(cbegin(row), cend(row), dtype{ 1 }, std::multiplies<dtype>());
3727 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool {
return lhs < rhs; };
3733 const auto result = stl_algorithms::minmax_element(cbegin(), cend(), comparitor);
3734 self_type returnArray = { *result.second - *result.first };
3740 for (
uint32 row = 0; row < shape_.rows; ++row)
3742 const auto result = stl_algorithms::minmax_element(cbegin(row), cend(row), comparitor);
3743 returnArray(0, row) = *result.second - *result.first;
3771 at(inIndex) = inValue;
3788 at(inRow, inCol) = inValue;
3803 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3806 for (
auto index : inIndices)
3808 put(index, inValue);
3824 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3829 return put(inIndices, inValues.
item());
3831 else if (inIndices.size() != inValues.
size())
3837 for (
auto index : inIndices)
3839 put(index, inValues[counter++]);
3857 return put(toIndices(inSlice, Axis::NONE), inValue);
3872 return put(toIndices(inSlice, Axis::NONE), inValues);
3886 template<
typename RowIndices,
3887 typename ColIndices,
3892 stl_algorithms::for_each(inRowIndices.begin(),
3894 [
this, &inColIndices, &inValue](
const auto row)
3896 stl_algorithms::for_each(inColIndices.begin(),
3898 [this, row, &inValue](const auto col)
3899 { this->put(row, col, inValue); });
3916 template<
typename RowIndices, type_traits::ndarray_
int_concept<RowIndices> = 0>
3919 return put(inRowIndices, toIndices(inColSlice, Axis::COL), inValue);
3933 template<
typename ColIndices, type_traits::ndarray_
int_concept<ColIndices> = 0>
3936 return put(toIndices(inRowSlice, Axis::ROW), inColIndices, inValue);
3952 return put(toIndices(inRowSlice, Axis::ROW), toIndices(inColSlice, Axis::COL), inValue);
3966 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
3970 return put(inRowIndices, colIndices, inValue);
3987 return put(toIndices(inRowSlice, Axis::ROW), colIndices, inValue);
4001 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
4005 return put(rowIndices, inColIndices, inValue);
4022 return put(rowIndices, toIndices(inColSlice, Axis::COL), inValue);
4036 template<
typename RowIndices,
4037 typename ColIndices,
4042 std::vector<size_type> indices;
4043 indices.reserve(inRowIndices.size() * inColIndices.size());
4044 std::for_each(inRowIndices.begin(),
4046 [
this, &inColIndices, &indices](
auto row)
4048 if constexpr (std::is_signed_v<decltype(row)>)
4057 THROW_INVALID_ARGUMENT_ERROR(
"row index exceeds matrix dimensions");
4060 std::for_each(inColIndices.begin(),
4062 [
this, row, &indices](
auto col)
4064 if constexpr (std::is_signed_v<decltype(col)>)
4073 THROW_INVALID_ARGUMENT_ERROR(
4074 "col index exceeds matrix dimensions");
4077 indices.push_back(row * shape_.cols + col);
4081 return put(NdArray<size_type>(indices.data(), indices.size(), PointerPolicy::SHELL), inValues);
4095 template<
typename RowIndices, type_traits::ndarray_
int_concept<RowIndices> = 0>
4098 return put(inRowIndices, toIndices(inColSlice, Axis::COL), inValues);
4112 template<
typename ColIndices, type_traits::ndarray_
int_concept<ColIndices> = 0>
4115 return put(toIndices(inRowSlice, Axis::ROW), inColIndices, inValues);
4131 return put(toIndices(inRowSlice, Axis::ROW), toIndices(inColSlice, Axis::COL), inValues);
4145 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
4149 return put(inRowIndices, colIndices, inValues);
4166 return put(toIndices(inRowSlice, Axis::ROW), colIndices, inValues);
4180 template<
typename Indices, type_traits::ndarray_
int_concept<Indices> = 0>
4184 return put(rowIndices, inColIndices, inValues);
4201 return put(rowIndices, toIndices(inColSlice, Axis::COL), inValues);
4213 if (inMask.
shape() != shape_)
4230 if (inMask.
shape() != shape_)
4273 self_type returnArray(shape_.rows * inNumRows, shape_.cols * inNumCols);
4275 for (
size_type row = 0; row < inNumRows; ++row)
4277 for (
size_type col = 0; col < inNumCols; ++col)
4279 std::vector<size_type> indices(shape_.size());
4281 const size_type rowStart = row * shape_.rows;
4282 const size_type colStart = col * shape_.cols;
4284 const size_type rowEnd = (row + 1) * shape_.rows;
4285 const size_type colEnd = (col + 1) * shape_.cols;
4288 for (
size_type rowIdx = rowStart; rowIdx < rowEnd; ++rowIdx)
4290 for (
size_type colIdx = colStart; colIdx < colEnd; ++colIdx)
4292 indices[counter++] = rowIdx * returnArray.shape_.
cols + colIdx;
4328 stl_algorithms::replace(begin(), end(), oldValue, newValue);
4349 if (inSize != size_)
4351 std::string errStr =
"Cannot reshape array of size " + utils::num2str(size_) +
" into shape ";
4352 errStr +=
"[" + utils::num2str(1) +
", " + utils::num2str(inSize) +
"]";
4357 shape_.cols = inSize;
4382 if (size_ % inNumCols == 0)
4384 return reshape(size_ / inNumCols, inNumCols);
4387 std::string errStr =
"Cannot reshape array of size " + utils::num2str(size_) +
" into a shape ";
4388 errStr +=
"with " + utils::num2str(inNumCols) +
" columns";
4394 if (size_ % inNumRows == 0)
4396 return reshape(inNumRows, size_ / inNumRows);
4399 std::string errStr =
"Cannot reshape array of size " + utils::num2str(size_) +
" into a shape ";
4400 errStr +=
"with " + utils::num2str(inNumRows) +
" rows";
4404 if (
static_cast<size_type>(inNumRows * inNumCols) != size_)
4406 std::string errStr =
"Cannot reshape array of size " + utils::num2str(size_) +
" into shape ";
4407 errStr +=
"[" + utils::num2str(inNumRows) +
", " + utils::num2str(inNumCols) +
"]";
4411 shape_.rows =
static_cast<size_type>(inNumRows);
4412 shape_.cols =
static_cast<size_type>(inNumCols);
4449 newArray(
Shape(inNumRows, inNumCols));
4481 std::vector<dtype> oldData(size_);
4482 stl_algorithms::copy(begin(), end(), oldData.begin());
4484 const Shape inShape(inNumRows, inNumCols);
4485 const Shape oldShape = shape_;
4489 for (
uint32 row = 0; row < inShape.
rows; ++row)
4491 for (
uint32 col = 0; col < inShape.
cols; ++col)
4493 if (row >= oldShape.
rows || col >= oldShape.
cols)
4495 operator()(row, col) = dtype{ 0 };
4499 operator()(row, col) = oldData[row * oldShape.
cols + col];
4538 const double multFactor = utils::power(10., inNumDecimals);
4539 const auto function = [multFactor](dtype value)
noexcept -> dtype
4540 {
return static_cast<dtype
>(std::nearbyint(
static_cast<double>(value) * multFactor) / multFactor); };
4542 stl_algorithms::transform(cbegin(), cend(), returnArray.
begin(), function);
4556 return self_type(cbegin(inRow), cend(inRow));
4569 const auto cSlice = returnArray.cSlice();
4573 returnArray.put(i, cSlice, row(inRows[i]));
4618 const auto comparitor = [](dtype lhs, dtype rhs)
noexcept ->
bool
4619 {
return lhs < rhs; };
4625 stl_algorithms::sort(begin(), end(), comparitor);
4630 for (
uint32 row = 0; row < shape_.rows; ++row)
4632 stl_algorithms::sort(begin(row), end(row), comparitor);
4639 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
4641 stl_algorithms::sort(transposedArray.
begin(row), transposedArray.
end(row), comparitor);
4658 [[nodiscard]] std::string
str()
const
4664 for (
uint32 row = 0; row < shape_.rows; ++row)
4667 for (
uint32 col = 0; col < shape_.cols; ++col)
4669 out += utils::value2str(
operator()(row, col)) +
", ";
4672 if (row == shape_.rows - 1)
4658 [[nodiscard]] std::string
str()
const {
…}
4702 self_type returnArray = { std::accumulate(cbegin(), cend(), dtype{ 0 }) };
4708 for (
uint32 row = 0; row < shape_.rows; ++row)
4710 returnArray(0, row) = std::accumulate(cbegin(row), cend(row), dtype{ 0 });
4750 for (
index_type row = 0; row < static_cast<index_type>(shape_.rows); ++row)
4752 std::swap(
operator()(row, colIdx1),
operator()(row, colIdx2));
4768 for (
index_type col = 0; col < static_cast<index_type>(shape_.cols); ++col)
4770 std::swap(
operator()(rowIdx1, col),
operator()(rowIdx2, col));
4786 void tofile(
const std::string& inFilename)
const
4786 void tofile(
const std::string& inFilename)
const {
…}
4802 void tofile(
const std::string& inFilename,
const char inSep)
const
4806 std::filesystem::path f(inFilename);
4807 if (!f.has_extension())
4809 f.replace_extension(
"txt");
4812 std::ofstream ofile(f.c_str());
4819 for (
auto value : *
this)
4822 if (counter++ != size_ - 1)
4802 void tofile(
const std::string& inFilename,
const char inSep)
const {
…}
4866 if (numElements == 0)
4890 return std::vector<dtype>(cbegin(), cend());
4915 rowStart += inOffset;
4920 colStart += inOffset;
4931 if (rowStart >= shape_.rows || colStart >= shape_.cols)
4938 for (
size_type row = rowStart; row < shape_.rows; ++row)
4940 if (col >= shape_.cols)
4944 sum += operator()(row, col++);
4960 self_type transArray(shape_.cols, shape_.rows);
4961 for (
uint32 row = 0; row < shape_.rows; ++row)
4963 for (
uint32 col = 0; col < shape_.cols; ++col)
4965 transArray(col, row) = operator()(row, col);
4986 allocator_type allocator_{};
4987 Shape shape_{ 0, 0 };
4988 size_type size_{ 0 };
4989 Endian endianess_{ Endian::NATIVE };
4990 pointer array_{
nullptr };
4991 bool ownsPtr_{
false };
4997 void deleteArray() noexcept
4999 if (ownsPtr_ && array_ !=
nullptr)
5001 allocator_.deallocate(array_, size_);
5005 shape_.rows = shape_.cols = 0;
5008 endianess_ = Endian::NATIVE;
5019 array_ = allocator_.allocate(size_);
5030 void newArray(
const Shape& inShape)
5035 size_ = inShape.size();
5042 template<
typename dtype,
class Alloc_>
5047 std::vector<size_type> rowIndices;
5048 std::vector<size_type> colIndices;
5050 for (
uint32 row = 0; row < shape_.rows; ++row)
5052 for (
uint32 col = 0; col < shape_.cols; ++col)
5054 if (!utils::essentiallyEqual(
operator()(row, col), dtype{ 0 }))
5056 rowIndices.push_back(row);
5057 colIndices.push_back(col);
#define THROW_RUNTIME_ERROR(msg)
Definition Error.hpp:40
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_VALID_DTYPE(dtype)
Definition StaticAsserts.hpp:35
#define STATIC_ASSERT_FLOAT(dtype)
Definition StaticAsserts.hpp:50
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition StaticAsserts.hpp:56
#define STATIC_ASSERT_INTEGER(dtype)
Definition StaticAsserts.hpp:43
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
Custom column iterator for NdArray.
Definition NdArrayIterators.hpp:813
Custom column const_iterator for NdArray.
Definition NdArrayIterators.hpp:487
Custom const_iterator for NdArray.
Definition NdArrayIterators.hpp:41
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp: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:4839
self_type operator[](Slice inSlice) const
Definition NdArrayCore.hpp:823
self_type max(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:3117
size_type size() const noexcept
Definition NdArrayCore.hpp:4600
reverse_iterator rbegin() noexcept
Definition NdArrayCore.hpp: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:4040
self_type & resizeSlow(size_type inNumRows, size_type inNumCols)
Definition NdArrayCore.hpp:4479
self_type & put(const Slice &inRowSlice, const ColIndices &inColIndices, const value_type &inValue)
Definition NdArrayCore.hpp:3934
self_type & zeros() noexcept
Definition NdArrayCore.hpp:4976
self_type & ones() noexcept
Definition NdArrayCore.hpp:3563
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:4748
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:3890
self_type repeat(const Shape &inRepeatShape) const
Definition NdArrayCore.hpp:4312
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:4802
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:4347
typename AllocTraits::pointer pointer
Definition NdArrayCore.hpp:152
self_type transpose() const
Definition NdArrayCore.hpp:4958
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:4566
const dtype & const_reference
Definition NdArrayCore.hpp:155
bool issquare() const noexcept
Definition NdArrayCore.hpp:3085
bool isflat() const noexcept
Definition NdArrayCore.hpp:3021
Endian endianess() const noexcept
Definition NdArrayCore.hpp:2868
self_type dot(const self_type &inOtherArray) const
Definition NdArrayCore.hpp:2795
void tofile(const std::string &inFilename) const
Definition NdArrayCore.hpp:4786
const_reverse_column_iterator crcolbegin() const noexcept
Definition NdArrayCore.hpp:1596
self_type & swapRows(index_type rowIdx1, index_type rowIdx2) noexcept
Definition NdArrayCore.hpp:4766
const_reverse_column_iterator crcolend(size_type inCol) const
Definition NdArrayCore.hpp:1916
size_type numCols() const noexcept
Definition NdArrayCore.hpp:3541
column_iterator colbegin(size_type inCol)
Definition NdArrayCore.hpp:1404
self_type median(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:3207
const_reference at(index_type inRowIndex, index_type inColIndex) const
Definition NdArrayCore.hpp:1081
self_type at(const Slice &inSlice) const
Definition NdArrayCore.hpp:1111
NdArray< bool > none(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:3487
pointer data() noexcept
Definition NdArrayCore.hpp:2676
bool isempty() const noexcept
Definition NdArrayCore.hpp:3008
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:2958
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:3679
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:4587
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:4447
const_iterator cend(size_type inRow) const
Definition NdArrayCore.hpp:1685
NdArray< size_type > flatnonzero() const
Definition NdArrayCore.hpp:2897
self_type & byteswap() noexcept
Definition NdArrayCore.hpp:2409
self_type & ravel()
Definition NdArrayCore.hpp:4255
self_type getByIndices(const NdArray< size_type > &inIndices) const
Definition NdArrayCore.hpp:2981
const_reverse_column_iterator rcolend(size_type inCol) const
Definition NdArrayCore.hpp: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:3597
self_type & put(const Indices &inRowIndices, index_type inColIndex, const value_type &inValue)
Definition NdArrayCore.hpp:3967
const_iterator end(size_type inRow) const
Definition NdArrayCore.hpp:1662
self_type flatten() const
Definition NdArrayCore.hpp:2923
self_type & replace(value_type oldValue, value_type newValue)
Definition NdArrayCore.hpp:4324
reference back() noexcept
Definition NdArrayCore.hpp: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:4129
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:4533
std::vector< dtype > toStlVector() const
Definition NdArrayCore.hpp:4888
self_type swapaxes() const
Definition NdArrayCore.hpp:4735
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:4198
bool ownsInternalData() noexcept
Definition NdArrayCore.hpp:3577
self_type operator[](const NdArray< bool > &inMask) const
Definition NdArrayCore.hpp:835
self_type & fill(value_type inFillValue) noexcept
Definition NdArrayCore.hpp:2884
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:5043
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:4181
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:3309
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:4146
const_reference front() const noexcept
Definition NdArrayCore.hpp:2936
~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:2947
self_type & put(const Slice &inRowSlice, index_type inColIndex, const self_type &inValues)
Definition NdArrayCore.hpp:4163
self_type & put(Slice inRowSlice, const ColIndices &inColIndices, const self_type &inValues)
Definition NdArrayCore.hpp:4113
self_type & put(const Slice &inRowSlice, index_type inColIndex, const value_type &inValue)
Definition NdArrayCore.hpp:3984
NdArray(size_type inNumRows, size_type inNumCols)
Definition NdArrayCore.hpp:196
self_type & putMask(const NdArray< bool > &inMask, const value_type &inValue)
Definition NdArrayCore.hpp:4211
Allocator allocator_type
Definition NdArrayCore.hpp:151
self_type & nans() noexcept
Definition NdArrayCore.hpp:3292
NdArray(pointer inPtr, UIntType1 numRows, UIntType2 numCols, PointerPolicy policy)
Definition NdArrayCore.hpp:599
void print() const
Definition NdArrayCore.hpp:3663
const_reverse_column_iterator crcolbegin(size_type inCol) const
Definition NdArrayCore.hpp:1608
self_type & reshape(const Shape &inShape)
Definition NdArrayCore.hpp:4432
size_type numRows() const noexcept
Definition NdArrayCore.hpp:3553
reverse_iterator rend(size_type inRow)
Definition NdArrayCore.hpp: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:3825
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:4518
self_type & operator=(self_type &&rhs) noexcept
Definition NdArrayCore.hpp:731
std::string str() const
Definition NdArrayCore.hpp:4658
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:4462
self_type & put(index_type inRowIndex, const Indices &inColIndices, const value_type &inValue)
Definition NdArrayCore.hpp:4002
reference front(size_type row)
Definition NdArrayCore.hpp:2969
self_type & put(const RowIndices &inRowIndices, Slice inColSlice, const self_type &inValues)
Definition NdArrayCore.hpp:4096
NdArray(std::array< std::array< dtype, Dim1Size >, Dim0Size > &in2dArray, PointerPolicy policy=PointerPolicy::COPY)
Definition NdArrayCore.hpp:310
self_type repeat(size_type inNumRows, size_type inNumCols) const
Definition NdArrayCore.hpp:4271
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:3032
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:3855
self_type newbyteorder(Endian inEndianess) const
Definition NdArrayCore.hpp:3324
value_type item() const
Definition NdArrayCore.hpp:3098
const_reference at(index_type inIndex) const
Definition NdArrayCore.hpp:1046
self_type & reshape(index_type inNumRows, index_type inNumCols)
Definition NdArrayCore.hpp:4378
const_column_iterator colend() const noexcept
Definition NdArrayCore.hpp:1804
self_type row(size_type inRow) const
Definition NdArrayCore.hpp:4554
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:3870
self_type & put(const Indices &inIndices, const value_type &inValue)
Definition NdArrayCore.hpp:3804
self_type cumprod(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp: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:2841
dtype & reference
Definition NdArrayCore.hpp:154
self_type & put(const RowIndices &inRowIndices, const Slice &inColSlice, const value_type &inValue)
Definition NdArrayCore.hpp:3917
self_type & put(index_type inRowIndex, const Slice &inColSlice, const value_type &inValue)
Definition NdArrayCore.hpp:4019
value_type trace(size_type inOffset=0, Axis inAxis=Axis::ROW) const noexcept
Definition NdArrayCore.hpp:4905
pointer dataRelease() noexcept
Definition NdArrayCore.hpp:2698
self_type ptp(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:3723
self_type clip(value_type inMin, value_type inMax) const
Definition NdArrayCore.hpp:2449
self_type getByMask(const NdArray< bool > &inMask) const
Definition NdArrayCore.hpp:2995
uint32 size_type
Definition NdArrayCore.hpp:156
NdArray< bool > issorted(Axis inAxis=Axis::NONE) const
Definition NdArrayCore.hpp:3044
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:3161
self_type & putMask(const NdArray< bool > &inMask, const self_type &inValues)
Definition NdArrayCore.hpp:4228
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:4614
self_type & put(const Slice &inRowSlice, const Slice &inColSlice, const value_type &inValue)
Definition NdArrayCore.hpp:3950
const_reverse_iterator crend(size_type inRow) const
Definition NdArrayCore.hpp: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:4694
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:3786
self_type & put(index_type inIndex, const value_type &inValue)
Definition NdArrayCore.hpp:3769
Custom iterator for NdArray.
Definition NdArrayIterators.hpp:313
A Shape Class for NdArrays.
Definition Core/shape.hpp:41
uint32 rows
Definition Core/shape.hpp:44
uint32 cols
Definition Core/shape.hpp:45
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
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition StlAlgorithms.hpp:225
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition StlAlgorithms.hpp:97
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
Definition Cartesian.hpp:40
uint32 size(const NdArray< dtype > &inArray) noexcept
Definition size.hpp:43
NdArray< dtype > & resizeSlow(NdArray< dtype > &inArray, uint32 inNumRows, uint32 inNumCols)
Definition resizeSlow.hpp:52
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
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
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59
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