Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
vec.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
21
22namespace sham {
23
24 template<class T>
26 using component_type = T;
27 static constexpr u32 dimension = 1;
28
29 static constexpr bool is_float_based = std::is_same<T, f16>::value
30 || std::is_same<T, f32>::value
31 || std::is_same<T, f64>::value;
32 static constexpr bool is_uint_based
33 = std::is_same<T, u8>::value || std::is_same<T, u16>::value
34 || std::is_same<T, u32>::value || std::is_same<T, u64>::value;
35 static constexpr bool is_int_based
36 = std::is_same<T, i8>::value || std::is_same<T, i16>::value
37 || std::is_same<T, i32>::value || std::is_same<T, i64>::value;
38
39 static constexpr bool has_info = is_float_based || is_int_based || is_uint_based;
40
41 static constexpr T get_min() {
42 return shambase::get_min<T>();
43 } // why this f***ing thing gives epsilon on float when you except -max
44 // aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah !!!!
45 static constexpr T get_max() { return shambase::get_max<T>(); }
46 static constexpr T get_inf() { return shambase::get_infty<T>(); }
47 static constexpr T get_zero() { return 0; }
48 };
49
50 template<class T, u32 dim>
51 struct VectorProperties<sycl::vec<T, dim>> {
52 using component_type = T;
53 static constexpr u32 dimension = dim;
54
55 static constexpr bool is_float_based = std::is_same<T, f16>::value
56 || std::is_same<T, f32>::value
57 || std::is_same<T, f64>::value;
58 static constexpr bool is_uint_based
59 = std::is_same<T, u8>::value || std::is_same<T, u16>::value
60 || std::is_same<T, u32>::value || std::is_same<T, u64>::value;
61 static constexpr bool is_int_based
62 = std::is_same<T, i8>::value || std::is_same<T, i16>::value
63 || std::is_same<T, i32>::value || std::is_same<T, i64>::value;
64 static constexpr bool has_info = is_float_based || is_int_based || is_uint_based;
65
66 static constexpr sycl::vec<T, dim> get_min() {
67 constexpr T min = shambase::get_min<T>();
68 if constexpr (dim == 2) {
69 return {min, min};
70 }
71 if constexpr (dim == 3) {
72 return {min, min, min};
73 }
74 if constexpr (dim == 4) {
75 return {min, min, min, min};
76 }
77 if constexpr (dim == 8) {
78 return {min, min, min, min, min, min, min, min};
79 }
80 if constexpr (dim == 16) {
81 return {
82 min, min, min, min, min, min, min, min, min, min, min, min, min, min, min, min};
83 }
84 }
85 static constexpr sycl::vec<T, dim> get_max() {
86 constexpr T max = shambase::get_max<T>();
87 if constexpr (dim == 2) {
88 return {max, max};
89 }
90 if constexpr (dim == 3) {
91 return {max, max, max};
92 }
93 if constexpr (dim == 4) {
94 return {max, max, max, max};
95 }
96 if constexpr (dim == 8) {
97 return {max, max, max, max, max, max, max, max};
98 }
99 if constexpr (dim == 16) {
100 return {
101 max, max, max, max, max, max, max, max, max, max, max, max, max, max, max, max};
102 }
103 }
104 static constexpr sycl::vec<T, dim> get_zero() {
105 constexpr T zero = 0;
106 if constexpr (dim == 2) {
107 return {zero, zero};
108 }
109 if constexpr (dim == 3) {
110 return {zero, zero, zero};
111 }
112 if constexpr (dim == 4) {
113 return {zero, zero, zero, zero};
114 }
115 if constexpr (dim == 8) {
116 return {zero, zero, zero, zero, zero, zero, zero, zero};
117 }
118 if constexpr (dim == 16) {
119 return {
120 zero,
121 zero,
122 zero,
123 zero,
124 zero,
125 zero,
126 zero,
127 zero,
128 zero,
129 zero,
130 zero,
131 zero,
132 zero,
133 zero,
134 zero,
135 zero};
136 }
137 }
138 };
139
140 template<class T>
141 using VecComponent = typename VectorProperties<T>::component_type;
142
143} // namespace sham
144
145namespace shambase {
146
147 template<class T>
148 using VectorProperties = sham::VectorProperties<T>;
149
150 template<class T>
151 using VecComponent = sham::VecComponent<T>;
152
153} // namespace shambase
std::uint32_t u32
32 bit unsigned integer
namespace for backends this one is named only sham since shambackends is too long to write
namespace for basic c++ utilities
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.