NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
diagflat.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <cmath>
31
33#include "NumCpp/Core/Types.hpp"
34#include "NumCpp/NdArray.hpp"
35
36namespace nc
37{
38 //============================================================================
39 // Method Description:
50 template<typename dtype>
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:56
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:139
size_type size() const noexcept
Definition: NdArrayCore.hpp:4524
self_type & zeros() noexcept
Definition: NdArrayCore.hpp:4900
Definition: Cartesian.hpp:40
auto abs(dtype inValue) noexcept
Definition: abs.hpp:49
NdArray< dtype > diagflat(const NdArray< dtype > &inArray, int32 k=0)
Definition: diagflat.hpp:51
std::int32_t int32
Definition: Types.hpp:36
std::uint32_t uint32
Definition: Types.hpp:40