NumCpp
2.4.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
diagflat.hpp
Go to the documentation of this file.
1
#pragma once
29
30
#include "
NumCpp/Core/Internal/StaticAsserts.hpp
"
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
{
53
STATIC_ASSERT_ARITHMETIC_OR_COMPLEX
(dtype);
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
StaticAsserts.hpp
nc::int32
std::int32_t int32
Definition:
Types.hpp:36
STATIC_ASSERT_ARITHMETIC_OR_COMPLEX
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition:
StaticAsserts.hpp:50
nc::NdArray< dtype >
nc::uint32
std::uint32_t uint32
Definition:
Types.hpp:40
NdArray.hpp
nc::NdArray::size
size_type size() const noexcept
Definition:
NdArrayCore.hpp:4370
nc::NdArray::zeros
NdArray< dtype > & zeros() noexcept
Definition:
NdArrayCore.hpp:4670
nc::diagflat
NdArray< dtype > diagflat(const NdArray< dtype > &inArray, int32 k=0)
Definition:
diagflat.hpp:51
nc
Definition:
Coordinate.hpp:44
Types.hpp
nc::abs
auto abs(dtype inValue) noexcept
Definition:
abs.hpp:51
include
NumCpp
Functions
diagflat.hpp
Generated by
1.8.17