NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
append.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <string>
31
34#include "NumCpp/Core/Types.hpp"
35#include "NumCpp/NdArray.hpp"
36
37namespace nc
38{
39 //============================================================================
40 // Method Description:
52 template<typename dtype>
54 {
55 if (inArray.shape().isnull())
56 {
57 return inAppendValues;
58 }
59 else if (inAppendValues.shape().isnull())
60 {
61 return inArray;
62 }
63
64 switch (inAxis)
65 {
66 case Axis::NONE:
67 {
69 stl_algorithms::copy(inArray.cbegin(), inArray.cend(), returnArray.begin());
71 inAppendValues.cend(),
72 returnArray.begin() + inArray.size());
73
74 return returnArray;
75 }
76 case Axis::ROW:
77 {
78 const Shape inShape = inArray.shape();
79 const Shape appendShape = inAppendValues.shape();
80 if (inShape.cols != appendShape.cols)
81 {
83 "all the input array dimensions except for the concatenation axis must match exactly");
84 }
85
87 stl_algorithms::copy(inArray.cbegin(), inArray.cend(), returnArray.begin());
89 inAppendValues.cend(),
90 returnArray.begin() + inArray.size());
91
92 return returnArray;
93 }
94 case Axis::COL:
95 {
96 const Shape inShape = inArray.shape();
97 const Shape appendShape = inAppendValues.shape();
98 if (inShape.rows != appendShape.rows)
99 {
101 "all the input array dimensions except for the concatenation axis must match exactly");
102 }
103
105 for (uint32 row = 0; row < returnArray.shape().rows; ++row)
106 {
107 stl_algorithms::copy(inArray.cbegin(row), inArray.cend(row), returnArray.begin(row));
109 inAppendValues.cend(row),
110 returnArray.begin(row) + inShape.cols);
111 }
112
113 return returnArray;
114 }
115 default:
116 {
117 THROW_INVALID_ARGUMENT_ERROR("Unimplemented axis type.");
118 return {}; // get rid of compiler warning
119 }
120 }
121 }
122} // 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:139
A Shape Class for NdArrays.
Definition Core/shape.hpp:41
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition StlAlgorithms.hpp:97
Definition Cartesian.hpp:40
Axis
Enum To describe an axis.
Definition Enums.hpp:36
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59
NdArray< dtype > append(const NdArray< dtype > &inArray, const NdArray< dtype > &inAppendValues, Axis inAxis=Axis::NONE)
Definition append.hpp:53
std::uint32_t uint32
Definition Types.hpp:40