NumCpp  2.8.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
flip.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:
46  template<typename dtype>
47  NdArray<dtype> flip(const NdArray<dtype>& inArray, Axis inAxis = Axis::NONE)
48  {
49  switch (inAxis)
50  {
51  case Axis::NONE:
52  {
53  NdArray<dtype> returnArray(inArray);
54  stl_algorithms::reverse(returnArray.begin(), returnArray.end());
55  return returnArray;
56  }
57  case Axis::COL:
58  {
59  NdArray<dtype> returnArray(inArray);
60  for (uint32 row = 0; row < inArray.shape().rows; ++row)
61  {
62  stl_algorithms::reverse(returnArray.begin(row), returnArray.end(row));
63  }
64  return returnArray;
65  }
66  case Axis::ROW:
67  {
68  NdArray<dtype> returnArray = inArray.transpose();
69  for (uint32 row = 0; row < returnArray.shape().rows; ++row)
70  {
71  stl_algorithms::reverse(returnArray.begin(row), returnArray.end(row));
72  }
73  return returnArray.transpose();
74  }
75  default:
76  {
77  THROW_INVALID_ARGUMENT_ERROR("Unimplemented axis type.");
78  return {}; // get rid of compiler warning
79  }
80  }
81  }
82 } // 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
iterator end() noexcept
Definition: NdArrayCore.hpp:1479
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4276
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4650
iterator begin() noexcept
Definition: NdArrayCore.hpp:1171
void reverse(BidirIt first, BidirIt last) noexcept
Definition: StlAlgorithms.hpp:491
Definition: Coordinate.hpp:45
Axis
Enum To describe an axis.
Definition: Types.hpp:47
NdArray< dtype > flip(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: flip.hpp:47
std::uint32_t uint32
Definition: Types.hpp:40