NumCpp  2.6.2
A Templatized Header Only C++ Implementation of the Python NumPy Library
concatenate.hpp
Go to the documentation of this file.
1 
28 #pragma once
29 
31 #include "NumCpp/Core/Shape.hpp"
32 #include "NumCpp/Core/Types.hpp"
35 
36 #include <initializer_list>
37 
38 namespace nc
39 {
40  //============================================================================
41  // Method Description:
51  template<typename dtype>
52  NdArray<dtype> concatenate(const std::initializer_list<NdArray<dtype> >& inArrayList, Axis inAxis = Axis::NONE)
53  {
54  switch (inAxis)
55  {
56  case Axis::NONE:
57  {
58  uint32 finalSize = 0;
59  for (auto& ndarray : inArrayList)
60  {
61  finalSize += ndarray.size();
62  }
63 
64  NdArray<dtype> returnArray(1, finalSize);
65  uint32 offset = 0;
66  for (auto& ndarray : inArrayList)
67  {
68  stl_algorithms::copy(ndarray.cbegin(), ndarray.cend(), returnArray.begin() + offset);
69  offset += ndarray.size();
70  }
71 
72  return returnArray;
73  }
74  case Axis::ROW:
75  {
76  return row_stack(inArrayList);
77  }
78  case Axis::COL:
79  {
80  return column_stack(inArrayList);
81  }
82  default:
83  {
84  THROW_INVALID_ARGUMENT_ERROR("Unimplemented axis type.");
85  return {}; // get rid of compiler warning
86  }
87  }
88  }
89 } // 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 begin() noexcept
Definition: NdArrayCore.hpp:1214
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:95
Definition: Coordinate.hpp:45
NdArray< dtype > concatenate(const std::initializer_list< NdArray< dtype > > &inArrayList, Axis inAxis=Axis::NONE)
Definition: concatenate.hpp:52
NdArray< dtype > row_stack(const std::initializer_list< NdArray< dtype > > &inArrayList)
Definition: row_stack.hpp:51
Axis
Enum To describe an axis.
Definition: Types.hpp:46
NdArray< dtype > column_stack(const std::initializer_list< NdArray< dtype > > &inArrayList)
Definition: column_stack.hpp:51
std::uint32_t uint32
Definition: Types.hpp:40