NumCpp  2.10.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
geomspace.hpp
Go to the documentation of this file.
1 #pragma once
29 
35 #include "NumCpp/NdArray.hpp"
37 
38 namespace nc
39 {
40  //============================================================================
41  // Method Description:
57  template<typename dtype>
58  NdArray<double> geomspace(dtype start, dtype stop, uint32 num = 50, bool endPoint = true)
59  {
61 
62  if (utils::essentiallyEqual(start, dtype{ 0 }))
63  {
64  THROW_INVALID_ARGUMENT_ERROR("Geometric sequence cannot include zero");
65  }
66 
67  if (num == 1)
68  {
69  return { static_cast<double>(start) };
70  }
71  else if (num == 2 && endPoint)
72  {
73  return { static_cast<double>(start), static_cast<double>(stop) };
74  }
75 
76  const auto base = nth_root(stop / start, num - 1);
77  const auto logStart = logb(start, base);
78  const auto logStop = logb(stop, base);
79  return logspace(logStart, logStop, num, endPoint, base);
80  }
81 } // 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:48
Definition: Coordinate.hpp:45
auto logb(dtype inValue, dtype inBase) noexcept
Definition: logb.hpp:49
NdArray< double > geomspace(dtype start, dtype stop, uint32 num=50, bool endPoint=true)
Definition: geomspace.hpp:58
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, bool endPoint=true, double base=10.)
Definition: logspace.hpp:57