NumCpp  1.0
A C++ implementation of the Python Numpy library
eye.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/NdArray.hpp"
32 #include "NumCpp/Core/Shape.hpp"
33 #include "NumCpp/Core/Types.hpp"
35 
36 namespace nc
37 {
38  //============================================================================
39  // Method Description:
52  template<typename dtype>
53  NdArray<dtype> eye(uint32 inN, uint32 inM, int32 inK = 0)
54  {
56 
57  NdArray<dtype> returnArray(inN, inM);
58  returnArray.zeros();
59 
60  if (inK < 0)
61  {
62  uint32 col = 0;
63  for (uint32 row = inK; row < inN; ++row)
64  {
65  if (col >= inM)
66  {
67  break;
68  }
69 
70  returnArray(row, col++) = dtype{ 1 };
71  }
72  }
73  else
74  {
75  uint32 row = 0;
76  for (uint32 col = inK; col < inM; ++col)
77  {
78  if (row >= inN)
79  {
80  break;
81  }
82 
83  returnArray(row++, col) = dtype{ 1 };
84  }
85  }
86 
87  return returnArray;
88  }
89 
90  //============================================================================
91  // Method Description:
103  template<typename dtype>
105  {
106  return eye<dtype>(inN, inN, inK);
107  }
108 
109  //============================================================================
110  // Method Description:
122  template<typename dtype>
123  NdArray<dtype> eye(const Shape& inShape, int32 inK = 0)
124  {
125  return eye<dtype>(inShape.rows, inShape.cols, inK);
126  }
127 }
StaticAsserts.hpp
nc::int32
std::int32_t int32
Definition: Types.hpp:37
nc::eye
NdArray< dtype > eye(uint32 inN, uint32 inM, int32 inK=0)
Definition: eye.hpp:53
STATIC_ASSERT_ARITHMETIC_OR_COMPLEX
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:51
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::Shape::cols
uint32 cols
Definition: Core/Shape.hpp:46
nc::NdArray::zeros
NdArray< dtype > & zeros() noexcept
Definition: NdArrayCore.hpp:4609
Shape.hpp
nc
Definition: Coordinate.hpp:45
nc::Shape::rows
uint32 rows
Definition: Core/Shape.hpp:45
Types.hpp