NumCpp  2.8.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
take.hpp
Go to the documentation of this file.
1 #pragma once
29 
31 #include "NumCpp/Core/Types.hpp"
32 #include "NumCpp/NdArray.hpp"
33 
34 namespace nc
35 {
36  //============================================================================
37  // Method Description:
47  template<typename dtype,
48  typename Indices,
49  enable_if_t<is_same_v<Indices, NdArray<int32>> || is_same_v<Indices, NdArray<uint32>>, int> = 0>
50  NdArray<dtype> take(const NdArray<dtype>& inArray, const Indices& inIndices, Axis inAxis = Axis::NONE)
51  {
52  switch (inAxis)
53  {
54  case Axis::NONE:
55  {
56  return inArray[inIndices];
57  }
58  case Axis::ROW:
59  {
60  return inArray(inIndices, inArray.cSlice());
61  }
62  case Axis::COL:
63  {
64  return inArray(inArray.rSlice(), inIndices);
65  }
66  default:
67  {
68  THROW_INVALID_ARGUMENT_ERROR("Unimplemented axis type.");
69  return {}; // get rid of compiler warning
70  }
71  }
72  }
73 
74 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
Slice cSlice(int32 inStartIdx=0, uint32 inStepSize=1) const noexcept
Definition: NdArrayCore.hpp:969
Slice rSlice(int32 inStartIdx=0, uint32 inStepSize=1) const noexcept
Definition: NdArrayCore.hpp:983
Definition: Coordinate.hpp:45
Axis
Enum To describe an axis.
Definition: Types.hpp:47
NdArray< dtype > take(const NdArray< dtype > &inArray, const Indices &inIndices, Axis inAxis=Axis::NONE)
Definition: take.hpp:50