NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
fillCorners.hpp
Go to the documentation of this file.
1
28#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
37{
38 //============================================================================
39 // Method Description:
45 template<typename dtype>
46 void fillCorners(NdArray<dtype>& inArray, uint32 inBorderWidth)
47 {
49
50 const Shape inShape = inArray.shape();
51 const auto numRows = static_cast<int32>(inShape.rows);
52 const auto numCols = static_cast<int32>(inShape.cols);
53
54 // top left
55 inArray.put(Slice(0, inBorderWidth), Slice(0, inBorderWidth), inArray(inBorderWidth, inBorderWidth));
56
57 // top right
58 inArray.put(Slice(0, inBorderWidth),
59 Slice(numCols - inBorderWidth, numCols),
60 inArray(inBorderWidth, numCols - inBorderWidth - 1));
61
62 // bottom left
63 inArray.put(Slice(numRows - inBorderWidth, numRows),
64 Slice(0, inBorderWidth),
65 inArray(numRows - inBorderWidth - 1, inBorderWidth));
66
67 // bottom right
68 inArray.put(Slice(numRows - inBorderWidth, numRows),
69 Slice(numCols - inBorderWidth, numCols),
70 inArray(numRows - inBorderWidth - 1, numCols - inBorderWidth - 1));
71 }
72
73 //============================================================================
74 // Method Description:
81 template<typename dtype>
82 void fillCorners(NdArray<dtype>& inArray, uint32 inBorderWidth, dtype inFillValue)
83 {
85
86 const Shape inShape = inArray.shape();
87 const auto numRows = static_cast<int32>(inShape.rows);
88 const auto numCols = static_cast<int32>(inShape.cols);
89
90 // top left
91 inArray.put(Slice(0, inBorderWidth), Slice(0, inBorderWidth), inFillValue);
92
93 // top right
94 inArray.put(Slice(0, inBorderWidth), Slice(numCols - inBorderWidth, numCols), inFillValue);
95
96 // bottom left
97 inArray.put(Slice(numRows - inBorderWidth, numRows), Slice(0, inBorderWidth), inFillValue);
98
99 // bottom right
100 inArray.put(Slice(numRows - inBorderWidth, numRows), Slice(numCols - inBorderWidth, numCols), inFillValue);
101 }
102} // namespace nc::filter::boundary
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:139
const Shape & shape() const noexcept
Definition: NdArrayCore.hpp:4511
self_type & put(index_type inIndex, const value_type &inValue)
Definition: NdArrayCore.hpp:3693
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:45
Definition: addBoundary1d.hpp:44
void fillCorners(NdArray< dtype > &inArray, uint32 inBorderWidth)
Definition: fillCorners.hpp:46
std::int32_t int32
Definition: Types.hpp:36
std::uint32_t uint32
Definition: Types.hpp:40