ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Limits.cuh
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <limits>
11 
12 #include "core/nns/kernel/Pair.cuh"
13 
14 namespace cloudViewer {
15 namespace core {
16 
17 template <typename T>
18 struct Limits {};
19 
20 // Unfortunately we can't use constexpr because there is no
21 // constexpr constructor for half
22 // FIXME: faiss CPU uses +/-FLT_MAX instead of +/-infinity
23 constexpr float kFloatMax = std::numeric_limits<float>::max();
24 constexpr float kFloatMin = std::numeric_limits<float>::lowest();
25 
26 template <>
27 struct Limits<float> {
28  static __device__ __host__ inline float getMin() { return kFloatMin; }
29  static __device__ __host__ inline float getMax() { return kFloatMax; }
30 };
31 
32 constexpr double kDoubleMax = std::numeric_limits<double>::max();
33 constexpr double kDoubleMin = std::numeric_limits<double>::lowest();
34 
35 template <>
36 struct Limits<double> {
37  static __device__ __host__ inline double getMin() { return kDoubleMin; }
38  static __device__ __host__ inline double getMax() { return kDoubleMax; }
39 };
40 
41 constexpr int kIntMax = std::numeric_limits<int>::max();
42 constexpr int kIntMin = std::numeric_limits<int>::lowest();
43 
44 template <>
45 struct Limits<int> {
46  static __device__ __host__ inline int getMin() { return kIntMin; }
47  static __device__ __host__ inline int getMax() { return kIntMax; }
48 };
49 
50 template <typename K, typename V>
51 struct Limits<Pair<K, V>> {
52  static __device__ __host__ inline Pair<K, V> getMin() {
53  return Pair<K, V>(Limits<K>::getMin(), Limits<V>::getMin());
54  }
55 
56  static __device__ __host__ inline Pair<K, V> getMax() {
57  return Pair<K, V>(Limits<K>::getMax(), Limits<V>::getMax());
58  }
59 };
60 
61 } // namespace core
62 } // namespace cloudViewer