NumCpp  2.5.1
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),
60  inArray(inBorderWidth, inBorderWidth));
61 
62  // top right
63  inArray.put(Slice(0, inBorderWidth), Slice(numCols - inBorderWidth, numCols),
64  inArray(inBorderWidth, numCols - inBorderWidth - 1));
65 
66  // bottom left
67  inArray.put(Slice(numRows - inBorderWidth, numRows), Slice(0, inBorderWidth),
68  inArray(numRows - inBorderWidth - 1, inBorderWidth));
69 
70  // bottom right
71  inArray.put(Slice(numRows - inBorderWidth, numRows), Slice(numCols - inBorderWidth, numCols),
72  inArray(numRows - inBorderWidth - 1, numCols - inBorderWidth - 1));
73  }
74 
75  //============================================================================
76  // Method Description:
83  template<typename dtype>
84  void fillCorners(NdArray<dtype>& inArray, uint32 inBorderWidth, dtype inFillValue)
85  {
87 
88  const Shape inShape = inArray.shape();
89  const auto numRows = static_cast<int32>(inShape.rows);
90  const auto numCols = static_cast<int32>(inShape.cols);
91 
92  // top left
93  inArray.put(Slice(0, inBorderWidth), Slice(0, inBorderWidth), inFillValue);
94 
95  // top right
96  inArray.put(Slice(0, inBorderWidth), Slice(numCols - inBorderWidth, numCols), inFillValue);
97 
98  // bottom left
99  inArray.put(Slice(numRows - inBorderWidth, numRows), Slice(0, inBorderWidth), inFillValue);
100 
101  // bottom right
102  inArray.put(Slice(numRows - inBorderWidth, numRows), Slice(numCols - inBorderWidth, numCols), inFillValue);
103  }
104  } // namespace boundary
105  } // namespace filter
106 } // 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:3856
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4483
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