NumCpp
2.1.0
A C++ implementation of the Python Numpy library
row_stack.hpp
Go to the documentation of this file.
1
#pragma once
30
31
#include "
NumCpp/Core/Internal/Error.hpp
"
32
#include "
NumCpp/Core/Shape.hpp
"
33
#include "
NumCpp/Core/Types.hpp
"
34
#include "
NumCpp/NdArray.hpp
"
35
36
#include <initializer_list>
37
#include <string>
38
39
namespace
nc
40
{
41
//============================================================================
42
// Method Description:
51
template
<
typename
dtype>
52
NdArray<dtype>
row_stack
(
const
std::initializer_list<
NdArray<dtype>
>& inArrayList)
53
{
54
// first loop through to calculate the final size of the array
55
Shape
finalShape;
56
for
(
auto
& ndarray : inArrayList)
57
{
58
if
(finalShape.
isnull
())
59
{
60
finalShape = ndarray.shape();
61
}
62
else
if
(ndarray.shape().cols != finalShape.
cols
)
63
{
64
THROW_INVALID_ARGUMENT_ERROR
(
"input arrays must have the same number of columns."
);
65
}
66
else
67
{
68
finalShape.
rows
+= ndarray.shape().rows;
69
}
70
}
71
72
// now that we know the final size, contruct the output array
73
NdArray<dtype>
returnArray(finalShape);
74
uint32
rowStart = 0;
75
for
(
auto
& ndarray : inArrayList)
76
{
77
const
Shape
theShape = ndarray.shape();
78
for
(
uint32
row = 0; row < theShape.
rows
; ++row)
79
{
80
for
(
uint32
col = 0; col < theShape.
cols
; ++col)
81
{
82
returnArray(rowStart + row, col) = ndarray(row, col);
83
}
84
}
85
rowStart += theShape.
rows
;
86
}
87
88
return
returnArray;
89
}
90
}
// namespace nc
Error.hpp
nc::NdArray< dtype >
nc::uint32
std::uint32_t uint32
Definition:
Types.hpp:41
NdArray.hpp
nc::Shape
A Shape Class for NdArrays.
Definition:
Core/Shape.hpp:41
nc::Shape::cols
uint32 cols
Definition:
Core/Shape.hpp:46
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::Shape::rows
uint32 rows
Definition:
Core/Shape.hpp:45
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition:
Error.hpp:37
nc::Shape::isnull
constexpr bool isnull() const noexcept
Definition:
Core/Shape.hpp:114
Types.hpp
include
NumCpp
Functions
row_stack.hpp
Generated by
1.8.17