51 #include <forward_list>
53 #include <initializer_list>
61 #include <type_traits>
70 template<
typename dtype,
class Allocator = std::allocator<dtype>>
74 STATIC_ASSERT_VALID_DTYPE(dtype);
75 static_assert(is_same_v<dtype, typename Allocator::value_type>,
"value_type and Allocator::value_type must match");
77 using AllocType =
typename std::allocator_traits<Allocator>::template rebind_alloc<dtype>;
78 using AllocTraits = std::allocator_traits<AllocType>;
83 using pointer =
typename AllocTraits::pointer;
114 shape_(inSquareSize, inSquareSize),
115 size_(inSquareSize * inSquareSize)
128 shape_(inNumRows, inNumCols),
129 size_(inNumRows * inNumCols)
155 NdArray(
const std::initializer_list<dtype>& inList) :
156 shape_(1, static_cast<
uint32>(inList.
size())),
173 NdArray(
const std::initializer_list<std::initializer_list<dtype> >& inList) :
176 for (
const auto& list : inList)
178 if (shape_.
cols == 0)
180 shape_.
cols =
static_cast<uint32>(list.size());
182 else if (list.size() != shape_.
cols)
188 size_ = shape_.
size();
191 for (
const auto& list : inList)
207 template<
size_t ArraySize,
208 std::enable_if_t<is_valid_dtype_v<dtype>,
int> = 0>
209 NdArray(std::array<dtype, ArraySize>& inArray,
bool copy =
true) :
210 shape_(1, static_cast<
uint32>(ArraySize)),
223 array_ = inArray.data();
236 template<
size_t Dim0Size,
size_t Dim1Size>
237 NdArray(std::array<std::array<dtype, Dim1Size>, Dim0Size>& in2dArray,
bool copy =
true) :
238 shape_(static_cast<
uint32>(Dim0Size), static_cast<
uint32>(Dim1Size)),
246 const auto start = in2dArray.front().begin();
252 array_ = in2dArray.front().data();
265 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
267 shape_(1, static_cast<
uint32>(inVector.
size())),
280 array_ = inVector.data();
291 explicit NdArray(
const std::vector<std::vector<dtype>>& in2dVector) :
292 shape_(static_cast<
uint32>(in2dVector.
size()), 0)
294 for (
const auto&
row : in2dVector)
296 if (shape_.
cols == 0)
300 else if (
row.size() != shape_.
cols)
306 size_ = shape_.
size();
309 auto currentPosition =
begin();
310 for (
const auto&
row : in2dVector)
313 currentPosition += shape_.
cols;
325 template<
size_t Dim1Size>
326 NdArray(std::vector<std::array<dtype, Dim1Size>>& in2dArray,
bool copy =
true) :
327 shape_(static_cast<
uint32>(in2dArray.
size()), static_cast<
uint32>(Dim1Size)),
335 const auto start = in2dArray.front().begin();
341 array_ = in2dArray.front().data();
352 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
353 explicit NdArray(
const std::deque<dtype>& inDeque) :
354 shape_(1, static_cast<
uint32>(inDeque.
size())),
370 explicit NdArray(
const std::deque<std::deque<dtype>>& in2dDeque) :
371 shape_(static_cast<
uint32>(in2dDeque.
size()), 0)
373 for (
const auto&
row : in2dDeque)
375 if (shape_.
cols == 0)
379 else if (
row.size() != shape_.
cols)
385 size_ = shape_.
size();
388 auto currentPosition =
begin();
389 for (
const auto&
row : in2dDeque)
392 currentPosition += shape_.
cols;
403 explicit NdArray(
const std::list<dtype>& inList) :
404 shape_(1, static_cast<
uint32>(inList.
size())),
421 template<
typename Iterator,
422 std::enable_if_t<is_same_v<typename std::iterator_traits<Iterator>::value_type, dtype>,
int> = 0>
424 shape_(1, static_cast<
uint32>(std::distance(inFirst, inLast))),
447 if (inPtr !=
nullptr && size_ > 0)
462 template<
typename UIntType1,
typename UIntType2,
463 std::enable_if_t<!is_same_v<UIntType1, bool>,
int> = 0,
464 std::enable_if_t<!is_same_v<UIntType2, bool>,
int> = 0>
470 if (inPtr !=
nullptr && size_ > 0)
486 template<
typename Bool,
487 std::enable_if_t<is_same_v<Bool, bool>,
int> = 0>
492 ownsPtr_(takeOwnership)
506 template<
typename Bool,
507 std::enable_if_t<is_same_v<Bool, bool>,
int> = 0>
512 ownsPtr_(takeOwnership)
523 shape_(inOtherArray.shape_),
524 size_(inOtherArray.size_),
525 endianess_(inOtherArray.endianess_)
542 shape_(inOtherArray.shape_),
543 size_(inOtherArray.size_),
544 endianess_(inOtherArray.endianess_),
545 array_(inOtherArray.array_),
546 ownsPtr_(inOtherArray.ownsPtr_)
548 inOtherArray.shape_.rows = inOtherArray.shape_.cols = 0;
549 inOtherArray.size_ = 0;
550 inOtherArray.ownsPtr_ =
false;
551 inOtherArray.array_ =
nullptr;
578 newArray(rhs.shape_);
579 endianess_ = rhs.endianess_;
600 if (array_ !=
nullptr)
624 endianess_ = rhs.endianess_;
626 ownsPtr_ = rhs.ownsPtr_;
628 rhs.shape_.rows = rhs.shape_.cols = rhs.size_ = 0;
629 rhs.array_ =
nullptr;
630 rhs.ownsPtr_ =
false;
652 return array_[inIndex];
671 return array_[inIndex];
687 inRowIndex += shape_.
rows;
692 inColIndex += shape_.
cols;
695 return array_[inRowIndex * shape_.
cols + inColIndex];
711 inRowIndex += shape_.
rows;
716 inColIndex += shape_.
cols;
719 return array_[inRowIndex * shape_.
cols + inColIndex];
734 Slice inSliceCopy(inSlice);
740 returnArray[counter++] =
at(i);
757 if (inMask.
shape() != shape_)
764 for (
size_type i = 0; i < indices.size(); ++i)
782 template<
typename Indices,
786 if (inIndices.max().item() > size_ - 1)
793 for (
auto& index : inIndices)
821 returnArray(rowCounter, colCounter++) =
at(
row, col);
847 returnArray(rowCounter++, 0) =
at(
row, inColIndex);
870 returnArray(0, colCounter++) =
at(inRowIndex, col);
886 template<
typename Indices,
904 template<
typename Indices,
921 template<
typename Indices,
939 template<
typename Indices,
956 template<
typename RowIndices,
typename ColIndices,
964 std::vector<int32> rowIndicesUnique(rowIndices.size());
965 std::vector<int32> colIndicesUnique(colIndices.size());
971 static_cast<uint32>(lastCol - colIndicesUnique.begin()));
974 for (
auto rowIter = rowIndicesUnique.begin(); rowIter != lastRow; ++rowIter)
977 for (
auto colIter = colIndicesUnique.begin(); colIter != lastCol; ++colIter)
979 returnArray(rowCounter, colCounter++) =
at(*rowIter, *colIter);
1000 return Slice(inStartIdx, shape_.
cols, inStepSize);
1015 return Slice(inStartIdx, shape_.
rows, inStepSize);
1034 errStr +=
" is out of bounds for array of size " +
utils::num2str(size_) +
".";
1057 errStr +=
" is out of bounds for array of size " +
utils::num2str(size_) +
".";
1080 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
rows) +
".";
1088 std::string errStr =
"Column index " +
utils::num2str(inColIndex);
1089 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
cols) +
".";
1112 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
rows) +
".";
1120 std::string errStr =
"Column index " +
utils::num2str(inColIndex);
1121 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
cols) +
".";
1230 if (inRow >= shape_.
rows)
1235 return begin() += (inRow * shape_.
cols);
1286 if (inRow >= shape_.
rows)
1316 if (inCol >= shape_.
cols)
1372 if (inCol >= shape_.
cols)
1402 if (inRow >= shape_.
rows)
1458 if (inRow >= shape_.
rows)
1488 if (inCol >= shape_.
cols)
1544 if (inCol >= shape_.
cols)
1560 return begin() += size_;
1574 if (inRow >= shape_.
rows)
1616 return cbegin() += size_;
1630 if (inRow >= shape_.
rows)
1646 return rbegin() += size_;
1660 if (inRow >= shape_.
rows)
1690 return crend(inRow);
1716 if (inRow >= shape_.
rows)
1746 if (inCol >= shape_.
cols)
1802 if (inCol >= shape_.
cols)
1832 if (inCol >= shape_.
cols)
1888 if (inCol >= shape_.
cols)
1911 const auto function = [](dtype i) ->
bool
1913 return i != dtype{ 0 };
1967 const auto function = [](dtype i) ->
bool
1969 return i != dtype{ 0 };
2024 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
2084 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
2147 std::vector<uint32> idx(size_);
2148 std::iota(idx.begin(), idx.end(), 0);
2150 const auto function = [
this](
uint32 i1,
uint32 i2) noexcept ->
bool
2152 return (*
this)[i1] < (*this)[i2];
2163 std::vector<uint32> idx(shape_.
cols);
2164 std::iota(idx.begin(), idx.end(), 0);
2166 const auto function = [
this,
row](
uint32 i1,
uint32 i2) noexcept ->
bool
2173 for (
uint32 col = 0; col < shape_.
cols; ++col)
2175 returnArray(
row, col) = idx[col];
2186 std::vector<uint32> idx(arrayTransposed.shape_.
cols);
2187 std::iota(idx.begin(), idx.end(), 0);
2189 const auto function = [&arrayTransposed,
row](
uint32 i1,
uint32 i2) noexcept ->
bool
2191 return arrayTransposed(
row, i1) < arrayTransposed(
row, i2);
2196 for (
uint32 col = 0; col < arrayTransposed.shape_.
cols; ++col)
2198 returnArray(
row, col) = idx[col];
2221 template<
typename dtypeOut,
typename dtype_ = dtype,
2229 if (is_same_v<dtypeOut, dtype>)
2235 const auto function = [](dtype value) -> dtypeOut
2237 return static_cast<dtypeOut
>(value);
2256 template<
typename dtypeOut,
typename dtype_ = dtype,
2266 return std::complex<typename dtypeOut::value_type>(value);
2284 template<
typename dtypeOut,
typename dtype_ = dtype,
2292 if (is_same_v<dtypeOut, dtype>)
2300 return complex_cast<typename dtypeOut::value_type>(value);
2319 template<
typename dtypeOut,
typename dtype_ = dtype,
2329 return static_cast<dtypeOut
>(value.real());
2346 return *(
cend() - 1);
2358 return *(
end() - 1);
2399 [](dtype& value) noexcept ->
void
2444 [inMin, inMax](dtype value) noexcept -> dtype
2446 #ifdef __cpp_lib_clamp
2447 const auto comparitor = [](dtype lhs, dtype rhs) noexcept -> bool
2452 return std::clamp(value, inMin, inMax, comparitor);
2458 else if (value > inMax)
2480 return operator()(rSlice(), inColumn);
2506 for (
uint32 row = 0; row < shape_.rows; ++row)
2517 for (
uint32 row = 0; row < transArray.shape_.
rows; ++row)
2566 returnArray[0] = front();
2567 for (
uint32 i = 1; i < size_; ++i)
2569 returnArray[i] = returnArray[i - 1] * array_[i];
2577 for (
uint32 row = 0; row < shape_.rows; ++row)
2579 returnArray(row, 0) = operator()(row, 0);
2580 for (
uint32 col = 1; col < shape_.cols; ++col)
2582 returnArray(row, col) = returnArray(row, col - 1) * operator()(row, col);
2591 for (
uint32 col = 0; col < shape_.cols; ++col)
2593 returnArray(0, col) = operator()(0, col);
2594 for (
uint32 row = 1; row < shape_.rows; ++row)
2596 returnArray(row, col) = returnArray(row - 1, col) * operator()(row, col);
2630 returnArray[0] = front();
2631 for (
uint32 i = 1; i < size_; ++i)
2633 returnArray[i] = returnArray[i - 1] + array_[i];
2641 for (
uint32 row = 0; row < shape_.rows; ++row)
2643 returnArray(row, 0) = operator()(row, 0);
2644 for (
uint32 col = 1; col < shape_.cols; ++col)
2646 returnArray(row, col) = returnArray(row, col - 1) + operator()(row, col);
2655 for (
uint32 col = 0; col < shape_.cols; ++col)
2657 returnArray(0, col) = operator()(0, col);
2658 for (
uint32 row = 1; row < shape_.rows; ++row)
2660 returnArray(row, col) = returnArray(row - 1, col) + operator()(row, col);
2724 std::vector<dtype> diagnolValues;
2725 int32 col = inOffset;
2726 for (
uint32 row = 0; row < shape_.rows; ++row)
2733 if (col >=
static_cast<int32>(shape_.cols))
2738 diagnolValues.push_back(
operator()(row,
static_cast<uint32>(col)));
2746 std::vector<dtype> diagnolValues;
2748 for (
int32 row = inOffset; row < static_cast<int32>(shape_.rows); ++row)
2755 if (col >= shape_.cols)
2760 diagnolValues.push_back(
operator()(
static_cast<uint32>(row), col));
2792 if (shape_ == inOtherArray.shape_ && (shape_.rows == 1 || shape_.cols == 1))
2794 dtype dotProduct = std::inner_product(cbegin(), cend(), inOtherArray.
cbegin(), dtype{ 0 });
2798 if (shape_.cols == inOtherArray.shape_.
rows)
2802 auto otherArrayT = inOtherArray.
transpose();
2804 for (
uint32 i = 0; i < shape_.rows; ++i)
2806 for (
uint32 j = 0;
j < otherArrayT.shape_.rows; ++
j)
2808 returnArray(i,
j) = std::inner_product(otherArrayT.cbegin(
j), otherArrayT.cend(
j), cbegin(i), dtype{ 0 });
2817 errStr +=
" are not consistent.";
2832 void dump(
const std::string& inFilename)
const
2840 std::ofstream ofile(
f.fullName().c_str(), std::ios::binary);
2846 if (array_ !=
nullptr)
2848 ofile.write(
reinterpret_cast<const char*
>(array_), size_ *
sizeof(dtype));
2896 std::vector<uint32> indices;
2898 for (
auto value : *
this)
2900 if (value != dtype{ 0 })
2902 indices.push_back(idx);
2959 return *cbegin(row);
2985 return operator[](inIndices);
3001 return operator[](inMask);
3027 return shape_.rows == 1 || shape_.cols == 1;
3041 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3056 for (
uint32 row = 0; row < transposedArray.shape_.rows; ++row)
3059 transposedArray.cend(row), comparitor);
3067 for (
uint32 row = 0; row < shape_.rows; ++row)
3090 return shape_.issquare();
3127 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3142 for (
uint32 row = 0; row < shape_.rows; ++row)
3153 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3156 transposedArray.
cend(row), comparitor);
3184 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3199 for (
uint32 row = 0; row < shape_.rows; ++row)
3210 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3213 transposedArray.
cend(row), comparitor);
3243 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3259 const uint32 middleIdx = size_ / 2;
3262 dtype medianValue = copyArray.array_[middleIdx];
3265 const uint32 lhsIndex = middleIdx - 1;
3267 medianValue = (medianValue + copyArray.array_[lhsIndex]) / dtype{2};
3270 return { medianValue };
3277 const bool isEven = shape_.cols % 2 == 0;
3278 for (
uint32 row = 0; row < shape_.rows; ++row)
3280 const uint32 middleIdx = shape_.cols / 2;
3282 copyArray.
end(row), comparitor);
3284 dtype medianValue = copyArray(row, middleIdx);
3287 const uint32 lhsIndex = middleIdx - 1;
3289 copyArray.
end(row), comparitor);
3290 medianValue = (medianValue + copyArray(row, lhsIndex)) / dtype{2};
3293 returnArray(0, row) = medianValue;
3303 const bool isEven = shape_.rows % 2 == 0;
3304 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3306 const uint32 middleIdx = transposedArray.shape_.
cols / 2;
3308 transposedArray.
end(row), comparitor);
3310 dtype medianValue = transposedArray(row, middleIdx);
3313 const uint32 lhsIndex = middleIdx - 1;
3315 transposedArray.
end(row), comparitor);
3316 medianValue = (medianValue + transposedArray(row, lhsIndex)) / dtype{2};
3319 returnArray(0, row) = medianValue;
3356 return static_cast<uint64>(
sizeof(dtype) * size_);
3381 switch (inEndianess)
3400 auto outArray =
NdArray(*
this);
3409 auto outArray =
NdArray(*
this);
3433 switch (inEndianess)
3448 auto outArray =
NdArray(*
this);
3476 switch (inEndianess)
3482 auto outArray =
NdArray(*
this);
3540 const auto function = [](dtype i) ->
bool
3542 return i != dtype{ 0 };
3555 for (
uint32 row = 0; row < shape_.rows; ++row)
3566 for (
uint32 row = 0; row < arrayTransposed.shape_.
rows; ++row)
3664 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3685 if (inKth >= shape_.cols)
3688 errStr +=
") out of bounds (" +
utils::num2str(shape_.cols) +
")";
3692 for (
uint32 row = 0; row < shape_.rows; ++row)
3700 if (inKth >= shape_.rows)
3703 errStr +=
") out of bounds (" +
utils::num2str(shape_.rows) +
")";
3708 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3711 transposedArray.
end(row), comparitor);
3752 dtype product = std::accumulate(cbegin(), cend(),
3753 dtype{ 1 }, std::multiplies<dtype>());
3760 for (
uint32 row = 0; row < shape_.rows; ++row)
3762 returnArray(0, row) = std::accumulate(cbegin(row), cend(row),
3763 dtype{ 1 }, std::multiplies<dtype>());
3772 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3774 returnArray(0, row) = std::accumulate(transposedArray.
cbegin(row), transposedArray.
cend(row),
3775 dtype{ 1 }, std::multiplies<dtype>());
3803 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3819 for (
uint32 row = 0; row < shape_.rows; ++row)
3822 returnArray(0, row) = *result.second - *result.first;
3831 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
3834 returnArray(0, row) = *result.second - *result.first;
3858 at(inIndex) = inValue;
3875 at(inRow, inCol) = inValue;
3891 for (
auto index : inIndices)
3893 put(index, inValue);
3910 if (inIndices.
size() != inValues.
size())
3916 for (
auto index : inIndices)
3918 put(index, inValues[counter++]);
3935 Slice inSliceCopy(inSlice);
3957 Slice inSliceCopy(inSlice);
3960 std::vector<uint32> indices;
3963 indices.push_back(i);
3981 Slice inRowSliceCopy(inRowSlice);
3982 Slice inColSliceCopy(inColSlice);
3987 std::vector<uint32> indices;
3988 for (
int32 row = inRowSliceCopy.
start; row < inRowSliceCopy.
stop; row += inRowSliceCopy.
step)
3990 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3992 put(row, col, inValue);
4011 Slice inRowSliceCopy(inRowSlice);
4014 std::vector<uint32> indices;
4015 for (
int32 row = inRowSliceCopy.
start; row < inRowSliceCopy.
stop; row += inRowSliceCopy.
step)
4017 put(row, inColIndex, inValue);
4035 Slice inColSliceCopy(inColSlice);
4038 std::vector<uint32> indices;
4039 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
4041 put(inRowIndex, col, inValue);
4059 Slice inRowSliceCopy(inRowSlice);
4060 Slice inColSliceCopy(inColSlice);
4065 std::vector<uint32> indices;
4066 for (
int32 row = inRowSliceCopy.
start; row < inRowSliceCopy.
stop; row += inRowSliceCopy.
step)
4068 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
4070 const uint32 index = row * shape_.cols + col;
4071 indices.push_back(index);
4090 Slice inRowSliceCopy(inRowSlice);
4093 std::vector<uint32> indices;
4094 for (
int32 row = inRowSliceCopy.
start; row < inRowSliceCopy.
stop; row += inRowSliceCopy.
step)
4096 const uint32 index = row * shape_.cols + inColIndex;
4097 indices.push_back(index);
4115 Slice inColSliceCopy(inColSlice);
4118 std::vector<uint32> indices;
4119 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
4121 const uint32 index = inRowIndex * shape_.cols + col;
4122 indices.push_back(index);
4137 if (inMask.
shape() != shape_)
4154 if (inMask.
shape() != shape_)
4189 NdArray<dtype> returnArray(shape_.rows * inNumRows, shape_.cols * inNumCols);
4191 for (
uint32 row = 0; row < inNumRows; ++row)
4193 for (
uint32 col = 0; col < inNumCols; ++col)
4195 std::vector<uint32> indices(shape_.size());
4197 const uint32 rowStart = row * shape_.rows;
4198 const uint32 colStart = col * shape_.cols;
4200 const uint32 rowEnd = (row + 1) * shape_.rows;
4201 const uint32 colEnd = (col + 1) * shape_.cols;
4204 for (
uint32 rowIdx = rowStart; rowIdx < rowEnd; ++rowIdx)
4206 for (
uint32 colIdx = colStart; colIdx < colEnd; ++colIdx)
4208 indices[counter++] = rowIdx * returnArray.shape_.
cols + colIdx;
4262 if (inSize != size_)
4264 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4270 shape_.cols = inSize;
4291 if (size_ % inNumCols == 0)
4293 return reshape(size_ / inNumCols, inNumCols);
4296 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4304 if (size_ % inNumRows == 0)
4306 return reshape(inNumRows, size_ / inNumRows);
4309 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4315 if (
static_cast<uint32>(inNumRows * inNumCols) != size_)
4317 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4322 shape_.rows =
static_cast<uint32>(inNumRows);
4323 shape_.cols =
static_cast<uint32>(inNumCols);
4357 newArray(
Shape(inNumRows, inNumCols));
4390 std::vector<dtype> oldData(size_);
4393 const Shape inShape(inNumRows, inNumCols);
4394 const Shape oldShape = shape_;
4398 for (
uint32 row = 0; row < inShape.
rows; ++row)
4400 for (
uint32 col = 0; col < inShape.
cols; ++col)
4402 if (row >= oldShape.
rows || col >= oldShape.
cols)
4404 operator()(row, col) = dtype{ 0 };
4408 operator()(row, col) = oldData[row * oldShape.
cols + col];
4450 const double multFactor =
utils::power(10.0, inNumDecimals);
4451 const auto function = [multFactor](dtype value) noexcept -> dtype
4453 return static_cast<dtype
>(std::nearbyint(
static_cast<double>(value) * multFactor) / multFactor);
4517 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
4531 for (
uint32 row = 0; row < shape_.rows; ++row)
4540 for (
uint32 row = 0; row < transposedArray.shape_.
rows; ++row)
4566 for (
uint32 row = 0; row < shape_.rows; ++row)
4569 for (
uint32 col = 0; col < shape_.cols; ++col)
4574 if (row == shape_.rows - 1)
4606 NdArray<dtype> returnArray = { std::accumulate(cbegin(), cend(), dtype{ 0 }) };
4612 for (
uint32 row = 0; row < shape_.rows; ++row)
4614 returnArray(0, row) = std::accumulate(cbegin(row), cend(row), dtype{ 0 });
4622 const Shape transShape = transposedArray.
shape();
4624 for (
uint32 row = 0; row < transShape.
rows; ++row)
4626 returnArray(0, row) = std::accumulate(transposedArray.
cbegin(row), transposedArray.
cend(row), dtype{ 0 });
4666 void tofile(
const std::string& inFilename,
const std::string& inSep =
"")
const
4682 std::ofstream ofile(
f.fullName().c_str());
4689 for (
auto value : *
this)
4692 if (counter++ != size_ - 1)
4737 if (numElements == 0)
4743 indices[0] = inSlice.
start;
4746 indices[i] =
static_cast<uint32>(indices[i - 1] + inSlice.
step);
4761 return std::vector<dtype>(cbegin(), cend());
4786 rowStart += inOffset;
4791 colStart += inOffset;
4802 if (rowStart >= shape_.rows || colStart >= shape_.cols)
4809 for (
uint32 row = rowStart; row < shape_.rows; ++row)
4811 if (col >= shape_.cols)
4815 sum += operator()(row, col++);
4833 for (
uint32 row = 0; row < shape_.rows; ++row)
4835 for (
uint32 col = 0; col < shape_.cols; ++col)
4837 transArray(col, row) = operator()(row, col);
4858 allocator_type allocator_{};
4859 Shape shape_{ 0, 0 };
4860 size_type size_{ 0 };
4862 pointer array_{
nullptr };
4863 bool ownsPtr_{
false };
4869 void deleteArray() noexcept
4871 if (ownsPtr_ && array_ !=
nullptr)
4873 allocator_.deallocate(array_, size_);
4877 shape_.rows = shape_.cols = 0;
4891 array_ = allocator_.allocate(size_);
4903 void newArray(
const Shape& inShape)
4908 size_ = inShape.size();
4915 template<
typename dtype,
class _Alloc>
4920 std::vector<uint32> rowIndices;
4921 std::vector<uint32> colIndices;
4923 for (
uint32 row = 0; row < shape_.rows; ++row)
4925 for (
uint32 col = 0; col < shape_.cols; ++col)
4927 if (
operator()(row, col) != dtype{ 0 })
4929 rowIndices.push_back(row);
4930 colIndices.push_back(col);
#define THROW_RUNTIME_ERROR(msg)
Definition: Error.hpp:37
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:43
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:50
#define STATIC_ASSERT_INTEGER(dtype)
Definition: StaticAsserts.hpp:40
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
Custom column iterator for NdArray.
Definition: NdArrayIterators.hpp:834
Custom column const_iterator for NdArray.
Definition: NdArrayIterators.hpp:503
Custom const_iterator for NdArray.
Definition: NdArrayIterators.hpp:44
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
uint32 numCols() const noexcept
Definition: NdArrayCore.hpp:3602
NdArray(std::vector< std::array< dtype, Dim1Size >> &in2dArray, bool copy=true)
Definition: NdArrayCore.hpp:326
const_reverse_column_iterator rcolbegin() const noexcept
Definition: NdArrayCore.hpp:1502
NdArray< dtype > at(const NdArray< int32 > &rowIndices, const NdArray< int32 > &colIndices) const
Definition: NdArrayCore.hpp:1201
NdArray< dtypeOut > astype() const
Definition: NdArrayCore.hpp:2225
NdArray< dtype > & put(int32 inIndex, value_type inValue)
Definition: NdArrayCore.hpp:3856
size_type size() const noexcept
Definition: NdArrayCore.hpp:4497
reverse_iterator rbegin() noexcept
Definition: NdArrayCore.hpp:1386
NdArray< dtype > & resizeSlow(uint32 inNumRows, uint32 inNumCols)
Definition: NdArrayCore.hpp:4388
NdArray< dtype > & put(const Slice &inRowSlice, const Slice &inColSlice, value_type inValue)
Definition: NdArrayCore.hpp:3979
NdArray< bool > issorted(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3037
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1270
NdArray< dtype > operator[](const Indices &inIndices) const
Definition: NdArrayCore.hpp:784
const_reference at(int32 inIndex) const
Definition: NdArrayCore.hpp:1050
const_column_iterator ccolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1370
NdArrayConstColumnIterator< dtype, size_type, const_pointer, difference_type > const_column_iterator
Definition: NdArrayCore.hpp:96
NdArray< dtype > round(uint8 inNumDecimals=0) const
Definition: NdArrayCore.hpp:4445
NdArray< bool > any(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1963
const_pointer data() const noexcept
Definition: NdArrayCore.hpp:2689
NdArray< uint32 > toIndices(Slice inSlice, Axis inAxis=Axis::ROW) const
Definition: NdArrayCore.hpp:4710
NdArray< dtype > at(const Slice &inRowSlice, int32 inColIndex) const
Definition: NdArrayCore.hpp:1169
iterator end() noexcept
Definition: NdArrayCore.hpp:1558
NdArray< dtype > operator()(Slice inRowSlice, int32 inColIndex) const
Definition: NdArrayCore.hpp:840
NdArray< dtype > & put(const Slice &inRowSlice, const Slice &inColSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:4057
NdArray(std::vector< dtype > &inVector, bool copy=true)
Definition: NdArrayCore.hpp:266
NdArray(const std::initializer_list< std::initializer_list< dtype > > &inList)
Definition: NdArrayCore.hpp:173
NdArray< dtype > prod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3744
NdArray< dtype > copy() const
Definition: NdArrayCore.hpp:2541
NdArray< dtype > & resizeFast(const Shape &inShape)
Definition: NdArrayCore.hpp:4371
std::vector< dtype > toStlVector() const
Definition: NdArrayCore.hpp:4759
reference back(size_type row)
Definition: NdArrayCore.hpp:2380
iterator end(size_type inRow)
Definition: NdArrayCore.hpp:1572
NdArray< dtype > flatten() const
Definition: NdArrayCore.hpp:2919
const_column_iterator ccolbegin() const noexcept
Definition: NdArrayCore.hpp:1356
typename AllocTraits::pointer pointer
Definition: NdArrayCore.hpp:83
Slice cSlice(int32 inStartIdx=0, uint32 inStepSize=1) const noexcept
Definition: NdArrayCore.hpp:998
reverse_iterator rbegin(size_type inRow)
Definition: NdArrayCore.hpp:1400
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4483
NdArray< dtype > & byteswap() noexcept
Definition: NdArrayCore.hpp:2394
const_reverse_column_iterator rcolend() const noexcept
Definition: NdArrayCore.hpp:1846
uint32 numRows() const noexcept
Definition: NdArrayCore.hpp:3615
const dtype & const_reference
Definition: NdArrayCore.hpp:86
NdArray< dtype > & put(const Slice &inRowSlice, int32 inColIndex, value_type inValue)
Definition: NdArrayCore.hpp:4009
NdArray< dtype > & partition(uint32 inKth, Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:3660
bool issquare() const noexcept
Definition: NdArrayCore.hpp:3088
NdArrayIterator< dtype, pointer, difference_type > iterator
Definition: NdArrayCore.hpp:90
bool isflat() const noexcept
Definition: NdArrayCore.hpp:3025
Endian endianess() const noexcept
Definition: NdArrayCore.hpp:2860
const_reverse_column_iterator crcolbegin() const noexcept
Definition: NdArrayCore.hpp:1528
const_reverse_column_iterator crcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1886
column_iterator colbegin(size_type inCol)
Definition: NdArrayCore.hpp:1314
NdArrayColumnIterator< dtype, size_type, pointer, difference_type > column_iterator
Definition: NdArrayCore.hpp:95
NdArray< bool > none(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3536
NdArray< dtype > at(const Slice &inSlice) const
Definition: NdArrayCore.hpp:1137
reference at(int32 inIndex)
Definition: NdArrayCore.hpp:1027
NdArray< dtype > & sort(Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:4513
pointer data() noexcept
Definition: NdArrayCore.hpp:2679
bool isempty() const noexcept
Definition: NdArrayCore.hpp:3012
column_iterator colbegin() noexcept
Definition: NdArrayCore.hpp:1300
const_reference front(size_type row) const
Definition: NdArrayCore.hpp:2957
reverse_column_iterator rcolend(size_type inCol)
Definition: NdArrayCore.hpp:1830
NdArray< dtype > sum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:4598
NdArray(Iterator inFirst, Iterator inLast)
Definition: NdArrayCore.hpp:423
NdArray< dtype > operator[](const Slice &inSlice) const
Definition: NdArrayCore.hpp:732
reverse_column_iterator rcolbegin() noexcept
Definition: NdArrayCore.hpp:1472
NdArrayConstIterator< dtype, const_pointer, difference_type > const_iterator
Definition: NdArrayCore.hpp:91
const_iterator cbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1284
const_column_iterator ccolend(size_type inCol) const
Definition: NdArrayCore.hpp:1800
NdArray< dtype > cumsum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2621
NdArray< dtype > median(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3239
NdArray< dtype > getByMask(const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:2999
const_iterator cend(size_type inRow) const
Definition: NdArrayCore.hpp:1628
NdArray< dtype > column(uint32 inColumn)
Definition: NdArrayCore.hpp:2478
const_reverse_column_iterator rcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1860
NdArray< dtype > & putMask(const NdArray< bool > &inMask, value_type inValue)
Definition: NdArrayCore.hpp:4135
const_iterator end(size_type inRow) const
Definition: NdArrayCore.hpp:1602
reference back() noexcept
Definition: NdArrayCore.hpp:2356
const_reverse_column_iterator crcolend() const noexcept
Definition: NdArrayCore.hpp:1872
const_reference back(size_type row) const
Definition: NdArrayCore.hpp:2368
reverse_column_iterator rcolbegin(size_type inCol)
Definition: NdArrayCore.hpp:1486
NdArray(const std::deque< std::deque< dtype >> &in2dDeque)
Definition: NdArrayCore.hpp:370
NdArray< dtype > & put(int32 inRow, int32 inCol, value_type inValue)
Definition: NdArrayCore.hpp:3873
iterator begin(size_type inRow)
Definition: NdArrayCore.hpp:1228
const_reverse_iterator rend() const noexcept
Definition: NdArrayCore.hpp:1674
NdArray< dtype > clip(value_type inMin, value_type inMax) const
Definition: NdArrayCore.hpp:2438
const_reverse_column_iterator rcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1516
NdArray< dtype > & operator=(NdArray< dtype > &&rhs) noexcept
Definition: NdArrayCore.hpp:617
typename AllocTraits::difference_type difference_type
Definition: NdArrayCore.hpp:88
NdArray< uint32 > argmin(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2080
const_iterator end() const noexcept
Definition: NdArrayCore.hpp:1588
bool ownsInternalData() noexcept
Definition: NdArrayCore.hpp:3639
NdArray< dtype > & fill(value_type inFillValue) noexcept
Definition: NdArrayCore.hpp:2878
column_iterator colend() noexcept
Definition: NdArrayCore.hpp:1730
NdArray< dtype > operator()(Slice inRowSlice, Slice inColSlice) const
Definition: NdArrayCore.hpp:811
NdArray< dtype > & put(const NdArray< uint32 > &inIndices, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3908
const_reference back() const noexcept
Definition: NdArrayCore.hpp:2344
NdArray< dtype > operator()(int32 inRowIndex, Slice inColSlice) const
Definition: NdArrayCore.hpp:863
std::pair< NdArray< uint32 >, NdArray< uint32 > > nonzero() const
Definition: NdArrayCore.hpp:4916
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: NdArrayCore.hpp:93
NdArray(const_pointer inPtr, UIntType1 numRows, UIntType2 numCols)
Definition: NdArrayCore.hpp:465
NdArray< dtype > cumprod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2557
uint64 nbytes() const noexcept
Definition: NdArrayCore.hpp:3354
const_reference at(int32 inRowIndex, int32 inColIndex) const
Definition: NdArrayCore.hpp:1105
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4830
NdArray< dtype > swapaxes() const
Definition: NdArrayCore.hpp:4648
NdArray< dtype > & put(int32 inRowIndex, const Slice &inColSlice, value_type inValue)
Definition: NdArrayCore.hpp:4033
NdArray(const std::list< dtype > &inList)
Definition: NdArrayCore.hpp:403
NdArray< dtype > at(int32 inRowIndex, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1185
const_reference front() const noexcept
Definition: NdArrayCore.hpp:2933
NdArray< dtype > repeat(const Shape &inRepeatShape) const
Definition: NdArrayCore.hpp:4230
~NdArray() noexcept
Definition: NdArrayCore.hpp:558
NdArray< dtype > min(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3180
NdArray(pointer inPtr, uint32 numRows, uint32 numCols, Bool takeOwnership) noexcept
Definition: NdArrayCore.hpp:508
NdArray< dtype > & reshape(const Shape &inShape)
Definition: NdArrayCore.hpp:4340
reference front() noexcept
Definition: NdArrayCore.hpp:2945
NdArray(size_type inNumRows, size_type inNumCols)
Definition: NdArrayCore.hpp:127
Allocator allocator_type
Definition: NdArrayCore.hpp:82
void print() const
Definition: NdArrayCore.hpp:3726
const_reverse_column_iterator crcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1542
reverse_iterator rend(size_type inRow)
Definition: NdArrayCore.hpp:1658
NdArray< uint32 > flatnonzero() const
Definition: NdArrayCore.hpp:2892
NdArray(size_type inSquareSize)
Definition: NdArrayCore.hpp:113
NdArray< dtype > operator()(int32 rowIndex, const Indices &colIndices) const
Definition: NdArrayCore.hpp:923
reverse_iterator rend() noexcept
Definition: NdArrayCore.hpp:1644
const_reverse_iterator rend(size_type inRow) const
Definition: NdArrayCore.hpp:1688
NdArray< dtype > getByIndices(const NdArray< uint32 > &inIndices) const
Definition: NdArrayCore.hpp:2983
typename AllocTraits::const_pointer const_pointer
Definition: NdArrayCore.hpp:84
NdArray< dtype > & resizeSlow(const Shape &inShape)
Definition: NdArrayCore.hpp:4428
const_reverse_iterator crbegin() const noexcept
Definition: NdArrayCore.hpp:1442
const_column_iterator colend(size_type inCol) const
Definition: NdArrayCore.hpp:1774
std::reverse_iterator< iterator > reverse_iterator
Definition: NdArrayCore.hpp:92
NdArray(const std::initializer_list< dtype > &inList)
Definition: NdArrayCore.hpp:155
NdArray< dtype > operator()(const Indices &rowIndices, Slice colSlice) const
Definition: NdArrayCore.hpp:906
NdArray(const std::vector< std::vector< dtype >> &in2dVector)
Definition: NdArrayCore.hpp:291
const_reverse_iterator rbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1430
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1614
std::string str() const
Definition: NdArrayCore.hpp:4560
std::reverse_iterator< const_column_iterator > const_reverse_column_iterator
Definition: NdArrayCore.hpp:98
reference operator[](int32 inIndex) noexcept
Definition: NdArrayCore.hpp:645
NdArray< dtype > & reshape(int32 inNumRows, int32 inNumCols)
Definition: NdArrayCore.hpp:4287
NdArray(NdArray< dtype > &&inOtherArray) noexcept
Definition: NdArrayCore.hpp:541
NdArray< dtype > & nans() noexcept
Definition: NdArrayCore.hpp:3337
NdArray< dtype > & put(const NdArray< uint32 > &inIndices, value_type inValue)
Definition: NdArrayCore.hpp:3889
NdArray< dtype > ptp(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3799
const_reference operator()(int32 inRowIndex, int32 inColIndex) const noexcept
Definition: NdArrayCore.hpp:707
reference front(size_type row)
Definition: NdArrayCore.hpp:2969
NdArray< dtype > diagonal(int32 inOffset=0, Axis inAxis=Axis::ROW) const
Definition: NdArrayCore.hpp:2718
NdArray< dtype > & putMask(const NdArray< bool > &inMask, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:4152
NdArray< dtype > operator[](const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:755
NdArray< dtype > row(uint32 inRow)
Definition: NdArrayCore.hpp:4469
NdArray< dtype > operator()(const Indices &rowIndices, int32 colIndex) const
Definition: NdArrayCore.hpp:888
const_iterator begin(size_type inRow) const
Definition: NdArrayCore.hpp:1258
iterator begin() noexcept
Definition: NdArrayCore.hpp:1214
NdArray< dtype > & put(const Slice &inSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3955
const_column_iterator colbegin() const noexcept
Definition: NdArrayCore.hpp:1330
NdArray< dtype > max(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3123
std::reverse_iterator< column_iterator > reverse_column_iterator
Definition: NdArrayCore.hpp:97
NdArray< dtype > & operator=(const NdArray< dtype > &rhs)
Definition: NdArrayCore.hpp:572
value_type item() const
Definition: NdArrayCore.hpp:3102
reference operator()(int32 inRowIndex, int32 inColIndex) noexcept
Definition: NdArrayCore.hpp:683
const_column_iterator colend() const noexcept
Definition: NdArrayCore.hpp:1760
NdArray< dtype > & resizeFast(uint32 inNumRows, uint32 inNumCols)
Definition: NdArrayCore.hpp:4355
const_reverse_iterator crend() const noexcept
Definition: NdArrayCore.hpp:1700
NdArray< dtype > & ones() noexcept
Definition: NdArrayCore.hpp:3625
NdArray< dtype > operator()(RowIndices rowIndices, ColIndices colIndices) const
Definition: NdArrayCore.hpp:959
NdArray< dtype > & zeros() noexcept
Definition: NdArrayCore.hpp:4848
const_column_iterator colbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1344
NdArray< dtype > dot(const NdArray< dtype > &inOtherArray) const
Definition: NdArrayCore.hpp:2788
NdArray< dtype > repeat(uint32 inNumRows, uint32 inNumCols) const
Definition: NdArrayCore.hpp:4187
NdArray< dtype > & reshape(size_type inSize)
Definition: NdArrayCore.hpp:4260
NdArray< bool > contains(value_type inValue, Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2492
const_column_iterator ccolend() const noexcept
Definition: NdArrayCore.hpp:1786
NdArray< uint32 > argmax(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2020
value_type trace(uint32 inOffset=0, Axis inAxis=Axis::ROW) const noexcept
Definition: NdArrayCore.hpp:4776
reverse_column_iterator rcolend() noexcept
Definition: NdArrayCore.hpp:1816
NdArray(std::array< dtype, ArraySize > &inArray, bool copy=true)
Definition: NdArrayCore.hpp:209
NdArray< dtype > & put(int32 inRowIndex, const Slice &inColSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:4113
const_reverse_iterator rbegin() const noexcept
Definition: NdArrayCore.hpp:1416
NdArray(const_pointer inPtr, size_type size)
Definition: NdArrayCore.hpp:442
NdArray(const std::deque< dtype > &inDeque)
Definition: NdArrayCore.hpp:353
NdArray(std::array< std::array< dtype, Dim1Size >, Dim0Size > &in2dArray, bool copy=true)
Definition: NdArrayCore.hpp:237
void dump(const std::string &inFilename) const
Definition: NdArrayCore.hpp:2832
dtype & reference
Definition: NdArrayCore.hpp:85
pointer dataRelease() noexcept
Definition: NdArrayCore.hpp:2701
reference at(int32 inRowIndex, int32 inColIndex)
Definition: NdArrayCore.hpp:1073
NdArray< dtype > at(const Slice &inRowSlice, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1153
NdArray< dtype > operator()(Slice rowSlice, const Indices &colIndices) const
Definition: NdArrayCore.hpp:941
NdArray(const NdArray< dtype > &inOtherArray)
Definition: NdArrayCore.hpp:522
NdArray< uint32 > argsort(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2139
uint32 size_type
Definition: NdArrayCore.hpp:87
const_iterator begin() const noexcept
Definition: NdArrayCore.hpp:1244
NdArray< dtype > & operator=(value_type inValue) noexcept
Definition: NdArrayCore.hpp:598
NdArray< dtype > newbyteorder(Endian inEndianess) const
Definition: NdArrayCore.hpp:3371
column_iterator colend(size_type inCol)
Definition: NdArrayCore.hpp:1744
NdArray< dtype > & put(const Slice &inSlice, value_type inValue)
Definition: NdArrayCore.hpp:3933
void tofile(const std::string &inFilename, const std::string &inSep="") const
Definition: NdArrayCore.hpp:4666
const_reference operator[](int32 inIndex) const noexcept
Definition: NdArrayCore.hpp:664
NdArray< dtype > & ravel() noexcept
Definition: NdArrayCore.hpp:4170
dtype value_type
Definition: NdArrayCore.hpp:81
NdArray(pointer inPtr, size_type size, Bool takeOwnership) noexcept
Definition: NdArrayCore.hpp:488
void replace(value_type oldValue, value_type newValue)
Definition: NdArrayCore.hpp:4242
NdArray< dtype > & put(const Slice &inRowSlice, int32 inColIndex, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:4088
Slice rSlice(int32 inStartIdx=0, uint32 inStepSize=1) const noexcept
Definition: NdArrayCore.hpp:1013
const_reverse_iterator crend(size_type inRow) const
Definition: NdArrayCore.hpp:1714
const_reverse_iterator crbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1456
NdArray(const Shape &inShape)
Definition: NdArrayCore.hpp:141
NdArray< bool > all(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1907
Custom iterator for NdArray.
Definition: NdArrayIterators.hpp:324
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:102
A Class for slicing into NdArrays.
Definition: Slice.hpp:44
int32 step
Definition: Slice.hpp:49
int32 start
Definition: Slice.hpp:47
void makePositiveAndValidate(uint32 inArraySize)
Definition: Slice.hpp:137
uint32 numElements(uint32 inArraySize)
Definition: Slice.hpp:188
int32 stop
Definition: Slice.hpp:48
Provides simple filesystem functions.
Definition: Filesystem.hpp:40
constexpr auto j
Definition: Constants.hpp:45
const double nan
NaN.
Definition: Constants.hpp:44
bool isLittleEndian() noexcept
Definition: Endian.hpp:44
dtype byteSwap(dtype value) noexcept
Definition: Endian.hpp:63
dtype f(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:629
bool none_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:379
ForwardIt max_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:268
void stable_sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:664
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:702
bool all_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:57
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:213
InputIt find(InputIt first, InputIt last, const T &value) noexcept
Definition: StlAlgorithms.hpp:195
constexpr OutputIt unique_copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:744
std::pair< ForwardIt, ForwardIt > minmax_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:341
void replace(ForwardIt first, ForwardIt last, const T &oldValue, const T &newValue) noexcept
Definition: StlAlgorithms.hpp:435
bool is_sorted(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:231
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:95
void nth_element(RandomIt first, RandomIt nth, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:397
ForwardIt min_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:304
void fill(ForwardIt first, ForwardIt last, const T &value) noexcept
Definition: StlAlgorithms.hpp:174
std::string num2str(dtype inNumber)
Definition: num2str.hpp:46
dtype power(dtype inValue, uint8 inPower) noexcept
Definition: Utils/power.hpp:48
std::string value2str(dtype inValue)
Definition: value2str.hpp:48
Definition: Coordinate.hpp:45
NdArray< dtype > repeat(const NdArray< dtype > &inArray, uint32 inNumRows, uint32 inNumCols)
Definition: repeat.hpp:50
std::pair< NdArray< uint32 >, NdArray< uint32 > > nonzero(const NdArray< dtype > &inArray)
Definition: nonzero.hpp:50
NdArray< dtype > & resizeFast(NdArray< dtype > &inArray, uint32 inNumRows, uint32 inNumCols)
Definition: resizeFast.hpp:51
Axis
Enum To describe an axis.
Definition: Types.hpp:46
NdArray< dtype > & reshape(NdArray< dtype > &inArray, uint32 inSize)
Definition: reshape.hpp:52
std::int64_t int64
Definition: Types.hpp:35
auto abs(dtype inValue) noexcept
Definition: abs.hpp:51
std::uint64_t uint64
Definition: Types.hpp:39
NdArray< dtype > & resizeSlow(NdArray< dtype > &inArray, uint32 inNumRows, uint32 inNumCols)
Definition: resizeSlow.hpp:53
Endian
Enum for endianess.
Definition: Types.hpp:50
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:47
NdArray< dtype > & put(NdArray< dtype > &inArray, const NdArray< uint32 > &inIndices, dtype inValue)
Definition: put.hpp:49
NdArray< dtype > transpose(const NdArray< dtype > &inArray)
Definition: transpose.hpp:47
typename std::enable_if< B, T >::type enable_if_t
Definition: TypeTraits.hpp:40
std::uint32_t uint32
Definition: Types.hpp:40
void dump(const NdArray< dtype > &inArray, const std::string &inFilename)
Definition: dump.hpp:47