VCTR
Loading...
Searching...
No Matches
Linspace.h
1/*
2 ==============================================================================
3 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5 Copyright 2022- by sonible GmbH.
6
7 This file is part of VCTR - Versatile Container Templates Reconceptualized.
8
9 VCTR is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License version 3
11 only, as published by the Free Software Foundation.
12
13 VCTR is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License version 3 for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 version 3 along with VCTR. If not, see <https://www.gnu.org/licenses/>.
20 ==============================================================================
21*/
22
23namespace vctr::generators
24{
27{
42 template <is::realNumber ElementType>
43 static Vector<ElementType> makeVector (ElementType start, ElementType stop, size_t num, bool includeEnd = true)
44 {
45 Vector<ElementType> dst (num);
46 dst.fillLinspace (start, stop, includeEnd);
47 return dst;
48 }
49
51 template <is::realNumber ElementType, size_t num>
52 static constexpr Array<ElementType, num> makeArray (ElementType start, ElementType stop, bool includeEnd = true)
53 {
55 dst.fillLinspace (start, stop, includeEnd);
56 return dst;
57 }
58
75 template <is::realNumber ElementType>
76 static Vector<ElementType> makeVector (ElementType start, ElementType stop, bool includeEnd = true)
77 {
78 const auto distance = stop - start;
79
80 VCTR_ASSERT (distance - std::floor (distance) == 0);
81
82 const auto num = std::abs (int (distance)) + 1;
83 return makeVector (start, stop, num, includeEnd);
84 }
85};
86} // namespace vctr::generators
The stack-based container type.
Definition: Array.h:53
constexpr void fillLinspace(ElementType start, ElementType stop, bool includeEnd=true)
Fills the vector with evenly spaced numbers between start and stop.
Definition: VctrBase.h:316
The heap-allocated container type.
Definition: Vector.h:99
Collection of static methods for generating evenly spaced numbers.
Definition: Linspace.h:27
static constexpr Array< ElementType, num > makeArray(ElementType start, ElementType stop, bool includeEnd=true)
Like makeVector, but returns an Array.
Definition: Linspace.h:52
static Vector< ElementType > makeVector(ElementType start, ElementType stop, size_t num, bool includeEnd=true)
Returns a Vector with evenly spaced numbers between start and stop.
Definition: Linspace.h:43
static Vector< ElementType > makeVector(ElementType start, ElementType stop, bool includeEnd=true)
Returns a Vector with values between start and stop and a step of 1.
Definition: Linspace.h:76