NumCpp
1.0
A C++ implementation of the Python Numpy library
diagflat.hpp
Go to the documentation of this file.
1
#pragma once
30
31
#include "
NumCpp/NdArray.hpp
"
32
#include "
NumCpp/Core/Types.hpp
"
33
#include "
NumCpp/Core/Internal/StaticAsserts.hpp
"
34
35
#include <cmath>
36
37
namespace
nc
38
{
39
//============================================================================
40
// Method Description:
51
template
<
typename
dtype>
52
NdArray<dtype>
diagflat
(
const
NdArray<dtype>
& inArray,
int32
k = 0)
53
{
54
STATIC_ASSERT_ARITHMETIC_OR_COMPLEX
(dtype);
55
56
const
uint32
absK =
static_cast<
uint32
>
(
std::abs
(k));
57
NdArray<dtype>
returnArray(inArray.
size
() + absK);
58
59
const
uint32
rowOffset = k < 0 ? absK : 0;
60
const
uint32
colOffset = k > 0 ? absK : 0;
61
62
returnArray.
zeros
();
63
for
(
uint32
i = 0; i < inArray.
size
(); ++i)
64
{
65
returnArray(i + rowOffset, i + colOffset) = inArray[i];
66
}
67
68
return
returnArray;
69
}
70
}
StaticAsserts.hpp
nc::int32
std::int32_t int32
Definition:
Types.hpp:37
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::NdArray::size
size_type size() const noexcept
Definition:
NdArrayCore.hpp:4310
nc::NdArray::zeros
NdArray< dtype > & zeros() noexcept
Definition:
NdArrayCore.hpp:4609
nc::diagflat
NdArray< dtype > diagflat(const NdArray< dtype > &inArray, int32 k=0)
Definition:
diagflat.hpp:52
nc
Definition:
Coordinate.hpp:45
Types.hpp
nc::abs
auto abs(dtype inValue) noexcept
Definition:
abs.hpp:52
include
NumCpp
Functions
diagflat.hpp
Generated by
1.8.17