NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
bartlett.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <cmath>
31
33#include "NumCpp/NdArray.hpp"
34
35namespace nc
36{
37 //============================================================================
38 // Method Description:
49 {
50 if (m < 1)
51 {
52 return {};
53 }
54
55 const auto mDouble = static_cast<double>(m);
56 const auto mMinus1Over2 = (mDouble - 1.) / 2.;
57 const auto mMinus1Over2Inv = 1. / mMinus1Over2;
58
59 NdArray<double> result(1, m);
60 int32 i = 0;
61 for (auto n : linspace(0., mDouble - 1., m, EndPoint::YES))
62 {
63 result[i++] = mMinus1Over2Inv * (mMinus1Over2 - std::abs(n - mMinus1Over2));
64 }
65
66 return result;
67 }
68} // namespace nc
Definition: Cartesian.hpp:40
NdArray< double > bartlett(int32 m)
Definition: bartlett.hpp:48
auto abs(dtype inValue) noexcept
Definition: abs.hpp:49
NdArray< dtype > linspace(dtype inStart, dtype inStop, uint32 inNum=50, EndPoint endPoint=EndPoint::YES)
Definition: linspace.hpp:61
std::int32_t int32
Definition: Types.hpp:36