NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
geomspace.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include "NumCpp/Core/Enums.hpp"
36#include "NumCpp/NdArray.hpp"
38
39namespace nc
40{
41 //============================================================================
42 // Method Description:
58 template<typename dtype>
59 NdArray<double> geomspace(dtype start, dtype stop, uint32 num = 50, EndPoint endPoint = EndPoint::YES)
60 {
62
63 if (utils::essentiallyEqual(start, dtype{ 0 }))
64 {
65 THROW_INVALID_ARGUMENT_ERROR("Geometric sequence cannot include zero");
66 }
67
68 if (num == 1)
69 {
70 return { static_cast<double>(start) };
71 }
72 else if (num == 2 && endPoint == EndPoint::YES)
73 {
74 return { static_cast<double>(start), static_cast<double>(stop) };
75 }
76
77 const auto base = nth_root(stop / start, num - 1);
78 const auto logStart = logb(start, base);
79 const auto logStop = logb(stop, base);
80 return logspace(logStart, logStop, num, endPoint, base);
81 }
82} // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:56
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:49
Definition: Cartesian.hpp:40
auto logb(dtype inValue, dtype inBase) noexcept
Definition: logb.hpp:49
NdArray< double > geomspace(dtype start, dtype stop, uint32 num=50, EndPoint endPoint=EndPoint::YES)
Definition: geomspace.hpp:59
double nth_root(dtype1 inValue, dtype2 inRoot) noexcept
Definition: nth_root.hpp:46
std::uint32_t uint32
Definition: Types.hpp:40
NdArray< double > logspace(dtype start, dtype stop, uint32 num=50, EndPoint endPoint=EndPoint::YES, double base=10.)
Definition: logspace.hpp:59
EndPoint
End Point boolean.
Definition: Enums.hpp:74