NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
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>
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
A Shape Class for NdArrays.
Definition Core/shape.hpp:41
Definition Cartesian.hpp:40
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59
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