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
arange.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <string>
31#include <vector>
32
35#include "NumCpp/NdArray.hpp"
36
37namespace nc
38{
39 //============================================================================
40 // Method Description:
58 template<typename dtype>
60 {
62
63 if (inStep > 0 && inStop < inStart)
64 {
65 THROW_INVALID_ARGUMENT_ERROR("stop value must be larger than the start value for positive step.");
66 }
67
69 {
70 THROW_INVALID_ARGUMENT_ERROR("start value must be larger than the stop value for negative step.");
71 }
72
73 std::vector<dtype> values;
74
76 auto counter = dtype{ 1 };
77
78 if (inStep > 0)
79 {
80 while (theValue < inStop)
81 {
82 values.push_back(theValue);
84 }
85 }
86 else
87 {
88 while (theValue > inStop)
89 {
90 values.push_back(theValue);
92 }
93 }
94
95 return NdArray<dtype>(values);
96 }
97
98 //============================================================================
99 // Method Description:
115 template<typename dtype>
117 {
118 if (inStop <= 0)
119 {
120 THROW_INVALID_ARGUMENT_ERROR("stop value must ge greater than 0.");
121 }
122
123 return arange<dtype>(0, inStop, 1);
124 }
125
126 //============================================================================
127 // Method Description:
143 template<typename dtype>
145 {
146 return arange<dtype>(inSlice.start, inSlice.stop, inSlice.step);
147 }
148} // 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
A Class for slicing into NdArrays.
Definition Slice.hpp:45
Definition Cartesian.hpp:40
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59