NumCpp  1.0
A C++ implementation of the Python Numpy library
concatenate.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/Core/Shape.hpp"
33 #include "NumCpp/Core/Types.hpp"
36 
37 #include <initializer_list>
38 
39 namespace nc
40 {
41  //============================================================================
42  // Method Description:
52  template<typename dtype>
53  NdArray<dtype> concatenate(const std::initializer_list<NdArray<dtype> >& inArrayList, Axis inAxis = Axis::NONE)
54  {
55  switch (inAxis)
56  {
57  case Axis::NONE:
58  {
59  uint32 finalSize = 0;
60  for (auto& ndarray : inArrayList)
61  {
62  finalSize += ndarray.size();
63  }
64 
65  NdArray<dtype> returnArray(1, finalSize);
66  uint32 offset = 0;
67  for (auto& ndarray : inArrayList)
68  {
69  stl_algorithms::copy(ndarray.cbegin(), ndarray.cend(), returnArray.begin() + offset);
70  offset += ndarray.size();
71  }
72 
73  return returnArray;
74  }
75  case Axis::ROW:
76  {
77  return row_stack(inArrayList);
78  }
79  case Axis::COL:
80  {
81  return column_stack(inArrayList);
82  }
83  default:
84  {
85  // this isn't actually possible, just putting this here to get rid
86  // of the compiler warning.
87  return NdArray<dtype>(0);
88  }
89  }
90  }
91 }
nc::Axis::NONE
@ NONE
nc::Axis::ROW
@ ROW
column_stack.hpp
row_stack.hpp
nc::NdArray< dtype >
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:41
nc::column_stack
NdArray< dtype > column_stack(const std::initializer_list< NdArray< dtype > > &inArrayList)
Definition: column_stack.hpp:52
nc::stl_algorithms::copy
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition: StlAlgorithms.hpp:96
nc::Axis
Axis
Enum To describe an axis.
Definition: Types.hpp:47
nc::row_stack
NdArray< dtype > row_stack(const std::initializer_list< NdArray< dtype > > &inArrayList)
Definition: row_stack.hpp:52
Shape.hpp
nc
Definition: Coordinate.hpp:45
nc::concatenate
NdArray< dtype > concatenate(const std::initializer_list< NdArray< dtype > > &inArrayList, Axis inAxis=Axis::NONE)
Definition: concatenate.hpp:53
StlAlgorithms.hpp
Types.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091
nc::Axis::COL
@ COL