isce3 0.25.0
Loading...
Searching...
No Matches
Linspace.icc
1#ifndef ISCE_CORE_LINSPACE_ICC
2#error "Linspace.icc is an implementation detail of Linspace.h"
3#endif
4
5#include <cassert>
6
7namespace isce3 { namespace core {
8
9template<typename T>
10CUDA_HOSTDEV
11constexpr
14{
15 T spacing = (last - first) / (size - 1);
16 return {first, spacing, size};
17}
18
19template<typename T>
20CUDA_HOSTDEV
21constexpr
22Linspace<T>::Linspace(T first, T spacing, int size)
23:
24 _first(first),
25 _spacing(spacing),
26 _size(size)
27{
28 assert(size >= 0);
29}
30
31template<typename T>
32template<typename U>
33CUDA_HOSTDEV
34constexpr
35Linspace<T>::Linspace(const Linspace<U> & x)
36:
37 _first(x.first()),
38 _spacing(x.spacing()),
39 _size(x.size())
40{}
41
42template<typename T>
43template<typename U>
44CUDA_HOSTDEV
45constexpr
47Linspace<T>::operator=(const Linspace<U> & other)
48{
49 _first = other.first();
50 _spacing = other.spacing();
51 _size = other.size();
52 return *this;
53}
54
55template<typename T>
56CUDA_HOSTDEV
57constexpr
59{
60 assert(size >= 0);
61 _size = size;
62}
63
64template<typename T>
65CUDA_HOSTDEV
66constexpr
68Linspace<T>::subinterval(int start, int stop) const
69{
70 return {operator[](start), _spacing, stop - start};
71}
72
73template<typename T>
74template<typename U>
75CUDA_HOSTDEV
76constexpr
77int Linspace<T>::search(U val) const
78{
79 if (spacing() >= 0) {
80 if (val < first()) { return 0; }
81 if (val > last()) { return size(); }
82 }
83 else {
84 if (val > first()) { return 0; }
85 if (val < last()) { return size(); }
86 }
87
88 return (val - first()) / spacing() + 1;
89}
90
91template<typename T, typename U>
92CUDA_HOSTDEV
93constexpr
94bool operator==(const Linspace<T> & lhs, const Linspace<U> & rhs)
96 return lhs.first() == rhs.first() &&
97 lhs.spacing() == rhs.spacing() &&
98 lhs.size() == rhs.size();
99}
100
101template<typename T, typename U>
102CUDA_HOSTDEV
103constexpr
104bool operator!=(const Linspace<T> & lhs, const Linspace<U> & rhs)
105{
106 return !(lhs == rhs);
108
109}}
A uniformly-spaced sequence of values over some interval.
Definition Linspace.h:9
CUDA_HOSTDEV constexpr Linspace< T > subinterval(int start, int stop) const
Return a sub-Linspace over the half-open interval [start, stop).
Definition Linspace.icc:68
CUDA_HOSTDEV static constexpr Linspace< T > from_interval(T first, T last, int size)
Construct a Linspace over the closed interval [first, last].
Definition Linspace.icc:13
CUDA_HOSTDEV constexpr T spacing() const
Sample spacing.
Definition Linspace.h:76
CUDA_HOSTDEV constexpr T operator[](int pos) const
Return sample at the specified position.
Definition Linspace.h:56
CUDA_HOSTDEV constexpr void resize(int size)
Change the number of samples in the sequence.
Definition Linspace.icc:58
CUDA_HOSTDEV constexpr T last() const
Last sample.
Definition Linspace.h:71
CUDA_HOSTDEV constexpr int search(U) const
Return the position where the specified value would be inserted in the sequence in order to maintain ...
Definition Linspace.icc:77
CUDA_HOSTDEV constexpr int size() const
Number of samples.
Definition Linspace.h:86
CUDA_HOSTDEV constexpr T first() const
First sample.
Definition Linspace.h:61
base interpolator is an abstract base class
Definition BinarySearchFunc.cpp:5

Generated for ISCE3.0 by doxygen 1.13.2.