NumCpp
2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Toggle main menu visibility
Main Page
Related Pages
Namespaces
Namespace List
Namespace Members
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
z
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
z
Variables
a
c
d
e
g
h
i
j
m
n
o
p
s
t
v
Typedefs
Enumerations
Data Structures
Data Structures
Data Structure Index
Class Hierarchy
Data Fields
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
a
c
d
e
i
l
m
n
p
r
s
t
v
x
y
z
Typedefs
a
c
d
i
p
r
s
t
v
Enumerations
Related Symbols
Files
File List
Globals
All
Macros
Examples
•
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Loading...
Searching...
No Matches
linspace.hpp
Go to the documentation of this file.
1
28
#pragma once
29
30
#include <string>
31
32
#include "
NumCpp/Core/Enums.hpp
"
33
#include "
NumCpp/Core/Internal/Error.hpp
"
34
#include "
NumCpp/Core/Internal/StaticAsserts.hpp
"
35
#include "
NumCpp/NdArray.hpp
"
36
37
namespace
nc
38
{
39
//============================================================================
40
// Method Description:
60
template
<
typename
dtype>
61
NdArray<dtype>
linspace
(
dtype
inStart
,
dtype
inStop
,
uint32
inNum
= 50,
EndPoint
endPoint
=
EndPoint::YES
)
62
{
63
STATIC_ASSERT_ARITHMETIC
(
dtype
);
64
65
if
(
inNum
== 0)
66
{
67
return
NdArray<dtype>
(0);
68
}
69
70
if
(
inNum
== 1)
71
{
72
NdArray<dtype>
returnArray
= {
inStart
};
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
81
if
(
endPoint
==
EndPoint::YES
)
82
{
83
if
(
inNum
== 2)
84
{
85
NdArray<dtype>
returnArray
= {
inStart
,
inStop
};
86
return
returnArray
;
87
}
88
89
NdArray<dtype>
returnArray
(1,
inNum
);
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
);
106
NdArray<dtype>
returnArray
= {
inStart
,
inStart
+ step };
107
return
returnArray
;
108
}
109
110
NdArray<dtype>
returnArray
(1,
inNum
);
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
}
61
NdArray<dtype>
linspace
(
dtype
inStart
,
dtype
inStop
,
uint32
inNum
= 50,
EndPoint
endPoint
=
EndPoint::YES
) {
…
}
122
}
// namespace nc
Enums.hpp
Error.hpp
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition
Error.hpp:37
NdArray.hpp
StaticAsserts.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition
StaticAsserts.hpp:39
nc::NdArray
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition
NdArrayCore.hpp:139
nc
Definition
Cartesian.hpp:40
nc::linspace
NdArray< dtype > linspace(dtype inStart, dtype inStop, uint32 inNum=50, EndPoint endPoint=EndPoint::YES)
Definition
linspace.hpp:61
nc::arange
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition
arange.hpp:59
nc::uint32
std::uint32_t uint32
Definition
Types.hpp:40
nc::EndPoint
EndPoint
End Point boolean.
Definition
Enums.hpp:74
nc::EndPoint::YES
@ YES
include
NumCpp
Functions
linspace.hpp
Generated by
1.9.8