 |
NumCpp
2.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>
357 explicit NdArray(
const std::deque<dtype>& inDeque) :
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 };
1844 const auto function = [](dtype i) ->
bool
1846 return i != dtype{ 0 };
1901 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
1961 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
2024 std::vector<uint32> idx(size_);
2025 std::iota(idx.begin(), idx.end(), 0);
2027 const auto function = [
this](
uint32 i1,
uint32 i2) noexcept ->
bool
2029 return (*
this)[i1] < (*this)[i2];
2040 std::vector<uint32> idx(shape_.
cols);
2041 std::iota(idx.begin(), idx.end(), 0);
2043 const auto function = [
this,
row](
uint32 i1,
uint32 i2) noexcept ->
bool
2050 for (
uint32 col = 0; col < shape_.
cols; ++col)
2052 returnArray(
row, col) = idx[col];
2063 std::vector<uint32> idx(arrayTransposed.shape_.
cols);
2064 std::iota(idx.begin(), idx.end(), 0);
2066 const auto function = [&arrayTransposed,
row](
uint32 i1,
uint32 i2) noexcept ->
bool
2068 return arrayTransposed(
row, i1) < arrayTransposed(
row, i2);
2073 for (
uint32 col = 0; col < arrayTransposed.shape_.
cols; ++col)
2075 returnArray(
row, col) = idx[col];
2098 template<
typename dtypeOut,
typename dtype_ = dtype,
2106 if (std::is_same<dtypeOut, dtype>::value)
2112 const auto function = [](dtype value) -> dtypeOut
2114 return static_cast<dtypeOut
>(value);
2133 template<
typename dtypeOut,
typename dtype_ = dtype,
2143 return std::complex<typename dtypeOut::value_type>(value);
2161 template<
typename dtypeOut,
typename dtype_ = dtype,
2169 if (std::is_same<dtypeOut, dtype>::value)
2177 return complex_cast<typename dtypeOut::value_type>(value);
2196 template<
typename dtypeOut,
typename dtype_ = dtype,
2206 return static_cast<dtypeOut
>(value.real());
2223 return *(
cend() - 1);
2235 return *(
end() - 1);
2289 #if BOOST_ENDIAN_BIG_BYTE
2291 #elif BOOST_ENDIAN_LITTLE_BYTE
2317 boost::algorithm::clamp_range(
cbegin(),
cend(), outArray.
begin(), inMin, inMax,
2318 [](dtype lhs, dtype rhs) noexcept ->
bool
2422 returnArray[0] =
front();
2423 for (
uint32 i = 1; i < size_; ++i)
2425 returnArray[i] = returnArray[i - 1] * array_[i];
2436 for (
uint32 col = 1; col < shape_.
cols; ++col)
2447 for (
uint32 col = 0; col < shape_.
cols; ++col)
2486 returnArray[0] =
front();
2487 for (
uint32 i = 1; i < size_; ++i)
2489 returnArray[i] = returnArray[i - 1] + array_[i];
2500 for (
uint32 col = 1; col < shape_.
cols; ++col)
2511 for (
uint32 col = 0; col < shape_.
cols; ++col)
2580 std::vector<dtype> diagnolValues;
2581 int32 col = inOffset;
2589 if (col >=
static_cast<int32>(shape_.
cols))
2594 diagnolValues.push_back(
operator()(
row,
static_cast<uint32>(col)));
2602 std::vector<dtype> diagnolValues;
2604 for (
int32 row = inOffset; row < static_cast<int32>(shape_.
rows); ++
row)
2611 if (col >= shape_.
cols)
2616 diagnolValues.push_back(
operator()(
static_cast<uint32>(
row), col));
2648 if (shape_ == inOtherArray.shape_ && (shape_.
rows == 1 || shape_.
cols == 1))
2650 dtype dotProduct = std::inner_product(
cbegin(),
cend(), inOtherArray.
cbegin(), dtype{ 0 });
2654 if (shape_.
cols == inOtherArray.shape_.
rows)
2658 auto otherArrayT = inOtherArray.
transpose();
2662 for (
uint32 j = 0;
j < otherArrayT.shape_.rows; ++
j)
2664 returnArray(i,
j) = std::inner_product(otherArrayT.cbegin(
j), otherArrayT.cend(
j),
cbegin(i), dtype{ 0 });
2673 errStr +=
" are not consistent.";
2688 void dump(
const std::string& inFilename)
const
2696 std::ofstream ofile(
f.fullName().c_str(), std::ios::binary);
2702 if (array_ !=
nullptr)
2704 ofile.write(
reinterpret_cast<const char*
>(array_), size_ *
sizeof(dtype));
2752 std::vector<uint32> indices;
2754 for (
auto value : *
this)
2756 if (value != dtype{ 0 })
2758 indices.push_back(idx);
2883 return shape_.
rows == 1 || shape_.
cols == 1;
2897 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
2915 transposedArray.cend(
row), comparitor);
2983 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3012 transposedArray.
cend(
row), comparitor);
3040 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3069 transposedArray.
cend(
row), comparitor);
3099 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3115 const uint32 middleIdx = size_ / 2;
3118 dtype medianValue = copyArray.array_[middleIdx];
3121 const uint32 lhsIndex = middleIdx - 1;
3123 medianValue = (medianValue + copyArray.array_[lhsIndex]) / dtype{2};
3126 return { medianValue };
3133 const bool isEven = shape_.
cols % 2 == 0;
3138 copyArray.
end(
row), comparitor);
3140 dtype medianValue = copyArray(
row, middleIdx);
3143 const uint32 lhsIndex = middleIdx - 1;
3145 copyArray.
end(
row), comparitor);
3146 medianValue = (medianValue + copyArray(
row, lhsIndex)) / dtype{2};
3149 returnArray(0,
row) = medianValue;
3159 const bool isEven = shape_.
rows % 2 == 0;
3162 const uint32 middleIdx = transposedArray.shape_.
cols / 2;
3164 transposedArray.
end(
row), comparitor);
3166 dtype medianValue = transposedArray(
row, middleIdx);
3169 const uint32 lhsIndex = middleIdx - 1;
3171 transposedArray.
end(
row), comparitor);
3172 medianValue = (medianValue + transposedArray(
row, lhsIndex)) / dtype{2};
3175 returnArray(0,
row) = medianValue;
3212 return static_cast<uint64>(
sizeof(dtype) * size_);
3237 switch (inEndianess)
3271 switch (inEndianess)
3291 [](dtype value) noexcept -> dtype
3293 return boost::endian::native_to_little<dtype>(boost::endian::big_to_native<dtype>(value));
3309 switch (inEndianess)
3324 const auto function = [](dtype value) noexcept -> dtype
3326 return boost::endian::native_to_big<dtype>(boost::endian::little_to_native<dtype>(value));
3369 const auto function = [](dtype i) ->
bool
3371 return i != dtype{ 0 };
3493 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3514 if (inKth >= shape_.
cols)
3529 if (inKth >= shape_.
rows)
3540 transposedArray.
end(
row), comparitor);
3581 dtype product = std::accumulate(
cbegin(),
cend(),
3582 dtype{ 1 }, std::multiplies<dtype>());
3592 dtype{ 1 }, std::multiplies<dtype>());
3603 returnArray(0,
row) = std::accumulate(transposedArray.
cbegin(
row), transposedArray.
cend(
row),
3604 dtype{ 1 }, std::multiplies<dtype>());
3632 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3651 returnArray(0,
row) = *result.second - *result.first;
3663 returnArray(0,
row) = *result.second - *result.first;
3687 at(inIndex) = inValue;
3704 at(inRow, inCol) = inValue;
3720 for (
auto index : inIndices)
3722 put(index, inValue);
3739 if (inIndices.
size() != inValues.
size())
3745 for (
auto index : inIndices)
3747 put(index, inValues[counter++]);
3764 Slice inSliceCopy(inSlice);
3786 Slice inSliceCopy(inSlice);
3789 std::vector<uint32> indices;
3792 indices.push_back(i);
3810 Slice inRowSliceCopy(inRowSlice);
3811 Slice inColSliceCopy(inColSlice);
3816 std::vector<uint32> indices;
3819 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3840 Slice inRowSliceCopy(inRowSlice);
3843 std::vector<uint32> indices;
3846 put(
row, inColIndex, inValue);
3864 Slice inColSliceCopy(inColSlice);
3867 std::vector<uint32> indices;
3868 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3870 put(inRowIndex, col, inValue);
3888 Slice inRowSliceCopy(inRowSlice);
3889 Slice inColSliceCopy(inColSlice);
3894 std::vector<uint32> indices;
3897 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3900 indices.push_back(index);
3919 Slice inRowSliceCopy(inRowSlice);
3922 std::vector<uint32> indices;
3926 indices.push_back(index);
3944 Slice inColSliceCopy(inColSlice);
3947 std::vector<uint32> indices;
3948 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3950 const uint32 index = inRowIndex * shape_.
cols + col;
3951 indices.push_back(index);
3966 if (inMask.
shape() != shape_)
3983 if (inMask.
shape() != shape_)
4022 for (
uint32 col = 0; col < inNumCols; ++col)
4024 std::vector<uint32> indices(shape_.
size());
4030 const uint32 colEnd = (col + 1) * shape_.
cols;
4033 for (
uint32 rowIdx = rowStart; rowIdx < rowEnd; ++rowIdx)
4035 for (
uint32 colIdx = colStart; colIdx < colEnd; ++colIdx)
4037 indices[counter++] = rowIdx * returnArray.shape_.
cols + colIdx;
4091 if (inSize != size_)
4093 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4099 shape_.
cols = inSize;
4120 if (size_ % inNumCols == 0)
4122 return reshape(size_ / inNumCols, inNumCols);
4125 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4133 if (size_ % inNumRows == 0)
4135 return reshape(inNumRows, size_ / inNumRows);
4138 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4144 if (
static_cast<uint32>(inNumRows * inNumCols) != size_)
4146 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4151 shape_.
rows =
static_cast<uint32>(inNumRows);
4152 shape_.
cols =
static_cast<uint32>(inNumCols);
4186 newArray(
Shape(inNumRows, inNumCols));
4219 std::vector<dtype> oldData(size_);
4222 const Shape inShape(inNumRows, inNumCols);
4223 const Shape oldShape = shape_;
4229 for (
uint32 col = 0; col < inShape.
cols; ++col)
4279 const double multFactor =
utils::power(10.0, inNumDecimals);
4280 const auto function = [multFactor](dtype value) noexcept -> dtype
4282 return static_cast<dtype
>(std::nearbyint(
static_cast<double>(value) * multFactor) / multFactor);
4346 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
4398 for (
uint32 col = 0; col < shape_.
cols; ++col)
4451 const Shape transShape = transposedArray.
shape();
4455 returnArray(0,
row) = std::accumulate(transposedArray.
cbegin(
row), transposedArray.
cend(
row), dtype{ 0 });
4495 void tofile(
const std::string& inFilename,
const std::string& inSep =
"")
const
4511 std::ofstream ofile(
f.fullName().c_str());
4518 for (
auto value : *
this)
4521 if (counter++ != size_ - 1)
4564 rowStart += inOffset;
4569 colStart += inOffset;
4580 if (rowStart >= shape_.
rows || colStart >= shape_.
cols)
4589 if (col >= shape_.
cols)
4613 for (
uint32 col = 0; col < shape_.
cols; ++col)
4637 Shape shape_{ 0, 0 };
4641 bool ownsPtr_{
false };
4647 void deleteArray() noexcept
4649 if (ownsPtr_ && array_ !=
nullptr)
4651 allocator_.deallocate(array_, size_);
4669 array_ = allocator_.allocate(size_);
4681 void newArray(
const Shape& inShape)
4686 size_ = inShape.size();
4693 template<
typename dtype,
class _Alloc>
4698 std::vector<uint32> rowIndices;
4699 std::vector<uint32> colIndices;
4701 for (
uint32 row = 0; row < shape_.rows; ++row)
4703 for (
uint32 col = 0; col < shape_.cols; ++col)
4705 if (
operator()(row, col) != dtype{ 0 })
4707 rowIndices.push_back(row);
4708 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:2958
column_iterator colbegin(size_type inCol)
Definition: NdArrayCore.hpp:1191
NdArray< bool > contains(value_type inValue, Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2348
int32 stop
Definition: Slice.hpp:49
NdArray< dtype > & put(int32 inRowIndex, const Slice &inColSlice, value_type inValue)
Definition: NdArrayCore.hpp:3862
const_iterator cend(size_type inRow) const
Definition: NdArrayCore.hpp:1505
NdArray< bool > any(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1840
std::vector< dtype > toStlVector() const
Definition: NdArrayCore.hpp:4537
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4312
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:2644
NdArray< dtype > & sort(Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:4342
reference operator[](int32 inIndex) noexcept
Definition: NdArrayCore.hpp:646
NdArray< dtype > & put(const Slice &inRowSlice, const Slice &inColSlice, value_type inValue)
Definition: NdArrayCore.hpp:3808
NdArray< dtype > round(uint8 inNumDecimals=0) const
Definition: NdArrayCore.hpp:4274
NdArray< dtype > copy() const
Definition: NdArrayCore.hpp:2397
NdArray< dtype > at(int32 inRowIndex, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1078
reference back(size_type row)
Definition: NdArrayCore.hpp:2257
NdArray< dtype > & nans() noexcept
Definition: NdArrayCore.hpp:3193
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:4554
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:4169
const_reverse_column_iterator crcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1419
NdArray< dtype > & resizeSlow(const Shape &inShape)
Definition: NdArrayCore.hpp:4257
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:4089
std::uint64_t uint64
Definition: Types.hpp:40
NdArray< dtype > & put(int32 inRowIndex, const Slice &inColSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3942
void tofile(const std::string &inFilename, const std::string &inSep="") const
Definition: NdArrayCore.hpp:4495
std::string num2str(dtype inNumber)
Definition: num2str.hpp:47
bool issquare() const noexcept
Definition: NdArrayCore.hpp:2944
NdArray< dtype > prod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3573
NdArray< dtype > diagonal(int32 inOffset=0, Axis inAxis=Axis::ROW) const
Definition: NdArrayCore.hpp:2574
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:3964
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:4608
uint64 nbytes() const noexcept
Definition: NdArrayCore.hpp:3210
NdArray< dtype > & byteswap()
Definition: NdArrayCore.hpp:2271
NdArray< dtype > getByMask(const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:2855
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:2979
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:3737
iterator end(size_type inRow)
Definition: NdArrayCore.hpp:1449
value_type front() const noexcept
Definition: NdArrayCore.hpp:2789
value_type back(size_type row) const
Definition: NdArrayCore.hpp:2245
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:3886
value_type back() const noexcept
Definition: NdArrayCore.hpp:2221
bool ownsInternalData() noexcept
Definition: NdArrayCore.hpp:3468
reference front() noexcept
Definition: NdArrayCore.hpp:2801
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: NdArrayCore.hpp:97
NdArray< dtype > at(const Slice &inSlice) const
Definition: NdArrayCore.hpp:1030
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:703
NdArray< dtype > clip(value_type inMin, value_type inMax) const
Definition: NdArrayCore.hpp:2312
constexpr auto j
Definition: Constants.hpp:46
std::uint32_t uint32
Definition: Types.hpp:41
Slice rSlice(int32 inStartIdx=0, uint32 inStepSize=1) const noexcept
Definition: NdArrayCore.hpp:906
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
Slice cSlice(int32 inStartIdx=0, uint32 inStepSize=1) const noexcept
Definition: NdArrayCore.hpp:891
uint32 numCols() const noexcept
Definition: NdArrayCore.hpp:3431
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:4389
column_iterator colend() noexcept
Definition: NdArrayCore.hpp:1607
NdArray< dtype > newbyteorder(Endian inEndianess) const
Definition: NdArrayCore.hpp:3229
pointer dataRelease() noexcept
Definition: NdArrayCore.hpp:2557
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:3685
NdArray< dtype > & reshape(int32 inNumRows, int32 inNumCols)
Definition: NdArrayCore.hpp:4116
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:2334
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:96
bool isflat() const noexcept
Definition: NdArrayCore.hpp:2881
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:4326
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:4059
void dump(const std::string &inFilename) const
Definition: NdArrayCore.hpp:2688
NdArray< dtype > sum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:4427
NdArray< dtype > swapaxes() const
Definition: NdArrayCore.hpp:4477
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:3917
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:3838
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:3762
NdArray< dtype > & zeros() noexcept
Definition: NdArrayCore.hpp:4626
NdArray< dtype > flatten() const
Definition: NdArrayCore.hpp:2775
NdArray< dtype > & put(const Slice &inSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3784
NdArray< dtype > cumsum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2477
NdArray< dtype > & ones() noexcept
Definition: NdArrayCore.hpp:3454
NdArray(const std::deque< dtype > &inDeque)
Definition: NdArrayCore.hpp:357
dtype value_type
Definition: NdArrayCore.hpp:85
Endian endianess() const noexcept
Definition: NdArrayCore.hpp:2716
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:2535
const_column_iterator ccolend(size_type inCol) const
Definition: NdArrayCore.hpp:1677
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:1957
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:4298
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:2016
NdArray< dtype > getByIndices(const NdArray< uint32 > &inIndices) const
Definition: NdArrayCore.hpp:2839
#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:3702
constexpr uint32 size() const noexcept
Definition: Core/Shape.hpp:103
dtype power(dtype inValue, uint8 inPower) noexcept
Definition: Utils/power.hpp:49
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1147
NdArray< dtype > cumprod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2413
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:2233
NdArray< dtypeOut > astype() const
Definition: NdArrayCore.hpp:2102
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:4184
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:1897
NdArray< uint32 > flatnonzero() const
Definition: NdArrayCore.hpp:2748
void replace(value_type oldValue, value_type newValue)
Definition: NdArrayCore.hpp:4071
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:3981
const_reverse_column_iterator rcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1393
NdArray< bool > none(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3365
std::pair< ForwardIt, ForwardIt > minmax_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:342
bool isempty() const noexcept
Definition: NdArrayCore.hpp:2868
value_type front(size_type row) const
Definition: NdArrayCore.hpp:2813
const_reverse_iterator crbegin() const noexcept
Definition: NdArrayCore.hpp:1319
std::pair< NdArray< uint32 >, NdArray< uint32 > > nonzero() const
Definition: NdArrayCore.hpp:4694
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:3444
reference front(size_type row)
Definition: NdArrayCore.hpp:2825
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:4200
NdArray< dtype > ptp(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3628
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:2545
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:3489
NdArray< bool > issorted(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2893
const_reverse_column_iterator crcolend() const noexcept
Definition: NdArrayCore.hpp:1749
NdArray< dtype > & fill(value_type inFillValue) noexcept
Definition: NdArrayCore.hpp:2734
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_iterator begin(size_type inRow) const
Definition: NdArrayCore.hpp:1135
NdArray< dtype > median(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3095
NdArray< dtype > & ravel() noexcept
Definition: NdArrayCore.hpp:3999
NdArray< dtype > repeat(uint32 inNumRows, uint32 inNumCols) const
Definition: NdArrayCore.hpp:4016
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:3555
Provides simple filesystem functions.
Definition: Filesystem.hpp:40
NdArray< dtype > & put(const NdArray< uint32 > &inIndices, value_type inValue)
Definition: NdArrayCore.hpp:3718
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:4217
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:3036