NumCpp  2.10.1
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  return flip(inArray.transpose(), Axis::COL).transpose();
69  }
70  default:
71  {
72  THROW_INVALID_ARGUMENT_ERROR("Unimplemented axis type.");
73  return {}; // get rid of compiler warning
74  }
75  }
76  }
77 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:138
iterator end() noexcept
Definition: NdArrayCore.hpp:1566
self_type transpose() const
Definition: NdArrayCore.hpp:4775
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4402
iterator begin() noexcept
Definition: NdArrayCore.hpp:1258
void reverse(BidirIt first, BidirIt last) noexcept
Definition: StlAlgorithms.hpp:488
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