NumCpp  2.8.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
fillCorners.hpp
Go to the documentation of this file.
1 #pragma once
29 
31 #include "NumCpp/Core/Shape.hpp"
32 #include "NumCpp/Core/Slice.hpp"
33 #include "NumCpp/Core/Types.hpp"
34 #include "NumCpp/NdArray.hpp"
35 
36 namespace nc
37 {
38  namespace filter
39  {
40  namespace boundary
41  {
42  //============================================================================
43  // Method Description:
49  template<typename dtype>
50  void fillCorners(NdArray<dtype>& inArray, uint32 inBorderWidth)
51  {
53 
54  const Shape inShape = inArray.shape();
55  const auto numRows = static_cast<int32>(inShape.rows);
56  const auto numCols = static_cast<int32>(inShape.cols);
57 
58  // top left
59  inArray.put(Slice(0, inBorderWidth), Slice(0, inBorderWidth), inArray(inBorderWidth, inBorderWidth));
60 
61  // top right
62  inArray.put(Slice(0, inBorderWidth),
63  Slice(numCols - inBorderWidth, numCols),
64  inArray(inBorderWidth, numCols - inBorderWidth - 1));
65 
66  // bottom left
67  inArray.put(Slice(numRows - inBorderWidth, numRows),
68  Slice(0, inBorderWidth),
69  inArray(numRows - inBorderWidth - 1, inBorderWidth));
70 
71  // bottom right
72  inArray.put(Slice(numRows - inBorderWidth, numRows),
73  Slice(numCols - inBorderWidth, numCols),
74  inArray(numRows - inBorderWidth - 1, numCols - inBorderWidth - 1));
75  }
76 
77  //============================================================================
78  // Method Description:
85  template<typename dtype>
86  void fillCorners(NdArray<dtype>& inArray, uint32 inBorderWidth, dtype inFillValue)
87  {
89 
90  const Shape inShape = inArray.shape();
91  const auto numRows = static_cast<int32>(inShape.rows);
92  const auto numCols = static_cast<int32>(inShape.cols);
93 
94  // top left
95  inArray.put(Slice(0, inBorderWidth), Slice(0, inBorderWidth), inFillValue);
96 
97  // top right
98  inArray.put(Slice(0, inBorderWidth), Slice(numCols - inBorderWidth, numCols), inFillValue);
99 
100  // bottom left
101  inArray.put(Slice(numRows - inBorderWidth, numRows), Slice(0, inBorderWidth), inFillValue);
102 
103  // bottom right
104  inArray.put(Slice(numRows - inBorderWidth, numRows),
105  Slice(numCols - inBorderWidth, numCols),
106  inFillValue);
107  }
108  } // namespace boundary
109  } // namespace filter
110 } // namespace nc
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
NdArray< dtype > & put(int32 inIndex, value_type inValue)
Definition: NdArrayCore.hpp:3663
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4276
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
uint32 rows
Definition: Core/Shape.hpp:44
uint32 cols
Definition: Core/Shape.hpp:45
A Class for slicing into NdArrays.
Definition: Slice.hpp:44
void fillCorners(NdArray< dtype > &inArray, uint32 inBorderWidth)
Definition: fillCorners.hpp:50
Definition: Coordinate.hpp:45
std::int32_t int32
Definition: Types.hpp:36
std::uint32_t uint32
Definition: Types.hpp:40