NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
linspace.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <string>
31
32#include "NumCpp/Core/Enums.hpp"
35#include "NumCpp/NdArray.hpp"
36
37namespace nc
38{
39 //============================================================================
40 // Method Description:
60 template<typename dtype>
62 {
64
65 if (inNum == 0)
66 {
67 return NdArray<dtype>(0);
68 }
69
70 if (inNum == 1)
71 {
73 return returnArray;
74 }
75
76 if (inStop <= inStart)
77 {
78 THROW_INVALID_ARGUMENT_ERROR("stop value must be greater than the start value.");
79 }
80
82 {
83 if (inNum == 2)
84 {
86 return returnArray;
87 }
88
90 returnArray.front() = inStart;
91 returnArray.back() = inStop;
92
93 dtype step = (inStop - inStart) / static_cast<dtype>(inNum - 1);
94
95 for (uint32 i = 1; i < inNum - 1; ++i)
96 {
97 returnArray[i] = inStart + static_cast<dtype>(i) * step;
98 }
99
100 return returnArray;
101 }
102
103 if (inNum == 2)
104 {
105 dtype step = (inStop - inStart) / (inNum);
107 return returnArray;
108 }
109
111 returnArray.front() = inStart;
112
113 dtype step = (inStop - inStart) / static_cast<dtype>(inNum);
114
115 for (uint32 i = 1; i < inNum; ++i)
116 {
117 returnArray[i] = inStart + static_cast<dtype>(i) * step;
118 }
119
120 return returnArray;
121 }
122} // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:139
Definition Cartesian.hpp:40
NdArray< dtype > linspace(dtype inStart, dtype inStop, uint32 inNum=50, EndPoint endPoint=EndPoint::YES)
Definition linspace.hpp:61
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59
std::uint32_t uint32
Definition Types.hpp:40
EndPoint
End Point boolean.
Definition Enums.hpp:74