NumCpp  2.1.0
A C++ implementation of the Python Numpy library
fillCorners.hpp
Go to the documentation of this file.
1 #pragma once
30 
32 #include "NumCpp/Core/Shape.hpp"
33 #include "NumCpp/Core/Slice.hpp"
34 #include "NumCpp/Core/Types.hpp"
35 #include "NumCpp/NdArray.hpp"
36 
37 namespace nc
38 {
39  namespace filter
40  {
41  namespace boundary
42  {
43  //============================================================================
44  // Method Description:
50  template<typename dtype>
51  void fillCorners(NdArray<dtype>& inArray, uint32 inBorderWidth)
52  {
54 
55  const Shape inShape = inArray.shape();
56  const auto numRows = static_cast<int32>(inShape.rows);
57  const auto numCols = static_cast<int32>(inShape.cols);
58 
59  // top left
60  inArray.put(Slice(0, inBorderWidth), Slice(0, inBorderWidth),
61  inArray(inBorderWidth, inBorderWidth));
62 
63  // top right
64  inArray.put(Slice(0, inBorderWidth), Slice(numCols - inBorderWidth, numCols),
65  inArray(inBorderWidth, numCols - inBorderWidth - 1));
66 
67  // bottom left
68  inArray.put(Slice(numRows - inBorderWidth, numRows), Slice(0, inBorderWidth),
69  inArray(numRows - inBorderWidth - 1, inBorderWidth));
70 
71  // bottom right
72  inArray.put(Slice(numRows - inBorderWidth, numRows), Slice(numCols - inBorderWidth, numCols),
73  inArray(numRows - inBorderWidth - 1, numCols - inBorderWidth - 1));
74  }
75 
76  //============================================================================
77  // Method Description:
84  template<typename dtype>
85  void fillCorners(NdArray<dtype>& inArray, uint32 inBorderWidth, dtype inFillValue)
86  {
88 
89  const Shape inShape = inArray.shape();
90  const auto numRows = static_cast<int32>(inShape.rows);
91  const auto numCols = static_cast<int32>(inShape.cols);
92 
93  // top left
94  inArray.put(Slice(0, inBorderWidth), Slice(0, inBorderWidth), inFillValue);
95 
96  // top right
97  inArray.put(Slice(0, inBorderWidth), Slice(numCols - inBorderWidth, numCols), inFillValue);
98 
99  // bottom left
100  inArray.put(Slice(numRows - inBorderWidth, numRows), Slice(0, inBorderWidth), inFillValue);
101 
102  // bottom right
103  inArray.put(Slice(numRows - inBorderWidth, numRows), Slice(numCols - inBorderWidth, numCols), inFillValue);
104  }
105  } // namespace boundary
106  } // namespace filter
107 } // namespace nc
StaticAsserts.hpp
nc::filter::boundary::fillCorners
void fillCorners(NdArray< dtype > &inArray, uint32 inBorderWidth)
Definition: fillCorners.hpp:51
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4312
nc::int32
std::int32_t int32
Definition: Types.hpp:37
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
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::NdArray::put
NdArray< dtype > & put(int32 inIndex, value_type inValue)
Definition: NdArrayCore.hpp:3685
nc::Shape::cols
uint32 cols
Definition: Core/Shape.hpp:46
Shape.hpp
nc
Definition: Coordinate.hpp:45
nc::Shape::rows
uint32 rows
Definition: Core/Shape.hpp:45
Types.hpp
nc::Slice
A Class for slicing into NdArrays.
Definition: Slice.hpp:44
Slice.hpp