 |
NumCpp
1.0
A C++ implementation of the Python Numpy library
|
Go to the documentation of this file.
48 #include <boost/algorithm/clamp.hpp>
49 #include <boost/endian/conversion.hpp>
50 #include <boost/predef/other/endian.h>
55 #include <forward_list>
57 #include <initializer_list>
65 #include <type_traits>
74 template<
typename dtype,
class Allocator = std::allocator<dtype>>
78 STATIC_ASSERT_VALID_DTYPE(dtype);
79 static_assert(is_same_v<dtype, typename Allocator::value_type>,
"value_type and Allocator::value_type must match");
81 using AllocType =
typename std::allocator_traits<Allocator>::template rebind_alloc<dtype>;
82 using AllocTraits = std::allocator_traits<AllocType>;
87 using pointer =
typename AllocTraits::pointer;
118 shape_(inSquareSize, inSquareSize),
119 size_(inSquareSize * inSquareSize)
132 shape_(inNumRows, inNumCols),
133 size_(inNumRows * inNumCols)
159 NdArray(
const std::initializer_list<dtype>& inList) :
160 shape_(1, static_cast<
uint32>(inList.
size())),
177 NdArray(
const std::initializer_list<std::initializer_list<dtype> >& inList) :
180 for (
const auto& list : inList)
182 if (shape_.
cols == 0)
184 shape_.
cols =
static_cast<uint32>(list.size());
186 else if (list.size() != shape_.
cols)
192 size_ = shape_.
size();
195 for (
const auto& list : inList)
211 template<
size_t ArraySize,
212 std::enable_if_t<is_valid_dtype_v<dtype>,
int> = 0>
213 NdArray(std::array<dtype, ArraySize>& inArray,
bool copy =
true) :
214 shape_(1, static_cast<
uint32>(ArraySize)),
227 array_ = inArray.data();
240 template<
size_t Dim0Size,
size_t Dim1Size>
241 NdArray(std::array<std::array<dtype, Dim1Size>, Dim0Size>& in2dArray,
bool copy =
true) :
242 shape_(static_cast<
uint32>(Dim0Size), static_cast<
uint32>(Dim1Size)),
250 const auto start = in2dArray.front().begin();
256 array_ = in2dArray.front().data();
269 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
271 shape_(1, static_cast<
uint32>(inVector.
size())),
284 array_ = inVector.data();
295 explicit NdArray(
const std::vector<std::vector<dtype>>& in2dVector) :
296 shape_(static_cast<
uint32>(in2dVector.
size()), 0)
298 for (
const auto&
row : in2dVector)
300 if (shape_.
cols == 0)
310 size_ = shape_.
size();
313 auto currentPosition =
begin();
314 for (
const auto&
row : in2dVector)
317 currentPosition += shape_.
cols;
329 template<
size_t Dim1Size>
330 NdArray(std::vector<std::array<dtype, Dim1Size>>& in2dArray,
bool copy =
true) :
331 shape_(static_cast<
uint32>(in2dArray.
size()), static_cast<
uint32>(Dim1Size)),
339 const auto start = in2dArray.front().begin();
345 array_ = in2dArray.front().data();
356 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
358 shape_(1, static_cast<
uint32>(inDeque.
size())),
374 explicit NdArray(
const std::deque<std::deque<dtype>>& in2dDeque) :
375 shape_(static_cast<
uint32>(in2dDeque.
size()), 0)
377 for (
const auto&
row : in2dDeque)
379 if (shape_.
cols == 0)
389 size_ = shape_.
size();
392 auto currentPosition =
begin();
393 for (
const auto&
row : in2dDeque)
396 currentPosition += shape_.
cols;
407 explicit NdArray(
const std::list<dtype>& inList) :
408 shape_(1, static_cast<
uint32>(inList.
size())),
425 template<
typename Iterator,
426 std::enable_if_t<std::is_same<typename std::iterator_traits<Iterator>::value_type, dtype>::value,
int> = 0>
428 shape_(1, static_cast<
uint32>(std::distance(inFirst, inLast))),
451 if (inPtr !=
nullptr && size_ > 0)
471 if (inPtr !=
nullptr && size_ > 0)
487 template<
typename Bool,
488 std::enable_if_t<std::is_same<Bool, bool>::value,
int> = 0>
493 ownsPtr_(takeOwnership)
507 template<
typename Bool,
508 std::enable_if_t<std::is_same<Bool, bool>::value,
int> = 0>
513 ownsPtr_(takeOwnership)
524 shape_(inOtherArray.shape_),
525 size_(inOtherArray.size_),
526 endianess_(inOtherArray.endianess_)
543 shape_(inOtherArray.shape_),
544 size_(inOtherArray.size_),
545 endianess_(inOtherArray.endianess_),
546 array_(inOtherArray.array_),
547 ownsPtr_(inOtherArray.ownsPtr_)
549 inOtherArray.shape_.rows = inOtherArray.shape_.cols = 0;
550 inOtherArray.size_ = 0;
551 inOtherArray.ownsPtr_ =
false;
552 inOtherArray.array_ =
nullptr;
579 newArray(rhs.shape_);
580 endianess_ = rhs.endianess_;
601 if (array_ !=
nullptr)
625 endianess_ = rhs.endianess_;
627 ownsPtr_ = rhs.ownsPtr_;
629 rhs.shape_.rows = rhs.shape_.cols = rhs.size_ = 0;
630 rhs.array_ =
nullptr;
631 rhs.ownsPtr_ =
false;
653 return array_[inIndex];
672 return array_[inIndex];
688 inRowIndex += shape_.
rows;
693 inColIndex += shape_.
cols;
696 return array_[inRowIndex * shape_.
cols + inColIndex];
712 inRowIndex += shape_.
rows;
717 inColIndex += shape_.
cols;
720 return array_[inRowIndex * shape_.
cols + inColIndex];
735 Slice inSliceCopy(inSlice);
741 returnArray[counter++] =
at(i);
758 if (inMask.
shape() != shape_)
765 for (
size_type i = 0; i < indices.size(); ++i)
784 if (inIndices.
max().item() > size_ - 1)
791 for (
auto& index : inIndices)
811 Slice inRowSliceCopy(inRowSlice);
812 Slice inColSliceCopy(inColSlice);
820 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
822 returnArray(rowCounter, colCounter++) =
at(
row, col);
843 Slice inRowSliceCopy(inRowSlice);
850 returnArray(rowCounter++, 0) =
at(
row, inColIndex);
868 Slice inColSliceCopy(inColSlice);
873 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
875 returnArray(0, colCounter++) =
at(inRowIndex, col);
893 return Slice(inStartIdx, shape_.
cols, inStepSize);
908 return Slice(inStartIdx, shape_.
rows, inStepSize);
927 errStr +=
" is out of bounds for array of size " +
utils::num2str(size_) +
".";
950 errStr +=
" is out of bounds for array of size " +
utils::num2str(size_) +
".";
981 std::string errStr =
"Column index " +
utils::num2str(inColIndex);
1005 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
rows) +
".";
1013 std::string errStr =
"Column index " +
utils::num2str(inColIndex);
1014 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
cols) +
".";
1107 if (inRow >= shape_.
rows)
1112 return begin() += (inRow * shape_.
cols);
1163 if (inRow >= shape_.
rows)
1193 if (inCol >= shape_.
cols)
1249 if (inCol >= shape_.
cols)
1279 if (inRow >= shape_.
rows)
1335 if (inRow >= shape_.
rows)
1365 if (inCol >= shape_.
cols)
1421 if (inCol >= shape_.
cols)
1437 return begin() += size_;
1451 if (inRow >= shape_.
rows)
1493 return cbegin() += size_;
1507 if (inRow >= shape_.
rows)
1523 return rbegin() += size_;
1537 if (inRow >= shape_.
rows)
1567 return crend(inRow);
1593 if (inRow >= shape_.
rows)
1623 if (inCol >= shape_.
cols)
1679 if (inCol >= shape_.
cols)
1709 if (inCol >= shape_.
cols)
1765 if (inCol >= shape_.
cols)
1788 const auto function = [](dtype i) ->
bool
1790 return i != dtype{ 0 };
1843 const auto function = [](dtype i) ->
bool
1845 return i != dtype{ 0 };
1899 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
1958 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
2020 std::vector<uint32> idx(size_);
2021 std::iota(idx.begin(), idx.end(), 0);
2023 const auto function = [
this](
uint32 i1,
uint32 i2) noexcept ->
bool
2025 return (*
this)[i1] < (*this)[i2];
2036 std::vector<uint32> idx(shape_.
cols);
2037 std::iota(idx.begin(), idx.end(), 0);
2039 const auto function = [
this,
row](
uint32 i1,
uint32 i2) noexcept ->
bool
2046 for (
uint32 col = 0; col < shape_.
cols; ++col)
2048 returnArray(
row, col) = idx[col];
2059 std::vector<uint32> idx(arrayTransposed.shape_.
cols);
2060 std::iota(idx.begin(), idx.end(), 0);
2062 const auto function = [&arrayTransposed,
row](
uint32 i1,
uint32 i2) noexcept ->
bool
2064 return arrayTransposed(
row, i1) < arrayTransposed(
row, i2);
2069 for (
uint32 col = 0; col < arrayTransposed.shape_.
cols; ++col)
2071 returnArray(
row, col) = idx[col];
2093 template<
typename dtypeOut,
typename dtype_ = dtype,
2101 if (std::is_same<dtypeOut, dtype>::value)
2107 const auto function = [](dtype value) -> dtypeOut
2109 return static_cast<dtypeOut
>(value);
2128 template<
typename dtypeOut,
typename dtype_ = dtype,
2138 return std::complex<typename dtypeOut::value_type>(value);
2156 template<
typename dtypeOut,
typename dtype_ = dtype,
2164 if (std::is_same<dtypeOut, dtype>::value)
2172 return complex_cast<typename dtypeOut::value_type>(value);
2191 template<
typename dtypeOut,
typename dtype_ = dtype,
2201 return static_cast<dtypeOut
>(value.real());
2218 return *(
cend() - 1);
2230 return *(
end() - 1);
2284 #if BOOST_ENDIAN_BIG_BYTE
2286 #elif BOOST_ENDIAN_LITTLE_BYTE
2312 boost::algorithm::clamp_range(
cbegin(),
cend(), outArray.
begin(), inMin, inMax,
2313 [](dtype lhs, dtype rhs) noexcept ->
bool
2416 returnArray[0] =
front();
2417 for (
uint32 i = 1; i < size_; ++i)
2419 returnArray[i] = returnArray[i - 1] * array_[i];
2430 for (
uint32 col = 1; col < shape_.
cols; ++col)
2441 for (
uint32 col = 0; col < shape_.
cols; ++col)
2479 returnArray[0] =
front();
2480 for (
uint32 i = 1; i < size_; ++i)
2482 returnArray[i] = returnArray[i - 1] + array_[i];
2493 for (
uint32 col = 1; col < shape_.
cols; ++col)
2504 for (
uint32 col = 0; col < shape_.
cols; ++col)
2572 std::vector<dtype> diagnolValues;
2573 int32 col = inOffset;
2581 else if (col >=
static_cast<int32>(shape_.
cols))
2586 diagnolValues.push_back(
operator()(
row,
static_cast<uint32>(col)));
2594 std::vector<dtype> diagnolValues;
2596 for (
int32 row = inOffset; row < static_cast<int32>(shape_.
rows); ++
row)
2603 else if (col >= shape_.
cols)
2608 diagnolValues.push_back(
operator()(
static_cast<uint32>(
row), col));
2639 if (shape_ == inOtherArray.shape_ && (shape_.
rows == 1 || shape_.
cols == 1))
2641 dtype dotProduct = std::inner_product(
cbegin(),
cend(), inOtherArray.
cbegin(), dtype{ 0 });
2645 else if (shape_.
cols == inOtherArray.shape_.
rows)
2649 auto otherArrayT = inOtherArray.
transpose();
2653 for (
uint32 j = 0;
j < otherArrayT.shape_.rows; ++
j)
2655 returnArray(i,
j) = std::inner_product(otherArrayT.cbegin(
j), otherArrayT.cend(
j),
cbegin(i), dtype{ 0 });
2665 errStr +=
" are not consistent.";
2681 void dump(
const std::string& inFilename)
const
2689 std::ofstream ofile(
f.fullName().c_str(), std::ios::binary);
2695 if (array_ !=
nullptr)
2697 ofile.write(
reinterpret_cast<const char*
>(array_), size_ *
sizeof(dtype));
2745 std::vector<uint32> indices;
2747 for (
auto value : *
this)
2749 if (value != dtype{ 0 })
2751 indices.push_back(idx);
2876 return shape_.
rows == 1 || shape_.
cols == 1;
2890 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
2908 transposedArray.cend(
row), comparitor);
2975 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3004 transposedArray.
cend(
row), comparitor);
3031 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3060 transposedArray.
cend(
row), comparitor);
3089 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3105 const uint32 middleIdx = size_ / 2;
3108 dtype medianValue = copyArray.array_[middleIdx];
3111 const uint32 lhsIndex = middleIdx - 1;
3113 medianValue = (medianValue + copyArray.array_[lhsIndex]) / dtype{2};
3116 return { medianValue };
3123 const bool isEven = shape_.
cols % 2 == 0;
3128 copyArray.
end(
row), comparitor);
3130 dtype medianValue = copyArray(
row, middleIdx);
3133 const uint32 lhsIndex = middleIdx - 1;
3135 copyArray.
end(
row), comparitor);
3136 medianValue = (medianValue + copyArray(
row, lhsIndex)) / dtype{2};
3139 returnArray(0,
row) = medianValue;
3149 const bool isEven = shape_.
rows % 2 == 0;
3152 const uint32 middleIdx = transposedArray.shape_.
cols / 2;
3154 transposedArray.
end(
row), comparitor);
3156 dtype medianValue = transposedArray(
row, middleIdx);
3159 const uint32 lhsIndex = middleIdx - 1;
3161 transposedArray.
end(
row), comparitor);
3162 medianValue = (medianValue + transposedArray(
row, lhsIndex)) / dtype{2};
3165 returnArray(0,
row) = medianValue;
3201 return static_cast<uint64>(
sizeof(dtype) * size_);
3226 switch (inEndianess)
3259 switch (inEndianess)
3279 [](dtype value) noexcept -> dtype
3281 return boost::endian::native_to_little<dtype>(boost::endian::big_to_native<dtype>(value));
3296 switch (inEndianess)
3311 const auto function = [](dtype value) noexcept -> dtype
3313 return boost::endian::native_to_big<dtype>(boost::endian::little_to_native<dtype>(value));
3354 const auto function = [](dtype i) ->
bool
3356 return i != dtype{ 0 };
3477 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3498 if (inKth >= shape_.
cols)
3513 if (inKth >= shape_.
rows)
3524 transposedArray.
end(
row), comparitor);
3565 dtype product = std::accumulate(
cbegin(),
cend(),
3566 dtype{ 1 }, std::multiplies<dtype>());
3576 dtype{ 1 }, std::multiplies<dtype>());
3587 returnArray(0,
row) = std::accumulate(transposedArray.
cbegin(
row), transposedArray.
cend(
row),
3588 dtype{ 1 }, std::multiplies<dtype>());
3615 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3634 returnArray(0,
row) = *result.second - *result.first;
3646 returnArray(0,
row) = *result.second - *result.first;
3669 at(inIndex) = inValue;
3686 at(inRow, inCol) = inValue;
3702 for (
auto index : inIndices)
3704 put(index, inValue);
3721 if (inIndices.
size() != inValues.
size())
3727 for (
auto index : inIndices)
3729 put(index, inValues[counter++]);
3746 Slice inSliceCopy(inSlice);
3768 Slice inSliceCopy(inSlice);
3771 std::vector<uint32> indices;
3774 indices.push_back(i);
3792 Slice inRowSliceCopy(inRowSlice);
3793 Slice inColSliceCopy(inColSlice);
3798 std::vector<uint32> indices;
3801 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3822 Slice inRowSliceCopy(inRowSlice);
3825 std::vector<uint32> indices;
3828 put(
row, inColIndex, inValue);
3846 Slice inColSliceCopy(inColSlice);
3849 std::vector<uint32> indices;
3850 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3852 put(inRowIndex, col, inValue);
3870 Slice inRowSliceCopy(inRowSlice);
3871 Slice inColSliceCopy(inColSlice);
3876 std::vector<uint32> indices;
3879 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3882 indices.push_back(index);
3901 Slice inRowSliceCopy(inRowSlice);
3904 std::vector<uint32> indices;
3908 indices.push_back(index);
3926 Slice inColSliceCopy(inColSlice);
3929 std::vector<uint32> indices;
3930 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3932 const uint32 index = inRowIndex * shape_.
cols + col;
3933 indices.push_back(index);
3948 if (inMask.
shape() != shape_)
3965 if (inMask.
shape() != shape_)
4004 for (
uint32 col = 0; col < inNumCols; ++col)
4006 std::vector<uint32> indices(shape_.
size());
4012 const uint32 colEnd = (col + 1) * shape_.
cols;
4015 for (
uint32 rowIdx = rowStart; rowIdx < rowEnd; ++rowIdx)
4017 for (
uint32 colIdx = colStart; colIdx < colEnd; ++colIdx)
4019 indices[counter++] = rowIdx * returnArray.shape_.
cols + colIdx;
4073 if (inSize != size_)
4075 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4081 shape_.
cols = inSize;
4102 if (size_ % inNumCols == 0)
4104 return reshape(size_ / inNumCols, inNumCols);
4108 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4116 if (size_ % inNumRows == 0)
4118 return reshape(inNumRows, size_ / inNumRows);
4122 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4128 if (
static_cast<uint32>(inNumRows * inNumCols) != size_)
4130 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4135 shape_.
rows =
static_cast<uint32>(inNumRows);
4136 shape_.
cols =
static_cast<uint32>(inNumCols);
4170 newArray(
Shape(inNumRows, inNumCols));
4203 std::vector<dtype> oldData(size_);
4206 const Shape inShape(inNumRows, inNumCols);
4207 const Shape oldShape = shape_;
4213 for (
uint32 col = 0; col < inShape.
cols; ++col)
4263 const double multFactor =
utils::power(10.0, inNumDecimals);
4264 const auto function = [multFactor](dtype value) noexcept -> dtype
4266 return static_cast<dtype
>(std::nearbyint(
static_cast<double>(value) * multFactor) / multFactor);
4330 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
4382 for (
uint32 col = 0; col < shape_.
cols; ++col)
4435 const Shape transShape = transposedArray.
shape();
4439 returnArray(0,
row) = std::accumulate(transposedArray.
cbegin(
row), transposedArray.
cend(
row), dtype{ 0 });
4478 void tofile(
const std::string& inFilename,
const std::string& inSep =
"")
const
4482 if (inSep.compare(
"") == 0)
4494 std::ofstream ofile(
f.fullName().c_str());
4501 for (
auto value : *
this)
4504 if (counter++ != size_ - 1)
4547 rowStart += inOffset;
4552 colStart += inOffset;
4563 if (rowStart >= shape_.
rows || colStart >= shape_.
cols)
4572 if (col >= shape_.
cols)
4596 for (
uint32 col = 0; col < shape_.
cols; ++col)
4620 Shape shape_{ 0, 0 };
4624 bool ownsPtr_{
false };
4630 void deleteArray() noexcept
4632 if (ownsPtr_ && array_ !=
nullptr)
4634 allocator_.deallocate(array_, size_);
4652 array_ = allocator_.allocate(size_);
4664 void newArray(
const Shape& inShape)
4669 size_ = inShape.size();
4676 template<
typename dtype,
class _Alloc>
4681 std::vector<uint32> rowIndices;
4682 std::vector<uint32> colIndices;
4684 for (
uint32 row = 0; row < shape_.rows; ++row)
4686 for (
uint32 col = 0; col < shape_.cols; ++col)
4688 if (
operator()(row, col) != dtype{ 0 })
4690 rowIndices.push_back(row);
4691 colIndices.push_back(col);
const_reverse_column_iterator rcolend() const noexcept
Definition: NdArrayCore.hpp:1723
#define STATIC_ASSERT_INTEGER(dtype)
Definition: StaticAsserts.hpp:41
std::reverse_iterator< const_column_iterator > const_reverse_column_iterator
Definition: NdArrayCore.hpp:102
const_reverse_iterator crbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1333
typename std::enable_if< B, T >::type enable_if_t
Definition: TypeTraits.hpp:41
value_type item() const
Definition: NdArrayCore.hpp:2950
column_iterator colbegin(size_type inCol)
Definition: NdArrayCore.hpp:1191
NdArray< bool > contains(value_type inValue, Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2343
int32 stop
Definition: Slice.hpp:49
NdArray< dtype > & put(int32 inRowIndex, const Slice &inColSlice, value_type inValue)
Definition: NdArrayCore.hpp:3844
const_iterator cend(size_type inRow) const
Definition: NdArrayCore.hpp:1505
NdArray< bool > any(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1839
std::vector< dtype > toStlVector() const
Definition: NdArrayCore.hpp:4520
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4296
std::int32_t int32
Definition: Types.hpp:37
NdArray< dtype > & operator=(NdArray< dtype > &&rhs) noexcept
Definition: NdArrayCore.hpp:618
Custom column iterator for NdArray.
Definition: NdArrayIterators.hpp:828
const_iterator cbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1161
std::reverse_iterator< column_iterator > reverse_column_iterator
Definition: NdArrayCore.hpp:101
NdArray(const NdArray< dtype > &inOtherArray)
Definition: NdArrayCore.hpp:523
void makePositiveAndValidate(uint32 inArraySize)
Definition: Slice.hpp:114
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
NdArray< dtype > dot(const NdArray< dtype > &inOtherArray) const
Definition: NdArrayCore.hpp:2635
NdArray< dtype > & sort(Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:4326
reference operator[](int32 inIndex) noexcept
Definition: NdArrayCore.hpp:646
NdArray< dtype > & put(const Slice &inRowSlice, const Slice &inColSlice, value_type inValue)
Definition: NdArrayCore.hpp:3790
NdArray< dtype > round(uint8 inNumDecimals=0) const
Definition: NdArrayCore.hpp:4258
NdArray< dtype > copy() const
Definition: NdArrayCore.hpp:2391
NdArray< dtype > at(int32 inRowIndex, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1078
reference back(size_type row)
Definition: NdArrayCore.hpp:2252
NdArray< dtype > & nans() noexcept
Definition: NdArrayCore.hpp:3182
const_iterator begin() const noexcept
Definition: NdArrayCore.hpp:1121
reference at(int32 inIndex)
Definition: NdArrayCore.hpp:920
NdArray< dtype > operator()(const Slice &inRowSlice, int32 inColIndex) const
Definition: NdArrayCore.hpp:841
value_type trace(uint32 inOffset=0, Axis inAxis=Axis::ROW) const noexcept
Definition: NdArrayCore.hpp:4537
NdArray< dtype > at(const Slice &inRowSlice, int32 inColIndex) const
Definition: NdArrayCore.hpp:1062
NdArray(std::vector< std::array< dtype, Dim1Size >> &in2dArray, bool copy=true)
Definition: NdArrayCore.hpp:330
NdArray(std::array< dtype, ArraySize > &inArray, bool copy=true)
Definition: NdArrayCore.hpp:213
NdArray< dtype > operator[](const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:756
NdArray< dtype > & reshape(const Shape &inShape)
Definition: NdArrayCore.hpp:4153
const_reverse_column_iterator crcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1419
NdArray< dtype > & resizeSlow(const Shape &inShape)
Definition: NdArrayCore.hpp:4241
NdArray(const std::initializer_list< dtype > &inList)
Definition: NdArrayCore.hpp:159
const dtype & const_reference
Definition: NdArrayCore.hpp:90
std::uint8_t uint8
Definition: Types.hpp:43
NdArray< dtype > & reshape(size_type inSize)
Definition: NdArrayCore.hpp:4071
std::uint64_t uint64
Definition: Types.hpp:40
NdArray< dtype > & put(int32 inRowIndex, const Slice &inColSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3924
void tofile(const std::string &inFilename, const std::string &inSep="") const
Definition: NdArrayCore.hpp:4478
std::string num2str(dtype inNumber)
Definition: num2str.hpp:47
bool issquare() const noexcept
Definition: NdArrayCore.hpp:2936
NdArray< dtype > prod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3557
NdArray< dtype > diagonal(int32 inOffset=0, Axis inAxis=Axis::ROW) const
Definition: NdArrayCore.hpp:2566
NdArray< dtype > & operator=(const NdArray< dtype > &rhs)
Definition: NdArrayCore.hpp:573
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:51
NdArray< dtype > & putMask(const NdArray< bool > &inMask, value_type inValue)
Definition: NdArrayCore.hpp:3946
const_reverse_iterator rend() const noexcept
Definition: NdArrayCore.hpp:1551
NdArrayConstColumnIterator< dtype, size_type, const_pointer, difference_type > const_column_iterator
Definition: NdArrayCore.hpp:100
const_reference at(int32 inRowIndex, int32 inColIndex) const
Definition: NdArrayCore.hpp:998
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4591
uint64 nbytes() const noexcept
Definition: NdArrayCore.hpp:3199
NdArray< dtype > & byteswap()
Definition: NdArrayCore.hpp:2266
NdArray< dtype > getByMask(const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:2848
uint32 size_type
Definition: NdArrayCore.hpp:91
const_column_iterator ccolend() const noexcept
Definition: NdArrayCore.hpp:1663
const_reverse_iterator crend(size_type inRow) const
Definition: NdArrayCore.hpp:1591
const_reference at(int32 inIndex) const
Definition: NdArrayCore.hpp:943
NdArray< dtype > max(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2971
NdArray(const std::initializer_list< std::initializer_list< dtype > > &inList)
Definition: NdArrayCore.hpp:177
typename AllocTraits::const_pointer const_pointer
Definition: NdArrayCore.hpp:88
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:75
constexpr bool issquare() const noexcept
Definition: Core/Shape.hpp:124
NdArray< dtype > & put(const NdArray< uint32 > &inIndices, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3719
iterator end(size_type inRow)
Definition: NdArrayCore.hpp:1449
value_type front() const noexcept
Definition: NdArrayCore.hpp:2782
value_type back(size_type row) const
Definition: NdArrayCore.hpp:2240
reverse_column_iterator rcolend(size_type inCol)
Definition: NdArrayCore.hpp:1707
NdArray< dtype > & put(const Slice &inRowSlice, const Slice &inColSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3868
value_type back() const noexcept
Definition: NdArrayCore.hpp:2216
bool ownsInternalData() noexcept
Definition: NdArrayCore.hpp:3452
reference front() noexcept
Definition: NdArrayCore.hpp:2794
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: NdArrayCore.hpp:97
NdArray< dtype > at(const Slice &inSlice) const
Definition: NdArrayCore.hpp:1030
NdArray< dtype > clip(value_type inMin, value_type inMax) const
Definition: NdArrayCore.hpp:2307
constexpr auto j
Definition: Constants.hpp:46
std::uint32_t uint32
Definition: Types.hpp:41
NdArray(std::vector< dtype > &inVector, bool copy=true)
Definition: NdArrayCore.hpp:270
bool is_sorted(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:232
std::allocator< dtype > allocator_type
Definition: NdArrayCore.hpp:86
const_reverse_iterator crend() const noexcept
Definition: NdArrayCore.hpp:1577
const_column_iterator colend(size_type inCol) const
Definition: NdArrayCore.hpp:1651
uint32 numCols() const noexcept
Definition: NdArrayCore.hpp:3415
NdArrayIterator< dtype, pointer, difference_type > iterator
Definition: NdArrayCore.hpp:94
Custom column const_iterator for NdArray.
Definition: NdArrayIterators.hpp:497
std::string str() const
Definition: NdArrayCore.hpp:4373
column_iterator colend() noexcept
Definition: NdArrayCore.hpp:1607
NdArray< dtype > newbyteorder(Endian inEndianess) const
Definition: NdArrayCore.hpp:3218
pointer dataRelease() noexcept
Definition: NdArrayCore.hpp:2549
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
ForwardIt max_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:269
NdArray< dtype > & put(int32 inIndex, value_type inValue)
Definition: NdArrayCore.hpp:3667
NdArray< dtype > & reshape(int32 inNumRows, int32 inNumCols)
Definition: NdArrayCore.hpp:4098
bool all_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:58
const_column_iterator ccolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1247
int32 start
Definition: Slice.hpp:48
void fill(ForwardIt first, ForwardIt last, const T &value) noexcept
Definition: StlAlgorithms.hpp:175
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:44
NdArray< dtype > column(uint32 inColumn)
Definition: NdArrayCore.hpp:2329
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:96
bool isflat() const noexcept
Definition: NdArrayCore.hpp:2874
const_iterator end() const noexcept
Definition: NdArrayCore.hpp:1465
const_reverse_iterator rend(size_type inRow) const
Definition: NdArrayCore.hpp:1565
NdArray(const Shape &inShape)
Definition: NdArrayCore.hpp:145
column_iterator colbegin() noexcept
Definition: NdArrayCore.hpp:1177
column_iterator colend(size_type inCol)
Definition: NdArrayCore.hpp:1621
iterator end() noexcept
Definition: NdArrayCore.hpp:1435
Endian
Enum for endianess.
Definition: Types.hpp:51
const_reverse_iterator rbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1307
NdArray(const_pointer inPtr, uint32 numRows, uint32 numCols)
Definition: NdArrayCore.hpp:466
size_type size() const noexcept
Definition: NdArrayCore.hpp:4310
uint32 cols
Definition: Core/Shape.hpp:46
reverse_column_iterator rcolend() noexcept
Definition: NdArrayCore.hpp:1693
NdArray< dtype > repeat(const Shape &inRepeatShape) const
Definition: NdArrayCore.hpp:4041
void dump(const std::string &inFilename) const
Definition: NdArrayCore.hpp:2681
NdArray< dtype > sum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:4411
NdArray< dtype > swapaxes() const
Definition: NdArrayCore.hpp:4460
const_reverse_iterator rbegin() const noexcept
Definition: NdArrayCore.hpp:1293
dtype & reference
Definition: NdArrayCore.hpp:89
NdArray< dtype > & operator=(value_type inValue) noexcept
Definition: NdArrayCore.hpp:599
NdArray< dtype > & put(const Slice &inRowSlice, int32 inColIndex, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3899
reverse_column_iterator rcolbegin() noexcept
Definition: NdArrayCore.hpp:1349
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1491
NdArray(NdArray< dtype > &&inOtherArray) noexcept
Definition: NdArrayCore.hpp:542
const_reverse_column_iterator rcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1737
uint32 numElements(uint32 inArraySize)
Definition: Slice.hpp:165
Axis
Enum To describe an axis.
Definition: Types.hpp:47
InputIt find(InputIt first, InputIt last, const T &value) noexcept
Definition: StlAlgorithms.hpp:196
#define THROW_RUNTIME_ERROR(msg)
Definition: Error.hpp:38
NdArray< dtype > & put(const Slice &inRowSlice, int32 inColIndex, value_type inValue)
Definition: NdArrayCore.hpp:3820
void nth_element(RandomIt first, RandomIt nth, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:398
std::reverse_iterator< iterator > reverse_iterator
Definition: NdArrayCore.hpp:96
const double nan
NaN.
Definition: Constants.hpp:45
reverse_iterator rend(size_type inRow)
Definition: NdArrayCore.hpp:1535
int32 step
Definition: Slice.hpp:50
NdArray< dtype > & put(const Slice &inSlice, value_type inValue)
Definition: NdArrayCore.hpp:3744
NdArray< dtype > & zeros() noexcept
Definition: NdArrayCore.hpp:4609
NdArray< dtype > flatten() const
Definition: NdArrayCore.hpp:2768
NdArray< dtype > & put(const Slice &inSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3766
NdArray< dtype > cumsum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2470
NdArray< dtype > & ones() noexcept
Definition: NdArrayCore.hpp:3438
NdArray(const std::deque< dtype > &inDeque)
Definition: NdArrayCore.hpp:357
dtype value_type
Definition: NdArrayCore.hpp:85
Endian endianess() const noexcept
Definition: NdArrayCore.hpp:2709
NdArray(size_type inSquareSize)
Definition: NdArrayCore.hpp:117
Definition: Coordinate.hpp:45
const_column_iterator ccolbegin() const noexcept
Definition: NdArrayCore.hpp:1233
bool any_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:77
pointer data() noexcept
Definition: NdArrayCore.hpp:2527
const_column_iterator ccolend(size_type inCol) const
Definition: NdArrayCore.hpp:1677
const Slice rSlice(int32 inStartIdx=0, uint32 inStepSize=1) const noexcept
Definition: NdArrayCore.hpp:906
const_reverse_column_iterator crcolbegin() const noexcept
Definition: NdArrayCore.hpp:1405
reverse_iterator rend() noexcept
Definition: NdArrayCore.hpp:1521
reference at(int32 inRowIndex, int32 inColIndex)
Definition: NdArrayCore.hpp:966
uint32 rows
Definition: Core/Shape.hpp:45
NdArray< dtype > operator()(int32 inRowIndex, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:866
NdArray< uint32 > argmin(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1954
std::int64_t int64
Definition: Types.hpp:36
void replace(ForwardIt first, ForwardIt last, const T &oldValue, const T &newValue) noexcept
Definition: StlAlgorithms.hpp:436
Custom const_iterator for NdArray.
Definition: NdArrayIterators.hpp:43
NdArray< dtype > operator[](const Slice &inSlice) const
Definition: NdArrayCore.hpp:733
NdArray< dtype > row(uint32 inRow)
Definition: NdArrayCore.hpp:4282
NdArrayColumnIterator< dtype, size_type, pointer, difference_type > column_iterator
Definition: NdArrayCore.hpp:99
NdArray(pointer inPtr, uint32 numRows, uint32 numCols, Bool takeOwnership) noexcept
Definition: NdArrayCore.hpp:509
NdArray< uint32 > argsort(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2012
NdArray< dtype > getByIndices(const NdArray< uint32 > &inIndices) const
Definition: NdArrayCore.hpp:2832
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
Custom iterator for NdArray.
Definition: NdArrayIterators.hpp:318
reverse_iterator rbegin() noexcept
Definition: NdArrayCore.hpp:1263
NdArray< dtype > & put(int32 inRow, int32 inCol, value_type inValue)
Definition: NdArrayCore.hpp:3684
constexpr uint32 size() const noexcept
Definition: Core/Shape.hpp:103
dtype power(dtype inValue, uint8 inPower) noexcept
Definition: Utils/power.hpp:49
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction) noexcept
Definition: StlAlgorithms.hpp:703
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1147
NdArray< dtype > cumprod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2407
void sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:630
NdArray(const std::deque< std::deque< dtype >> &in2dDeque)
Definition: NdArrayCore.hpp:374
const_iterator end(size_type inRow) const
Definition: NdArrayCore.hpp:1479
reference back() noexcept
Definition: NdArrayCore.hpp:2228
NdArray< dtypeOut > astype() const
Definition: NdArrayCore.hpp:2097
NdArrayConstIterator< dtype, const_pointer, difference_type > const_iterator
Definition: NdArrayCore.hpp:95
const_column_iterator colbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1221
NdArray(const std::vector< std::vector< dtype >> &in2dVector)
Definition: NdArrayCore.hpp:295
ForwardIt min_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:305
NdArray< dtype > & resizeFast(uint32 inNumRows, uint32 inNumCols)
Definition: NdArrayCore.hpp:4168
const_column_iterator colbegin() const noexcept
Definition: NdArrayCore.hpp:1207
const_reference operator()(int32 inRowIndex, int32 inColIndex) const noexcept
Definition: NdArrayCore.hpp:708
const_reverse_column_iterator crcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1763
NdArray< uint32 > argmax(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1895
NdArray< uint32 > flatnonzero() const
Definition: NdArrayCore.hpp:2741
void replace(value_type oldValue, value_type newValue)
Definition: NdArrayCore.hpp:4053
reference operator()(int32 inRowIndex, int32 inColIndex) noexcept
Definition: NdArrayCore.hpp:684
void stable_sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:665
NdArray< dtype > & putMask(const NdArray< bool > &inMask, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3963
const_reverse_column_iterator rcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1393
NdArray< bool > none(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3350
std::pair< ForwardIt, ForwardIt > minmax_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:342
bool isempty() const noexcept
Definition: NdArrayCore.hpp:2861
value_type front(size_type row) const
Definition: NdArrayCore.hpp:2806
const_reverse_iterator crbegin() const noexcept
Definition: NdArrayCore.hpp:1319
std::pair< NdArray< uint32 >, NdArray< uint32 > > nonzero() const
Definition: NdArrayCore.hpp:4677
const_reverse_column_iterator rcolbegin() const noexcept
Definition: NdArrayCore.hpp:1379
NdArray(pointer inPtr, size_type size, Bool takeOwnership) noexcept
Definition: NdArrayCore.hpp:489
uint32 numRows() const noexcept
Definition: NdArrayCore.hpp:3428
reference front(size_type row)
Definition: NdArrayCore.hpp:2818
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091
NdArray< dtype > at(const Slice &inRowSlice, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1046
dtype f(dtype inDofN, dtype inDofD)
Definition: f.hpp:58
std::string value2str(dtype inValue)
Definition: value2str.hpp:49
reverse_iterator rbegin(size_type inRow)
Definition: NdArrayCore.hpp:1277
reverse_column_iterator rcolbegin(size_type inCol)
Definition: NdArrayCore.hpp:1363
A Class for slicing into NdArrays.
Definition: Slice.hpp:44
NdArray< dtype > & resizeFast(const Shape &inShape)
Definition: NdArrayCore.hpp:4184
NdArray< dtype > ptp(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3611
NdArray(const std::list< dtype > &inList)
Definition: NdArrayCore.hpp:407
const_reference operator[](int32 inIndex) const noexcept
Definition: NdArrayCore.hpp:665
const_pointer data() const noexcept
Definition: NdArrayCore.hpp:2537
NdArray< dtype > operator[](const NdArray< size_type > &inIndices) const
Definition: NdArrayCore.hpp:782
NdArray(std::array< std::array< dtype, Dim1Size >, Dim0Size > &in2dArray, bool copy=true)
Definition: NdArrayCore.hpp:241
NdArray(const_pointer inPtr, size_type size)
Definition: NdArrayCore.hpp:446
bool none_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:380
typename AllocTraits::pointer pointer
Definition: NdArrayCore.hpp:87
const_column_iterator colend() const noexcept
Definition: NdArrayCore.hpp:1637
NdArray< dtype > & partition(uint32 inKth, Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:3473
NdArray< bool > issorted(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2886
const_reverse_column_iterator crcolend() const noexcept
Definition: NdArrayCore.hpp:1749
NdArray< dtype > & fill(value_type inFillValue) noexcept
Definition: NdArrayCore.hpp:2727
NdArray(Iterator inFirst, Iterator inLast)
Definition: NdArrayCore.hpp:427
NdArray< bool > all(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1784
~NdArray() noexcept
Definition: NdArrayCore.hpp:559
const Slice cSlice(int32 inStartIdx=0, uint32 inStepSize=1) const noexcept
Definition: NdArrayCore.hpp:891
const_iterator begin(size_type inRow) const
Definition: NdArrayCore.hpp:1135
NdArray< dtype > median(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3085
NdArray< dtype > & ravel() noexcept
Definition: NdArrayCore.hpp:3981
NdArray< dtype > repeat(uint32 inNumRows, uint32 inNumCols) const
Definition: NdArrayCore.hpp:3998
typename AllocTraits::difference_type difference_type
Definition: NdArrayCore.hpp:92
NdArray(size_type inNumRows, size_type inNumCols)
Definition: NdArrayCore.hpp:131
void print() const
Definition: NdArrayCore.hpp:3539
Provides simple filesystem functions.
Definition: Filesystem.hpp:40
NdArray< dtype > & put(const NdArray< uint32 > &inIndices, value_type inValue)
Definition: NdArrayCore.hpp:3700
iterator begin(size_type inRow)
Definition: NdArrayCore.hpp:1105
auto abs(dtype inValue) noexcept
Definition: abs.hpp:52
NdArray< dtype > & resizeSlow(uint32 inNumRows, uint32 inNumCols)
Definition: NdArrayCore.hpp:4201
NdArray< dtype > operator()(const Slice &inRowSlice, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:809
NdArray< dtype > min(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3027