NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
eye.hpp
Go to the documentation of this file.
1
28#pragma once
29
31#include "NumCpp/Core/Shape.hpp"
32#include "NumCpp/Core/Types.hpp"
33#include "NumCpp/NdArray.hpp"
34
35namespace nc
36{
37 //============================================================================
38 // Method Description:
50 template<typename dtype>
52 {
54
55 NdArray<dtype> returnArray(inN, inM);
56 returnArray.zeros();
57
58 if (inK < 0)
59 {
60 uint32 col = 0;
61 for (uint32 row = inK; row < inN; ++row)
62 {
63 if (col >= inM)
64 {
65 break;
66 }
67
68 returnArray(row, col++) = dtype{ 1 };
69 }
70 }
71 else
72 {
73 uint32 row = 0;
74 for (uint32 col = inK; col < inM; ++col)
75 {
76 if (row >= inN)
77 {
78 break;
79 }
80
81 returnArray(row++, col) = dtype{ 1 };
82 }
83 }
84
85 return returnArray;
86 }
87
88 //============================================================================
89 // Method Description:
100 template<typename dtype>
102 {
103 return eye<dtype>(inN, inN, inK);
104 }
105
106 //============================================================================
107 // Method Description:
118 template<typename dtype>
119 NdArray<dtype> eye(const Shape& inShape, int32 inK = 0)
120 {
121 return eye<dtype>(inShape.rows, inShape.cols, inK);
122 }
123} // namespace nc
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:56
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:139
self_type & zeros() noexcept
Definition: NdArrayCore.hpp:4900
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
uint32 rows
Definition: Core/Shape.hpp:44
uint32 cols
Definition: Core/Shape.hpp:45
Definition: Cartesian.hpp:40
std::int32_t int32
Definition: Types.hpp:36
NdArray< dtype > eye(uint32 inN, uint32 inM, int32 inK=0)
Definition: eye.hpp:51
std::uint32_t uint32
Definition: Types.hpp:40