NumCpp  2.5.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
diagflat.hpp
Go to the documentation of this file.
1 #pragma once
29 
31 #include "NumCpp/Core/Types.hpp"
32 #include "NumCpp/NdArray.hpp"
33 
34 #include <cmath>
35 
36 namespace nc
37 {
38  //============================================================================
39  // Method Description:
50  template<typename dtype>
51  NdArray<dtype> diagflat(const NdArray<dtype>& inArray, int32 k = 0)
52  {
54 
55  const auto absK = static_cast<uint32>(std::abs(k));
56  NdArray<dtype> returnArray(inArray.size() + absK);
57 
58  const uint32 rowOffset = k < 0 ? absK : 0;
59  const uint32 colOffset = k > 0 ? absK : 0;
60 
61  returnArray.zeros();
62  for (uint32 i = 0; i < inArray.size(); ++i)
63  {
64  returnArray(i + rowOffset, i + colOffset) = inArray[i];
65  }
66 
67  return returnArray;
68  }
69 } // namespace nc
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:50
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
size_type size() const noexcept
Definition: NdArrayCore.hpp:4497
NdArray< dtype > & zeros() noexcept
Definition: NdArrayCore.hpp:4848
Definition: Coordinate.hpp:45
auto abs(dtype inValue) noexcept
Definition: abs.hpp:51
std::int32_t int32
Definition: Types.hpp:36
std::uint32_t uint32
Definition: Types.hpp:40
NdArray< dtype > diagflat(const NdArray< dtype > &inArray, int32 k=0)
Definition: diagflat.hpp:51