 |
NumCpp
2.3.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
|
Go to the documentation of this file.
47 #include <boost/algorithm/clamp.hpp>
48 #include <boost/endian/conversion.hpp>
49 #include <boost/predef/other/endian.h>
54 #include <forward_list>
56 #include <initializer_list>
64 #include <type_traits>
73 template<
typename dtype,
class Allocator = std::allocator<dtype>>
77 STATIC_ASSERT_VALID_DTYPE(dtype);
78 static_assert(is_same_v<dtype, typename Allocator::value_type>,
"value_type and Allocator::value_type must match");
80 using AllocType =
typename std::allocator_traits<Allocator>::template rebind_alloc<dtype>;
81 using AllocTraits = std::allocator_traits<AllocType>;
86 using pointer =
typename AllocTraits::pointer;
117 shape_(inSquareSize, inSquareSize),
118 size_(inSquareSize * inSquareSize)
131 shape_(inNumRows, inNumCols),
132 size_(inNumRows * inNumCols)
158 NdArray(
const std::initializer_list<dtype>& inList) :
159 shape_(1, static_cast<
uint32>(inList.
size())),
176 NdArray(
const std::initializer_list<std::initializer_list<dtype> >& inList) :
179 for (
const auto& list : inList)
181 if (shape_.
cols == 0)
183 shape_.
cols =
static_cast<uint32>(list.size());
185 else if (list.size() != shape_.
cols)
191 size_ = shape_.
size();
194 for (
const auto& list : inList)
210 template<
size_t ArraySize,
211 std::enable_if_t<is_valid_dtype_v<dtype>,
int> = 0>
212 NdArray(std::array<dtype, ArraySize>& inArray,
bool copy =
true) :
213 shape_(1, static_cast<
uint32>(ArraySize)),
226 array_ = inArray.data();
239 template<
size_t Dim0Size,
size_t Dim1Size>
240 NdArray(std::array<std::array<dtype, Dim1Size>, Dim0Size>& in2dArray,
bool copy =
true) :
241 shape_(static_cast<
uint32>(Dim0Size), static_cast<
uint32>(Dim1Size)),
249 const auto start = in2dArray.front().begin();
255 array_ = in2dArray.front().data();
268 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
270 shape_(1, static_cast<
uint32>(inVector.
size())),
283 array_ = inVector.data();
294 explicit NdArray(
const std::vector<std::vector<dtype>>& in2dVector) :
295 shape_(static_cast<
uint32>(in2dVector.
size()), 0)
297 for (
const auto&
row : in2dVector)
299 if (shape_.
cols == 0)
309 size_ = shape_.
size();
312 auto currentPosition =
begin();
313 for (
const auto&
row : in2dVector)
316 currentPosition += shape_.
cols;
328 template<
size_t Dim1Size>
329 NdArray(std::vector<std::array<dtype, Dim1Size>>& in2dArray,
bool copy =
true) :
330 shape_(static_cast<
uint32>(in2dArray.
size()), static_cast<
uint32>(Dim1Size)),
338 const auto start = in2dArray.front().begin();
344 array_ = in2dArray.front().data();
355 template<std::enable_if_t<is_val
id_dtype_v<dtype>,
int> = 0>
356 explicit NdArray(
const std::deque<dtype>& inDeque) :
357 shape_(1, static_cast<
uint32>(inDeque.
size())),
373 explicit NdArray(
const std::deque<std::deque<dtype>>& in2dDeque) :
374 shape_(static_cast<
uint32>(in2dDeque.
size()), 0)
376 for (
const auto&
row : in2dDeque)
378 if (shape_.
cols == 0)
388 size_ = shape_.
size();
391 auto currentPosition =
begin();
392 for (
const auto&
row : in2dDeque)
395 currentPosition += shape_.
cols;
406 explicit NdArray(
const std::list<dtype>& inList) :
407 shape_(1, static_cast<
uint32>(inList.
size())),
424 template<
typename Iterator,
425 std::enable_if_t<std::is_same<typename std::iterator_traits<Iterator>::value_type, dtype>::value,
int> = 0>
427 shape_(1, static_cast<
uint32>(std::distance(inFirst, inLast))),
450 if (inPtr !=
nullptr && size_ > 0)
470 if (inPtr !=
nullptr && size_ > 0)
486 template<
typename Bool,
487 std::enable_if_t<std::is_same<Bool, bool>::value,
int> = 0>
492 ownsPtr_(takeOwnership)
506 template<
typename Bool,
507 std::enable_if_t<std::is_same<Bool, bool>::value,
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)
783 if (inIndices.
max().item() > size_ - 1)
790 for (
auto& index : inIndices)
810 Slice inRowSliceCopy(inRowSlice);
811 Slice inColSliceCopy(inColSlice);
819 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
821 returnArray(rowCounter, colCounter++) =
at(
row, col);
842 Slice inRowSliceCopy(inRowSlice);
849 returnArray(rowCounter++, 0) =
at(
row, inColIndex);
867 Slice inColSliceCopy(inColSlice);
872 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
874 returnArray(0, colCounter++) =
at(inRowIndex, col);
892 return Slice(inStartIdx, shape_.
cols, inStepSize);
907 return Slice(inStartIdx, shape_.
rows, inStepSize);
926 errStr +=
" is out of bounds for array of size " +
utils::num2str(size_) +
".";
949 errStr +=
" is out of bounds for array of size " +
utils::num2str(size_) +
".";
980 std::string errStr =
"Column index " +
utils::num2str(inColIndex);
1004 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
rows) +
".";
1012 std::string errStr =
"Column index " +
utils::num2str(inColIndex);
1013 errStr +=
" is out of bounds for array of size " +
utils::num2str(shape_.
cols) +
".";
1106 if (inRow >= shape_.
rows)
1111 return begin() += (inRow * shape_.
cols);
1162 if (inRow >= shape_.
rows)
1192 if (inCol >= shape_.
cols)
1248 if (inCol >= shape_.
cols)
1278 if (inRow >= shape_.
rows)
1334 if (inRow >= shape_.
rows)
1364 if (inCol >= shape_.
cols)
1420 if (inCol >= shape_.
cols)
1436 return begin() += size_;
1450 if (inRow >= shape_.
rows)
1492 return cbegin() += size_;
1506 if (inRow >= shape_.
rows)
1522 return rbegin() += size_;
1536 if (inRow >= shape_.
rows)
1566 return crend(inRow);
1592 if (inRow >= shape_.
rows)
1622 if (inCol >= shape_.
cols)
1678 if (inCol >= shape_.
cols)
1708 if (inCol >= shape_.
cols)
1764 if (inCol >= shape_.
cols)
1787 const auto function = [](dtype i) ->
bool
1789 return i != dtype{ 0 };
1843 const auto function = [](dtype i) ->
bool
1845 return i != dtype{ 0 };
1900 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
1960 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
2023 std::vector<uint32> idx(size_);
2024 std::iota(idx.begin(), idx.end(), 0);
2026 const auto function = [
this](
uint32 i1,
uint32 i2) noexcept ->
bool
2028 return (*
this)[i1] < (*this)[i2];
2039 std::vector<uint32> idx(shape_.
cols);
2040 std::iota(idx.begin(), idx.end(), 0);
2042 const auto function = [
this,
row](
uint32 i1,
uint32 i2) noexcept ->
bool
2049 for (
uint32 col = 0; col < shape_.
cols; ++col)
2051 returnArray(
row, col) = idx[col];
2062 std::vector<uint32> idx(arrayTransposed.shape_.
cols);
2063 std::iota(idx.begin(), idx.end(), 0);
2065 const auto function = [&arrayTransposed,
row](
uint32 i1,
uint32 i2) noexcept ->
bool
2067 return arrayTransposed(
row, i1) < arrayTransposed(
row, i2);
2072 for (
uint32 col = 0; col < arrayTransposed.shape_.
cols; ++col)
2074 returnArray(
row, col) = idx[col];
2097 template<
typename dtypeOut,
typename dtype_ = dtype,
2105 if (std::is_same<dtypeOut, dtype>::value)
2111 const auto function = [](dtype value) -> dtypeOut
2113 return static_cast<dtypeOut
>(value);
2132 template<
typename dtypeOut,
typename dtype_ = dtype,
2142 return std::complex<typename dtypeOut::value_type>(value);
2160 template<
typename dtypeOut,
typename dtype_ = dtype,
2168 if (std::is_same<dtypeOut, dtype>::value)
2176 return complex_cast<typename dtypeOut::value_type>(value);
2195 template<
typename dtypeOut,
typename dtype_ = dtype,
2205 return static_cast<dtypeOut
>(value.real());
2222 return *(
cend() - 1);
2234 return *(
end() - 1);
2288 #if BOOST_ENDIAN_BIG_BYTE
2290 #elif BOOST_ENDIAN_LITTLE_BYTE
2316 boost::algorithm::clamp_range(
cbegin(),
cend(), outArray.
begin(), inMin, inMax,
2317 [](dtype lhs, dtype rhs) noexcept ->
bool
2421 returnArray[0] =
front();
2422 for (
uint32 i = 1; i < size_; ++i)
2424 returnArray[i] = returnArray[i - 1] * array_[i];
2435 for (
uint32 col = 1; col < shape_.
cols; ++col)
2446 for (
uint32 col = 0; col < shape_.
cols; ++col)
2485 returnArray[0] =
front();
2486 for (
uint32 i = 1; i < size_; ++i)
2488 returnArray[i] = returnArray[i - 1] + array_[i];
2499 for (
uint32 col = 1; col < shape_.
cols; ++col)
2510 for (
uint32 col = 0; col < shape_.
cols; ++col)
2579 std::vector<dtype> diagnolValues;
2580 int32 col = inOffset;
2588 if (col >=
static_cast<int32>(shape_.
cols))
2593 diagnolValues.push_back(
operator()(
row,
static_cast<uint32>(col)));
2601 std::vector<dtype> diagnolValues;
2603 for (
int32 row = inOffset; row < static_cast<int32>(shape_.
rows); ++
row)
2610 if (col >= shape_.
cols)
2615 diagnolValues.push_back(
operator()(
static_cast<uint32>(
row), col));
2647 if (shape_ == inOtherArray.shape_ && (shape_.
rows == 1 || shape_.
cols == 1))
2649 dtype dotProduct = std::inner_product(
cbegin(),
cend(), inOtherArray.
cbegin(), dtype{ 0 });
2653 if (shape_.
cols == inOtherArray.shape_.
rows)
2657 auto otherArrayT = inOtherArray.
transpose();
2661 for (
uint32 j = 0;
j < otherArrayT.shape_.rows; ++
j)
2663 returnArray(i,
j) = std::inner_product(otherArrayT.cbegin(
j), otherArrayT.cend(
j),
cbegin(i), dtype{ 0 });
2672 errStr +=
" are not consistent.";
2687 void dump(
const std::string& inFilename)
const
2695 std::ofstream ofile(
f.fullName().c_str(), std::ios::binary);
2701 if (array_ !=
nullptr)
2703 ofile.write(
reinterpret_cast<const char*
>(array_), size_ *
sizeof(dtype));
2751 std::vector<uint32> indices;
2753 for (
auto value : *
this)
2755 if (value != dtype{ 0 })
2757 indices.push_back(idx);
2882 return shape_.
rows == 1 || shape_.
cols == 1;
2896 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
2914 transposedArray.cend(
row), comparitor);
2982 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3011 transposedArray.
cend(
row), comparitor);
3039 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3068 transposedArray.
cend(
row), comparitor);
3098 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3114 const uint32 middleIdx = size_ / 2;
3117 dtype medianValue = copyArray.array_[middleIdx];
3120 const uint32 lhsIndex = middleIdx - 1;
3122 medianValue = (medianValue + copyArray.array_[lhsIndex]) / dtype{2};
3125 return { medianValue };
3132 const bool isEven = shape_.
cols % 2 == 0;
3137 copyArray.
end(
row), comparitor);
3139 dtype medianValue = copyArray(
row, middleIdx);
3142 const uint32 lhsIndex = middleIdx - 1;
3144 copyArray.
end(
row), comparitor);
3145 medianValue = (medianValue + copyArray(
row, lhsIndex)) / dtype{2};
3148 returnArray(0,
row) = medianValue;
3158 const bool isEven = shape_.
rows % 2 == 0;
3161 const uint32 middleIdx = transposedArray.shape_.
cols / 2;
3163 transposedArray.
end(
row), comparitor);
3165 dtype medianValue = transposedArray(
row, middleIdx);
3168 const uint32 lhsIndex = middleIdx - 1;
3170 transposedArray.
end(
row), comparitor);
3171 medianValue = (medianValue + transposedArray(
row, lhsIndex)) / dtype{2};
3174 returnArray(0,
row) = medianValue;
3211 return static_cast<uint64>(
sizeof(dtype) * size_);
3236 switch (inEndianess)
3270 switch (inEndianess)
3290 [](dtype value) noexcept -> dtype
3292 return boost::endian::native_to_little<dtype>(boost::endian::big_to_native<dtype>(value));
3308 switch (inEndianess)
3323 const auto function = [](dtype value) noexcept -> dtype
3325 return boost::endian::native_to_big<dtype>(boost::endian::little_to_native<dtype>(value));
3368 const auto function = [](dtype i) ->
bool
3370 return i != dtype{ 0 };
3492 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3513 if (inKth >= shape_.
cols)
3528 if (inKth >= shape_.
rows)
3539 transposedArray.
end(
row), comparitor);
3580 dtype product = std::accumulate(
cbegin(),
cend(),
3581 dtype{ 1 }, std::multiplies<dtype>());
3591 dtype{ 1 }, std::multiplies<dtype>());
3602 returnArray(0,
row) = std::accumulate(transposedArray.
cbegin(
row), transposedArray.
cend(
row),
3603 dtype{ 1 }, std::multiplies<dtype>());
3631 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
3650 returnArray(0,
row) = *result.second - *result.first;
3662 returnArray(0,
row) = *result.second - *result.first;
3686 at(inIndex) = inValue;
3703 at(inRow, inCol) = inValue;
3719 for (
auto index : inIndices)
3721 put(index, inValue);
3738 if (inIndices.
size() != inValues.
size())
3744 for (
auto index : inIndices)
3746 put(index, inValues[counter++]);
3763 Slice inSliceCopy(inSlice);
3785 Slice inSliceCopy(inSlice);
3788 std::vector<uint32> indices;
3791 indices.push_back(i);
3809 Slice inRowSliceCopy(inRowSlice);
3810 Slice inColSliceCopy(inColSlice);
3815 std::vector<uint32> indices;
3818 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3839 Slice inRowSliceCopy(inRowSlice);
3842 std::vector<uint32> indices;
3845 put(
row, inColIndex, inValue);
3863 Slice inColSliceCopy(inColSlice);
3866 std::vector<uint32> indices;
3867 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3869 put(inRowIndex, col, inValue);
3887 Slice inRowSliceCopy(inRowSlice);
3888 Slice inColSliceCopy(inColSlice);
3893 std::vector<uint32> indices;
3896 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3899 indices.push_back(index);
3918 Slice inRowSliceCopy(inRowSlice);
3921 std::vector<uint32> indices;
3925 indices.push_back(index);
3943 Slice inColSliceCopy(inColSlice);
3946 std::vector<uint32> indices;
3947 for (
int32 col = inColSliceCopy.
start; col < inColSliceCopy.
stop; col += inColSliceCopy.
step)
3949 const uint32 index = inRowIndex * shape_.
cols + col;
3950 indices.push_back(index);
3965 if (inMask.
shape() != shape_)
3982 if (inMask.
shape() != shape_)
4021 for (
uint32 col = 0; col < inNumCols; ++col)
4023 std::vector<uint32> indices(shape_.
size());
4029 const uint32 colEnd = (col + 1) * shape_.
cols;
4032 for (
uint32 rowIdx = rowStart; rowIdx < rowEnd; ++rowIdx)
4034 for (
uint32 colIdx = colStart; colIdx < colEnd; ++colIdx)
4036 indices[counter++] = rowIdx * returnArray.shape_.
cols + colIdx;
4090 if (inSize != size_)
4092 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4098 shape_.
cols = inSize;
4119 if (size_ % inNumCols == 0)
4121 return reshape(size_ / inNumCols, inNumCols);
4124 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4132 if (size_ % inNumRows == 0)
4134 return reshape(inNumRows, size_ / inNumRows);
4137 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into a shape ";
4143 if (
static_cast<uint32>(inNumRows * inNumCols) != size_)
4145 std::string errStr =
"Cannot reshape array of size " +
utils::num2str(size_) +
" into shape ";
4150 shape_.
rows =
static_cast<uint32>(inNumRows);
4151 shape_.
cols =
static_cast<uint32>(inNumCols);
4185 newArray(
Shape(inNumRows, inNumCols));
4218 std::vector<dtype> oldData(size_);
4221 const Shape inShape(inNumRows, inNumCols);
4222 const Shape oldShape = shape_;
4228 for (
uint32 col = 0; col < inShape.
cols; ++col)
4278 const double multFactor =
utils::power(10.0, inNumDecimals);
4279 const auto function = [multFactor](dtype value) noexcept -> dtype
4281 return static_cast<dtype
>(std::nearbyint(
static_cast<double>(value) * multFactor) / multFactor);
4345 const auto comparitor = [](dtype lhs, dtype rhs) noexcept ->
bool
4397 for (
uint32 col = 0; col < shape_.
cols; ++col)
4450 const Shape transShape = transposedArray.
shape();
4454 returnArray(0,
row) = std::accumulate(transposedArray.
cbegin(
row), transposedArray.
cend(
row), dtype{ 0 });
4494 void tofile(
const std::string& inFilename,
const std::string& inSep =
"")
const
4510 std::ofstream ofile(
f.fullName().c_str());
4517 for (
auto value : *
this)
4520 if (counter++ != size_ - 1)
4563 rowStart += inOffset;
4568 colStart += inOffset;
4579 if (rowStart >= shape_.
rows || colStart >= shape_.
cols)
4588 if (col >= shape_.
cols)
4612 for (
uint32 col = 0; col < shape_.
cols; ++col)
4636 Shape shape_{ 0, 0 };
4640 bool ownsPtr_{
false };
4646 void deleteArray() noexcept
4648 if (ownsPtr_ && array_ !=
nullptr)
4650 allocator_.deallocate(array_, size_);
4668 array_ = allocator_.allocate(size_);
4680 void newArray(
const Shape& inShape)
4685 size_ = inShape.size();
4692 template<
typename dtype,
class _Alloc>
4697 std::vector<uint32> rowIndices;
4698 std::vector<uint32> colIndices;
4700 for (
uint32 row = 0; row < shape_.rows; ++row)
4702 for (
uint32 col = 0; col < shape_.cols; ++col)
4704 if (
operator()(row, col) != dtype{ 0 })
4706 rowIndices.push_back(row);
4707 colIndices.push_back(col);
const_reverse_column_iterator rcolend() const noexcept
Definition: NdArrayCore.hpp:1722
#define STATIC_ASSERT_INTEGER(dtype)
Definition: StaticAsserts.hpp:40
std::reverse_iterator< const_column_iterator > const_reverse_column_iterator
Definition: NdArrayCore.hpp:101
const_reverse_iterator crbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1332
typename std::enable_if< B, T >::type enable_if_t
Definition: TypeTraits.hpp:40
value_type item() const
Definition: NdArrayCore.hpp:2957
column_iterator colbegin(size_type inCol)
Definition: NdArrayCore.hpp:1190
NdArray< bool > contains(value_type inValue, Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2347
int32 stop
Definition: Slice.hpp:48
NdArray< dtype > & put(int32 inRowIndex, const Slice &inColSlice, value_type inValue)
Definition: NdArrayCore.hpp:3861
const_iterator cend(size_type inRow) const
Definition: NdArrayCore.hpp:1504
NdArray< bool > any(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1839
std::vector< dtype > toStlVector() const
Definition: NdArrayCore.hpp:4536
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4311
std::int32_t int32
Definition: Types.hpp:36
NdArray< dtype > & operator=(NdArray< dtype > &&rhs) noexcept
Definition: NdArrayCore.hpp:617
Custom column iterator for NdArray.
Definition: NdArrayIterators.hpp:827
const_iterator cbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1160
std::reverse_iterator< column_iterator > reverse_column_iterator
Definition: NdArrayCore.hpp:100
NdArray(const NdArray< dtype > &inOtherArray)
Definition: NdArrayCore.hpp:522
void makePositiveAndValidate(uint32 inArraySize)
Definition: Slice.hpp:113
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
NdArray< dtype > dot(const NdArray< dtype > &inOtherArray) const
Definition: NdArrayCore.hpp:2643
NdArray< dtype > & sort(Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:4341
reference operator[](int32 inIndex) noexcept
Definition: NdArrayCore.hpp:645
NdArray< dtype > & put(const Slice &inRowSlice, const Slice &inColSlice, value_type inValue)
Definition: NdArrayCore.hpp:3807
NdArray< dtype > round(uint8 inNumDecimals=0) const
Definition: NdArrayCore.hpp:4273
NdArray< dtype > copy() const
Definition: NdArrayCore.hpp:2396
NdArray< dtype > at(int32 inRowIndex, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1077
reference back(size_type row)
Definition: NdArrayCore.hpp:2256
NdArray< dtype > & nans() noexcept
Definition: NdArrayCore.hpp:3192
const_iterator begin() const noexcept
Definition: NdArrayCore.hpp:1120
reference at(int32 inIndex)
Definition: NdArrayCore.hpp:919
NdArray< dtype > operator()(const Slice &inRowSlice, int32 inColIndex) const
Definition: NdArrayCore.hpp:840
value_type trace(uint32 inOffset=0, Axis inAxis=Axis::ROW) const noexcept
Definition: NdArrayCore.hpp:4553
NdArray< dtype > at(const Slice &inRowSlice, int32 inColIndex) const
Definition: NdArrayCore.hpp:1061
NdArray(std::vector< std::array< dtype, Dim1Size >> &in2dArray, bool copy=true)
Definition: NdArrayCore.hpp:329
NdArray(std::array< dtype, ArraySize > &inArray, bool copy=true)
Definition: NdArrayCore.hpp:212
NdArray< dtype > operator[](const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:755
NdArray< dtype > & reshape(const Shape &inShape)
Definition: NdArrayCore.hpp:4168
const_reverse_column_iterator crcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1418
NdArray< dtype > & resizeSlow(const Shape &inShape)
Definition: NdArrayCore.hpp:4256
NdArray(const std::initializer_list< dtype > &inList)
Definition: NdArrayCore.hpp:158
const dtype & const_reference
Definition: NdArrayCore.hpp:89
std::uint8_t uint8
Definition: Types.hpp:42
NdArray< dtype > & reshape(size_type inSize)
Definition: NdArrayCore.hpp:4088
std::uint64_t uint64
Definition: Types.hpp:39
NdArray< dtype > & put(int32 inRowIndex, const Slice &inColSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3941
void tofile(const std::string &inFilename, const std::string &inSep="") const
Definition: NdArrayCore.hpp:4494
std::string num2str(dtype inNumber)
Definition: num2str.hpp:46
bool issquare() const noexcept
Definition: NdArrayCore.hpp:2943
NdArray< dtype > prod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3572
NdArray< dtype > diagonal(int32 inOffset=0, Axis inAxis=Axis::ROW) const
Definition: NdArrayCore.hpp:2573
NdArray< dtype > & operator=(const NdArray< dtype > &rhs)
Definition: NdArrayCore.hpp:572
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:50
NdArray< dtype > & putMask(const NdArray< bool > &inMask, value_type inValue)
Definition: NdArrayCore.hpp:3963
const_reverse_iterator rend() const noexcept
Definition: NdArrayCore.hpp:1550
NdArrayConstColumnIterator< dtype, size_type, const_pointer, difference_type > const_column_iterator
Definition: NdArrayCore.hpp:99
const_reference at(int32 inRowIndex, int32 inColIndex) const
Definition: NdArrayCore.hpp:997
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4607
uint64 nbytes() const noexcept
Definition: NdArrayCore.hpp:3209
NdArray< dtype > & byteswap()
Definition: NdArrayCore.hpp:2270
NdArray< dtype > getByMask(const NdArray< bool > &inMask) const
Definition: NdArrayCore.hpp:2854
uint32 size_type
Definition: NdArrayCore.hpp:90
const_column_iterator ccolend() const noexcept
Definition: NdArrayCore.hpp:1662
const_reverse_iterator crend(size_type inRow) const
Definition: NdArrayCore.hpp:1590
const_reference at(int32 inIndex) const
Definition: NdArrayCore.hpp:942
NdArray< dtype > max(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2978
NdArray(const std::initializer_list< std::initializer_list< dtype > > &inList)
Definition: NdArrayCore.hpp:176
typename AllocTraits::const_pointer const_pointer
Definition: NdArrayCore.hpp:87
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:74
constexpr bool issquare() const noexcept
Definition: Core/Shape.hpp:123
NdArray< dtype > & put(const NdArray< uint32 > &inIndices, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3736
iterator end(size_type inRow)
Definition: NdArrayCore.hpp:1448
value_type front() const noexcept
Definition: NdArrayCore.hpp:2788
value_type back(size_type row) const
Definition: NdArrayCore.hpp:2244
reverse_column_iterator rcolend(size_type inCol)
Definition: NdArrayCore.hpp:1706
NdArray< dtype > & put(const Slice &inRowSlice, const Slice &inColSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3885
value_type back() const noexcept
Definition: NdArrayCore.hpp:2220
bool ownsInternalData() noexcept
Definition: NdArrayCore.hpp:3467
reference front() noexcept
Definition: NdArrayCore.hpp:2800
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: NdArrayCore.hpp:96
NdArray< dtype > at(const Slice &inSlice) const
Definition: NdArrayCore.hpp:1029
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:702
NdArray< dtype > clip(value_type inMin, value_type inMax) const
Definition: NdArrayCore.hpp:2311
constexpr auto j
Definition: Constants.hpp:45
std::uint32_t uint32
Definition: Types.hpp:40
Slice rSlice(int32 inStartIdx=0, uint32 inStepSize=1) const noexcept
Definition: NdArrayCore.hpp:905
NdArray(std::vector< dtype > &inVector, bool copy=true)
Definition: NdArrayCore.hpp:269
bool is_sorted(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:231
std::allocator< dtype > allocator_type
Definition: NdArrayCore.hpp:85
const_reverse_iterator crend() const noexcept
Definition: NdArrayCore.hpp:1576
const_column_iterator colend(size_type inCol) const
Definition: NdArrayCore.hpp:1650
Slice cSlice(int32 inStartIdx=0, uint32 inStepSize=1) const noexcept
Definition: NdArrayCore.hpp:890
uint32 numCols() const noexcept
Definition: NdArrayCore.hpp:3430
NdArrayIterator< dtype, pointer, difference_type > iterator
Definition: NdArrayCore.hpp:93
Custom column const_iterator for NdArray.
Definition: NdArrayIterators.hpp:496
std::string str() const
Definition: NdArrayCore.hpp:4388
column_iterator colend() noexcept
Definition: NdArrayCore.hpp:1606
NdArray< dtype > newbyteorder(Endian inEndianess) const
Definition: NdArrayCore.hpp:3228
pointer dataRelease() noexcept
Definition: NdArrayCore.hpp:2556
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:40
ForwardIt max_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:268
NdArray< dtype > & put(int32 inIndex, value_type inValue)
Definition: NdArrayCore.hpp:3684
NdArray< dtype > & reshape(int32 inNumRows, int32 inNumCols)
Definition: NdArrayCore.hpp:4115
bool all_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:57
const_column_iterator ccolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1246
int32 start
Definition: Slice.hpp:47
void fill(ForwardIt first, ForwardIt last, const T &value) noexcept
Definition: StlAlgorithms.hpp:174
#define STATIC_ASSERT_FLOAT(dtype)
Definition: StaticAsserts.hpp:43
NdArray< dtype > column(uint32 inColumn)
Definition: NdArrayCore.hpp:2333
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:95
bool isflat() const noexcept
Definition: NdArrayCore.hpp:2880
const_iterator end() const noexcept
Definition: NdArrayCore.hpp:1464
const_reverse_iterator rend(size_type inRow) const
Definition: NdArrayCore.hpp:1564
NdArray(const Shape &inShape)
Definition: NdArrayCore.hpp:144
column_iterator colbegin() noexcept
Definition: NdArrayCore.hpp:1176
column_iterator colend(size_type inCol)
Definition: NdArrayCore.hpp:1620
iterator end() noexcept
Definition: NdArrayCore.hpp:1434
Endian
Enum for endianess.
Definition: Types.hpp:50
const_reverse_iterator rbegin(size_type inRow) const
Definition: NdArrayCore.hpp:1306
NdArray(const_pointer inPtr, uint32 numRows, uint32 numCols)
Definition: NdArrayCore.hpp:465
size_type size() const noexcept
Definition: NdArrayCore.hpp:4325
uint32 cols
Definition: Core/Shape.hpp:45
reverse_column_iterator rcolend() noexcept
Definition: NdArrayCore.hpp:1692
NdArray< dtype > repeat(const Shape &inRepeatShape) const
Definition: NdArrayCore.hpp:4058
void dump(const std::string &inFilename) const
Definition: NdArrayCore.hpp:2687
NdArray< dtype > sum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:4426
NdArray< dtype > swapaxes() const
Definition: NdArrayCore.hpp:4476
const_reverse_iterator rbegin() const noexcept
Definition: NdArrayCore.hpp:1292
dtype & reference
Definition: NdArrayCore.hpp:88
NdArray< dtype > & operator=(value_type inValue) noexcept
Definition: NdArrayCore.hpp:598
NdArray< dtype > & put(const Slice &inRowSlice, int32 inColIndex, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3916
reverse_column_iterator rcolbegin() noexcept
Definition: NdArrayCore.hpp:1348
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1490
NdArray(NdArray< dtype > &&inOtherArray) noexcept
Definition: NdArrayCore.hpp:541
const_reverse_column_iterator rcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1736
uint32 numElements(uint32 inArraySize)
Definition: Slice.hpp:164
Axis
Enum To describe an axis.
Definition: Types.hpp:46
InputIt find(InputIt first, InputIt last, const T &value) noexcept
Definition: StlAlgorithms.hpp:195
#define THROW_RUNTIME_ERROR(msg)
Definition: Error.hpp:37
NdArray< dtype > & put(const Slice &inRowSlice, int32 inColIndex, value_type inValue)
Definition: NdArrayCore.hpp:3837
void nth_element(RandomIt first, RandomIt nth, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:397
std::reverse_iterator< iterator > reverse_iterator
Definition: NdArrayCore.hpp:95
const double nan
NaN.
Definition: Constants.hpp:44
reverse_iterator rend(size_type inRow)
Definition: NdArrayCore.hpp:1534
int32 step
Definition: Slice.hpp:49
NdArray< dtype > & put(const Slice &inSlice, value_type inValue)
Definition: NdArrayCore.hpp:3761
NdArray< dtype > & zeros() noexcept
Definition: NdArrayCore.hpp:4625
NdArray< dtype > flatten() const
Definition: NdArrayCore.hpp:2774
NdArray< dtype > & put(const Slice &inSlice, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3783
NdArray< dtype > cumsum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2476
NdArray< dtype > & ones() noexcept
Definition: NdArrayCore.hpp:3453
NdArray(const std::deque< dtype > &inDeque)
Definition: NdArrayCore.hpp:356
dtype value_type
Definition: NdArrayCore.hpp:84
Endian endianess() const noexcept
Definition: NdArrayCore.hpp:2715
NdArray(size_type inSquareSize)
Definition: NdArrayCore.hpp:116
Definition: Coordinate.hpp:44
const_column_iterator ccolbegin() const noexcept
Definition: NdArrayCore.hpp:1232
bool any_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:76
pointer data() noexcept
Definition: NdArrayCore.hpp:2534
const_column_iterator ccolend(size_type inCol) const
Definition: NdArrayCore.hpp:1676
const_reverse_column_iterator crcolbegin() const noexcept
Definition: NdArrayCore.hpp:1404
reverse_iterator rend() noexcept
Definition: NdArrayCore.hpp:1520
reference at(int32 inRowIndex, int32 inColIndex)
Definition: NdArrayCore.hpp:965
uint32 rows
Definition: Core/Shape.hpp:44
NdArray< dtype > operator()(int32 inRowIndex, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:865
NdArray< uint32 > argmin(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1956
std::int64_t int64
Definition: Types.hpp:35
void replace(ForwardIt first, ForwardIt last, const T &oldValue, const T &newValue) noexcept
Definition: StlAlgorithms.hpp:435
Custom const_iterator for NdArray.
Definition: NdArrayIterators.hpp:42
NdArray< dtype > operator[](const Slice &inSlice) const
Definition: NdArrayCore.hpp:732
NdArray< dtype > row(uint32 inRow)
Definition: NdArrayCore.hpp:4297
NdArrayColumnIterator< dtype, size_type, pointer, difference_type > column_iterator
Definition: NdArrayCore.hpp:98
NdArray(pointer inPtr, uint32 numRows, uint32 numCols, Bool takeOwnership) noexcept
Definition: NdArrayCore.hpp:508
NdArray< uint32 > argsort(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2015
NdArray< dtype > getByIndices(const NdArray< uint32 > &inIndices) const
Definition: NdArrayCore.hpp:2838
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
Custom iterator for NdArray.
Definition: NdArrayIterators.hpp:317
reverse_iterator rbegin() noexcept
Definition: NdArrayCore.hpp:1262
NdArray< dtype > & put(int32 inRow, int32 inCol, value_type inValue)
Definition: NdArrayCore.hpp:3701
constexpr uint32 size() const noexcept
Definition: Core/Shape.hpp:102
dtype power(dtype inValue, uint8 inPower) noexcept
Definition: Utils/power.hpp:48
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1146
NdArray< dtype > cumprod(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2412
void sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:629
NdArray(const std::deque< std::deque< dtype >> &in2dDeque)
Definition: NdArrayCore.hpp:373
const_iterator end(size_type inRow) const
Definition: NdArrayCore.hpp:1478
reference back() noexcept
Definition: NdArrayCore.hpp:2232
NdArray< dtypeOut > astype() const
Definition: NdArrayCore.hpp:2101
NdArrayConstIterator< dtype, const_pointer, difference_type > const_iterator
Definition: NdArrayCore.hpp:94
const_column_iterator colbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1220
NdArray(const std::vector< std::vector< dtype >> &in2dVector)
Definition: NdArrayCore.hpp:294
ForwardIt min_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:304
NdArray< dtype > & resizeFast(uint32 inNumRows, uint32 inNumCols)
Definition: NdArrayCore.hpp:4183
const_column_iterator colbegin() const noexcept
Definition: NdArrayCore.hpp:1206
const_reference operator()(int32 inRowIndex, int32 inColIndex) const noexcept
Definition: NdArrayCore.hpp:707
const_reverse_column_iterator crcolend(size_type inCol) const
Definition: NdArrayCore.hpp:1762
NdArray< uint32 > argmax(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1896
NdArray< uint32 > flatnonzero() const
Definition: NdArrayCore.hpp:2747
void replace(value_type oldValue, value_type newValue)
Definition: NdArrayCore.hpp:4070
reference operator()(int32 inRowIndex, int32 inColIndex) noexcept
Definition: NdArrayCore.hpp:683
void stable_sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:664
NdArray< dtype > & putMask(const NdArray< bool > &inMask, const NdArray< dtype > &inValues)
Definition: NdArrayCore.hpp:3980
const_reverse_column_iterator rcolbegin(size_type inCol) const
Definition: NdArrayCore.hpp:1392
NdArray< bool > none(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3364
std::pair< ForwardIt, ForwardIt > minmax_element(ForwardIt first, ForwardIt last) noexcept
Definition: StlAlgorithms.hpp:341
bool isempty() const noexcept
Definition: NdArrayCore.hpp:2867
value_type front(size_type row) const
Definition: NdArrayCore.hpp:2812
const_reverse_iterator crbegin() const noexcept
Definition: NdArrayCore.hpp:1318
std::pair< NdArray< uint32 >, NdArray< uint32 > > nonzero() const
Definition: NdArrayCore.hpp:4693
const_reverse_column_iterator rcolbegin() const noexcept
Definition: NdArrayCore.hpp:1378
NdArray(pointer inPtr, size_type size, Bool takeOwnership) noexcept
Definition: NdArrayCore.hpp:488
uint32 numRows() const noexcept
Definition: NdArrayCore.hpp:3443
reference front(size_type row)
Definition: NdArrayCore.hpp:2824
iterator begin() noexcept
Definition: NdArrayCore.hpp:1090
NdArray< dtype > at(const Slice &inRowSlice, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:1045
dtype f(dtype inDofN, dtype inDofD)
Definition: f.hpp:57
std::string value2str(dtype inValue)
Definition: value2str.hpp:48
reverse_iterator rbegin(size_type inRow)
Definition: NdArrayCore.hpp:1276
reverse_column_iterator rcolbegin(size_type inCol)
Definition: NdArrayCore.hpp:1362
A Class for slicing into NdArrays.
Definition: Slice.hpp:43
NdArray< dtype > & resizeFast(const Shape &inShape)
Definition: NdArrayCore.hpp:4199
NdArray< dtype > ptp(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3627
NdArray(const std::list< dtype > &inList)
Definition: NdArrayCore.hpp:406
const_reference operator[](int32 inIndex) const noexcept
Definition: NdArrayCore.hpp:664
const_pointer data() const noexcept
Definition: NdArrayCore.hpp:2544
NdArray< dtype > operator[](const NdArray< size_type > &inIndices) const
Definition: NdArrayCore.hpp:781
NdArray(std::array< std::array< dtype, Dim1Size >, Dim0Size > &in2dArray, bool copy=true)
Definition: NdArrayCore.hpp:240
NdArray(const_pointer inPtr, size_type size)
Definition: NdArrayCore.hpp:445
bool none_of(InputIt first, InputIt last, UnaryPredicate p) noexcept
Definition: StlAlgorithms.hpp:379
typename AllocTraits::pointer pointer
Definition: NdArrayCore.hpp:86
const_column_iterator colend() const noexcept
Definition: NdArrayCore.hpp:1636
NdArray< dtype > & partition(uint32 inKth, Axis inAxis=Axis::NONE)
Definition: NdArrayCore.hpp:3488
NdArray< bool > issorted(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:2892
const_reverse_column_iterator crcolend() const noexcept
Definition: NdArrayCore.hpp:1748
NdArray< dtype > & fill(value_type inFillValue) noexcept
Definition: NdArrayCore.hpp:2733
NdArray(Iterator inFirst, Iterator inLast)
Definition: NdArrayCore.hpp:426
NdArray< bool > all(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:1783
~NdArray() noexcept
Definition: NdArrayCore.hpp:558
const_iterator begin(size_type inRow) const
Definition: NdArrayCore.hpp:1134
NdArray< dtype > median(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3094
NdArray< dtype > & ravel() noexcept
Definition: NdArrayCore.hpp:3998
NdArray< dtype > repeat(uint32 inNumRows, uint32 inNumCols) const
Definition: NdArrayCore.hpp:4015
typename AllocTraits::difference_type difference_type
Definition: NdArrayCore.hpp:91
NdArray(size_type inNumRows, size_type inNumCols)
Definition: NdArrayCore.hpp:130
void print() const
Definition: NdArrayCore.hpp:3554
Provides simple filesystem functions.
Definition: Filesystem.hpp:39
NdArray< dtype > & put(const NdArray< uint32 > &inIndices, value_type inValue)
Definition: NdArrayCore.hpp:3717
iterator begin(size_type inRow)
Definition: NdArrayCore.hpp:1104
auto abs(dtype inValue) noexcept
Definition: abs.hpp:51
NdArray< dtype > & resizeSlow(uint32 inNumRows, uint32 inNumCols)
Definition: NdArrayCore.hpp:4216
NdArray< dtype > operator()(const Slice &inRowSlice, const Slice &inColSlice) const
Definition: NdArrayCore.hpp:808
NdArray< dtype > min(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:3035