NumCpp  2.4.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
pad.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include "NumCpp/Core/Shape.hpp"
31 #include "NumCpp/Core/Slice.hpp"
32 #include "NumCpp/Core/Types.hpp"
33 #include "NumCpp/NdArray.hpp"
34 
35 namespace nc
36 {
37  //============================================================================
38  // Method Description:
49  template<typename dtype>
50  NdArray<dtype> pad(const NdArray<dtype>& inArray, uint16 inPadWidth, dtype inPadValue)
51  {
53 
54  const Shape inShape = inArray.shape();
55  Shape outShape(inShape);
56  outShape.rows += 2 * inPadWidth;
57  outShape.cols += 2 * inPadWidth;
58 
59  NdArray<dtype> returnArray(outShape);
60  returnArray.fill(inPadValue);
61  returnArray.put(Slice(inPadWidth, inPadWidth + inShape.rows), Slice(inPadWidth, inPadWidth + inShape.cols), inArray);
62 
63  return returnArray;
64  }
65 } // namespace nc
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4356
nc::pad
NdArray< dtype > pad(const NdArray< dtype > &inArray, uint16 inPadWidth, dtype inPadValue)
Definition: pad.hpp:50
STATIC_ASSERT_ARITHMETIC_OR_COMPLEX
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:50
nc::NdArray< dtype >
NdArray.hpp
nc::Shape
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:40
nc::NdArray::put
NdArray< dtype > & put(int32 inIndex, value_type inValue)
Definition: NdArrayCore.hpp:3729
nc::Shape::cols
uint32 cols
Definition: Core/Shape.hpp:45
Shape.hpp
nc
Definition: Coordinate.hpp:44
nc::Shape::rows
uint32 rows
Definition: Core/Shape.hpp:44
nc::uint16
std::uint16_t uint16
Definition: Types.hpp:41
Types.hpp
nc::Slice
A Class for slicing into NdArrays.
Definition: Slice.hpp:43
nc::NdArray::fill
NdArray< dtype > & fill(value_type inFillValue) noexcept
Definition: NdArrayCore.hpp:2751
Slice.hpp