NVIDIA DeepStream SDK API Reference

9.2 Release
sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 // Host and device math operations on CUDA vector types.
19 
20 #ifndef HELPER_MATH_H
21 #define HELPER_MATH_H
22 
23 #include "cuda_runtime.h"
24 
25 typedef unsigned int uint;
26 typedef unsigned short ushort;
27 
28 #ifndef __CUDACC__
29 #include <math.h>
30 
32 // Host implementations of CUDA functions.
34 
40 inline float fminf(float a, float b)
41 {
42  return a < b ? a : b;
43 }
44 
50 inline float fmaxf(float a, float b)
51 {
52  return a > b ? a : b;
53 }
54 
60 inline int max(int a, int b)
61 {
62  return a > b ? a : b;
63 }
64 
70 inline int min(int a, int b)
71 {
72  return a < b ? a : b;
73 }
74 
79 inline float rsqrtf(float x)
80 {
81  return 1.0f / sqrtf(x);
82 }
83 #endif
84 
86 // Constructors.
88 
93 inline __host__ __device__ float2 make_float2(float s)
94 {
95  return make_float2(s, s);
96 }
97 
102 inline __host__ __device__ float2 make_float2(float3 a)
103 {
104  return make_float2(a.x, a.y);
105 }
106 
111 inline __host__ __device__ float2 make_float2(int2 a)
112 {
113  return make_float2(float(a.x), float(a.y));
114 }
115 
120 inline __host__ __device__ float2 make_float2(uint2 a)
121 {
122  return make_float2(float(a.x), float(a.y));
123 }
124 
129 inline __host__ __device__ int2 make_int2(int s)
130 {
131  return make_int2(s, s);
132 }
133 
138 inline __host__ __device__ int2 make_int2(int3 a)
139 {
140  return make_int2(a.x, a.y);
141 }
142 
147 inline __host__ __device__ int2 make_int2(uint2 a)
148 {
149  return make_int2(int(a.x), int(a.y));
150 }
151 
156 inline __host__ __device__ int2 make_int2(float2 a)
157 {
158  return make_int2(int(a.x), int(a.y));
159 }
160 
165 inline __host__ __device__ uint2 make_uint2(uint s)
166 {
167  return make_uint2(s, s);
168 }
169 
174 inline __host__ __device__ uint2 make_uint2(uint3 a)
175 {
176  return make_uint2(a.x, a.y);
177 }
178 
183 inline __host__ __device__ uint2 make_uint2(int2 a)
184 {
185  return make_uint2(uint(a.x), uint(a.y));
186 }
187 
192 inline __host__ __device__ float3 make_float3(float s)
193 {
194  return make_float3(s, s, s);
195 }
196 
201 inline __host__ __device__ float3 make_float3(float2 a)
202 {
203  return make_float3(a.x, a.y, 0.0f);
204 }
205 
211 inline __host__ __device__ float3 make_float3(float2 a, float s)
212 {
213  return make_float3(a.x, a.y, s);
214 }
215 
220 inline __host__ __device__ float3 make_float3(float4 a)
221 {
222  return make_float3(a.x, a.y, a.z);
223 }
224 
229 inline __host__ __device__ float3 make_float3(int3 a)
230 {
231  return make_float3(float(a.x), float(a.y), float(a.z));
232 }
233 
238 inline __host__ __device__ float3 make_float3(uint3 a)
239 {
240  return make_float3(float(a.x), float(a.y), float(a.z));
241 }
242 
247 inline __host__ __device__ int3 make_int3(int s)
248 {
249  return make_int3(s, s, s);
250 }
251 
256 inline __host__ __device__ int3 make_int3(int2 a)
257 {
258  return make_int3(a.x, a.y, 0);
259 }
260 
266 inline __host__ __device__ int3 make_int3(int2 a, int s)
267 {
268  return make_int3(a.x, a.y, s);
269 }
270 
275 inline __host__ __device__ int3 make_int3(uint3 a)
276 {
277  return make_int3(int(a.x), int(a.y), int(a.z));
278 }
279 
284 inline __host__ __device__ int3 make_int3(float3 a)
285 {
286  return make_int3(int(a.x), int(a.y), int(a.z));
287 }
288 
293 inline __host__ __device__ uint3 make_uint3(uint s)
294 {
295  return make_uint3(s, s, s);
296 }
297 
302 inline __host__ __device__ uint3 make_uint3(uint2 a)
303 {
304  return make_uint3(a.x, a.y, 0);
305 }
306 
312 inline __host__ __device__ uint3 make_uint3(uint2 a, uint s)
313 {
314  return make_uint3(a.x, a.y, s);
315 }
316 
321 inline __host__ __device__ uint3 make_uint3(uint4 a)
322 {
323  return make_uint3(a.x, a.y, a.z);
324 }
325 
330 inline __host__ __device__ uint3 make_uint3(int3 a)
331 {
332  return make_uint3(uint(a.x), uint(a.y), uint(a.z));
333 }
334 
339 inline __host__ __device__ float4 make_float4(float s)
340 {
341  return make_float4(s, s, s, s);
342 }
343 
348 inline __host__ __device__ float4 make_float4(float3 a)
349 {
350  return make_float4(a.x, a.y, a.z, 0.0f);
351 }
352 
358 inline __host__ __device__ float4 make_float4(float3 a, float w)
359 {
360  return make_float4(a.x, a.y, a.z, w);
361 }
362 
367 inline __host__ __device__ float4 make_float4(int4 a)
368 {
369  return make_float4(float(a.x), float(a.y), float(a.z), float(a.w));
370 }
371 
376 inline __host__ __device__ float4 make_float4(uint4 a)
377 {
378  return make_float4(float(a.x), float(a.y), float(a.z), float(a.w));
379 }
380 
385 inline __host__ __device__ int4 make_int4(int s)
386 {
387  return make_int4(s, s, s, s);
388 }
389 
394 inline __host__ __device__ int4 make_int4(int3 a)
395 {
396  return make_int4(a.x, a.y, a.z, 0);
397 }
398 
404 inline __host__ __device__ int4 make_int4(int3 a, int w)
405 {
406  return make_int4(a.x, a.y, a.z, w);
407 }
408 
413 inline __host__ __device__ int4 make_int4(uint4 a)
414 {
415  return make_int4(int(a.x), int(a.y), int(a.z), int(a.w));
416 }
417 
422 inline __host__ __device__ int4 make_int4(float4 a)
423 {
424  return make_int4(int(a.x), int(a.y), int(a.z), int(a.w));
425 }
426 
431 inline __host__ __device__ uint4 make_uint4(uint s)
432 {
433  return make_uint4(s, s, s, s);
434 }
435 
440 inline __host__ __device__ uint4 make_uint4(uint3 a)
441 {
442  return make_uint4(a.x, a.y, a.z, 0);
443 }
444 
450 inline __host__ __device__ uint4 make_uint4(uint3 a, uint w)
451 {
452  return make_uint4(a.x, a.y, a.z, w);
453 }
454 
459 inline __host__ __device__ uint4 make_uint4(int4 a)
460 {
461  return make_uint4(uint(a.x), uint(a.y), uint(a.z), uint(a.w));
462 }
463 
465 // Negate.
467 
472 inline __host__ __device__ float2 operator-(float2 &a)
473 {
474  return make_float2(-a.x, -a.y);
475 }
476 
481 inline __host__ __device__ int2 operator-(int2 &a)
482 {
483  return make_int2(-a.x, -a.y);
484 }
485 
490 inline __host__ __device__ float3 operator-(float3 &a)
491 {
492  return make_float3(-a.x, -a.y, -a.z);
493 }
494 
499 inline __host__ __device__ int3 operator-(int3 &a)
500 {
501  return make_int3(-a.x, -a.y, -a.z);
502 }
503 
508 inline __host__ __device__ float4 operator-(float4 &a)
509 {
510  return make_float4(-a.x, -a.y, -a.z, -a.w);
511 }
512 
517 inline __host__ __device__ int4 operator-(int4 &a)
518 {
519  return make_int4(-a.x, -a.y, -a.z, -a.w);
520 }
521 
523 // Addition.
525 
531 inline __host__ __device__ float2 operator+(float2 a, float2 b)
532 {
533  return make_float2(a.x + b.x, a.y + b.y);
534 }
535 
541 inline __host__ __device__ void operator+=(float2 &a, float2 b)
542 {
543  a.x += b.x;
544  a.y += b.y;
545 }
546 
552 inline __host__ __device__ float2 operator+(float2 a, float b)
553 {
554  return make_float2(a.x + b, a.y + b);
555 }
556 
562 inline __host__ __device__ float2 operator+(float b, float2 a)
563 {
564  return make_float2(a.x + b, a.y + b);
565 }
566 
572 inline __host__ __device__ void operator+=(float2 &a, float b)
573 {
574  a.x += b;
575  a.y += b;
576 }
577 
583 inline __host__ __device__ int2 operator+(int2 a, int2 b)
584 {
585  return make_int2(a.x + b.x, a.y + b.y);
586 }
587 
593 inline __host__ __device__ void operator+=(int2 &a, int2 b)
594 {
595  a.x += b.x;
596  a.y += b.y;
597 }
598 
604 inline __host__ __device__ int2 operator+(int2 a, int b)
605 {
606  return make_int2(a.x + b, a.y + b);
607 }
608 
614 inline __host__ __device__ int2 operator+(int b, int2 a)
615 {
616  return make_int2(a.x + b, a.y + b);
617 }
618 
624 inline __host__ __device__ void operator+=(int2 &a, int b)
625 {
626  a.x += b;
627  a.y += b;
628 }
629 
635 inline __host__ __device__ uint2 operator+(uint2 a, uint2 b)
636 {
637  return make_uint2(a.x + b.x, a.y + b.y);
638 }
639 
645 inline __host__ __device__ void operator+=(uint2 &a, uint2 b)
646 {
647  a.x += b.x;
648  a.y += b.y;
649 }
650 
656 inline __host__ __device__ uint2 operator+(uint2 a, uint b)
657 {
658  return make_uint2(a.x + b, a.y + b);
659 }
660 
666 inline __host__ __device__ uint2 operator+(uint b, uint2 a)
667 {
668  return make_uint2(a.x + b, a.y + b);
669 }
670 
676 inline __host__ __device__ void operator+=(uint2 &a, uint b)
677 {
678  a.x += b;
679  a.y += b;
680 }
681 
687 inline __host__ __device__ float3 operator+(float3 a, float3 b)
688 {
689  return make_float3(a.x + b.x, a.y + b.y, a.z + b.z);
690 }
691 
697 inline __host__ __device__ void operator+=(float3 &a, float3 b)
698 {
699  a.x += b.x;
700  a.y += b.y;
701  a.z += b.z;
702 }
703 
709 inline __host__ __device__ float3 operator+(float3 a, float b)
710 {
711  return make_float3(a.x + b, a.y + b, a.z + b);
712 }
713 
719 inline __host__ __device__ void operator+=(float3 &a, float b)
720 {
721  a.x += b;
722  a.y += b;
723  a.z += b;
724 }
725 
731 inline __host__ __device__ int3 operator+(int3 a, int3 b)
732 {
733  return make_int3(a.x + b.x, a.y + b.y, a.z + b.z);
734 }
735 
741 inline __host__ __device__ void operator+=(int3 &a, int3 b)
742 {
743  a.x += b.x;
744  a.y += b.y;
745  a.z += b.z;
746 }
747 
753 inline __host__ __device__ int3 operator+(int3 a, int b)
754 {
755  return make_int3(a.x + b, a.y + b, a.z + b);
756 }
757 
763 inline __host__ __device__ void operator+=(int3 &a, int b)
764 {
765  a.x += b;
766  a.y += b;
767  a.z += b;
768 }
769 
775 inline __host__ __device__ uint3 operator+(uint3 a, uint3 b)
776 {
777  return make_uint3(a.x + b.x, a.y + b.y, a.z + b.z);
778 }
779 
785 inline __host__ __device__ void operator+=(uint3 &a, uint3 b)
786 {
787  a.x += b.x;
788  a.y += b.y;
789  a.z += b.z;
790 }
791 
797 inline __host__ __device__ uint3 operator+(uint3 a, uint b)
798 {
799  return make_uint3(a.x + b, a.y + b, a.z + b);
800 }
801 
807 inline __host__ __device__ void operator+=(uint3 &a, uint b)
808 {
809  a.x += b;
810  a.y += b;
811  a.z += b;
812 }
813 
819 inline __host__ __device__ int3 operator+(int b, int3 a)
820 {
821  return make_int3(a.x + b, a.y + b, a.z + b);
822 }
823 
829 inline __host__ __device__ uint3 operator+(uint b, uint3 a)
830 {
831  return make_uint3(a.x + b, a.y + b, a.z + b);
832 }
833 
839 inline __host__ __device__ float3 operator+(float b, float3 a)
840 {
841  return make_float3(a.x + b, a.y + b, a.z + b);
842 }
843 
849 inline __host__ __device__ float4 operator+(float4 a, float4 b)
850 {
851  return make_float4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
852 }
853 
859 inline __host__ __device__ void operator+=(float4 &a, float4 b)
860 {
861  a.x += b.x;
862  a.y += b.y;
863  a.z += b.z;
864  a.w += b.w;
865 }
866 
872 inline __host__ __device__ float4 operator+(float4 a, float b)
873 {
874  return make_float4(a.x + b, a.y + b, a.z + b, a.w + b);
875 }
876 
882 inline __host__ __device__ float4 operator+(float b, float4 a)
883 {
884  return make_float4(a.x + b, a.y + b, a.z + b, a.w + b);
885 }
886 
892 inline __host__ __device__ void operator+=(float4 &a, float b)
893 {
894  a.x += b;
895  a.y += b;
896  a.z += b;
897  a.w += b;
898 }
899 
905 inline __host__ __device__ int4 operator+(int4 a, int4 b)
906 {
907  return make_int4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
908 }
909 
915 inline __host__ __device__ void operator+=(int4 &a, int4 b)
916 {
917  a.x += b.x;
918  a.y += b.y;
919  a.z += b.z;
920  a.w += b.w;
921 }
922 
928 inline __host__ __device__ int4 operator+(int4 a, int b)
929 {
930  return make_int4(a.x + b, a.y + b, a.z + b, a.w + b);
931 }
932 
938 inline __host__ __device__ int4 operator+(int b, int4 a)
939 {
940  return make_int4(a.x + b, a.y + b, a.z + b, a.w + b);
941 }
942 
948 inline __host__ __device__ void operator+=(int4 &a, int b)
949 {
950  a.x += b;
951  a.y += b;
952  a.z += b;
953  a.w += b;
954 }
955 
961 inline __host__ __device__ uint4 operator+(uint4 a, uint4 b)
962 {
963  return make_uint4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
964 }
965 
971 inline __host__ __device__ void operator+=(uint4 &a, uint4 b)
972 {
973  a.x += b.x;
974  a.y += b.y;
975  a.z += b.z;
976  a.w += b.w;
977 }
978 
984 inline __host__ __device__ uint4 operator+(uint4 a, uint b)
985 {
986  return make_uint4(a.x + b, a.y + b, a.z + b, a.w + b);
987 }
988 
994 inline __host__ __device__ uint4 operator+(uint b, uint4 a)
995 {
996  return make_uint4(a.x + b, a.y + b, a.z + b, a.w + b);
997 }
998 
1004 inline __host__ __device__ void operator+=(uint4 &a, uint b)
1005 {
1006  a.x += b;
1007  a.y += b;
1008  a.z += b;
1009  a.w += b;
1010 }
1011 
1013 // Subtract.
1015 
1021 inline __host__ __device__ float2 operator-(float2 a, float2 b)
1022 {
1023  return make_float2(a.x - b.x, a.y - b.y);
1024 }
1025 
1031 inline __host__ __device__ void operator-=(float2 &a, float2 b)
1032 {
1033  a.x -= b.x;
1034  a.y -= b.y;
1035 }
1036 
1042 inline __host__ __device__ float2 operator-(float2 a, float b)
1043 {
1044  return make_float2(a.x - b, a.y - b);
1045 }
1046 
1052 inline __host__ __device__ float2 operator-(float b, float2 a)
1053 {
1054  return make_float2(b - a.x, b - a.y);
1055 }
1056 
1062 inline __host__ __device__ void operator-=(float2 &a, float b)
1063 {
1064  a.x -= b;
1065  a.y -= b;
1066 }
1067 
1073 inline __host__ __device__ int2 operator-(int2 a, int2 b)
1074 {
1075  return make_int2(a.x - b.x, a.y - b.y);
1076 }
1077 
1083 inline __host__ __device__ void operator-=(int2 &a, int2 b)
1084 {
1085  a.x -= b.x;
1086  a.y -= b.y;
1087 }
1088 
1094 inline __host__ __device__ int2 operator-(int2 a, int b)
1095 {
1096  return make_int2(a.x - b, a.y - b);
1097 }
1098 
1104 inline __host__ __device__ int2 operator-(int b, int2 a)
1105 {
1106  return make_int2(b - a.x, b - a.y);
1107 }
1108 
1114 inline __host__ __device__ void operator-=(int2 &a, int b)
1115 {
1116  a.x -= b;
1117  a.y -= b;
1118 }
1119 
1125 inline __host__ __device__ uint2 operator-(uint2 a, uint2 b)
1126 {
1127  return make_uint2(a.x - b.x, a.y - b.y);
1128 }
1129 
1135 inline __host__ __device__ void operator-=(uint2 &a, uint2 b)
1136 {
1137  a.x -= b.x;
1138  a.y -= b.y;
1139 }
1140 
1146 inline __host__ __device__ uint2 operator-(uint2 a, uint b)
1147 {
1148  return make_uint2(a.x - b, a.y - b);
1149 }
1150 
1156 inline __host__ __device__ uint2 operator-(uint b, uint2 a)
1157 {
1158  return make_uint2(b - a.x, b - a.y);
1159 }
1160 
1166 inline __host__ __device__ void operator-=(uint2 &a, uint b)
1167 {
1168  a.x -= b;
1169  a.y -= b;
1170 }
1171 
1177 inline __host__ __device__ float3 operator-(float3 a, float3 b)
1178 {
1179  return make_float3(a.x - b.x, a.y - b.y, a.z - b.z);
1180 }
1181 
1187 inline __host__ __device__ void operator-=(float3 &a, float3 b)
1188 {
1189  a.x -= b.x;
1190  a.y -= b.y;
1191  a.z -= b.z;
1192 }
1193 
1199 inline __host__ __device__ float3 operator-(float3 a, float b)
1200 {
1201  return make_float3(a.x - b, a.y - b, a.z - b);
1202 }
1203 
1209 inline __host__ __device__ float3 operator-(float b, float3 a)
1210 {
1211  return make_float3(b - a.x, b - a.y, b - a.z);
1212 }
1213 
1219 inline __host__ __device__ void operator-=(float3 &a, float b)
1220 {
1221  a.x -= b;
1222  a.y -= b;
1223  a.z -= b;
1224 }
1225 
1231 inline __host__ __device__ int3 operator-(int3 a, int3 b)
1232 {
1233  return make_int3(a.x - b.x, a.y - b.y, a.z - b.z);
1234 }
1235 
1241 inline __host__ __device__ void operator-=(int3 &a, int3 b)
1242 {
1243  a.x -= b.x;
1244  a.y -= b.y;
1245  a.z -= b.z;
1246 }
1247 
1253 inline __host__ __device__ int3 operator-(int3 a, int b)
1254 {
1255  return make_int3(a.x - b, a.y - b, a.z - b);
1256 }
1257 
1263 inline __host__ __device__ int3 operator-(int b, int3 a)
1264 {
1265  return make_int3(b - a.x, b - a.y, b - a.z);
1266 }
1267 
1273 inline __host__ __device__ void operator-=(int3 &a, int b)
1274 {
1275  a.x -= b;
1276  a.y -= b;
1277  a.z -= b;
1278 }
1279 
1285 inline __host__ __device__ uint3 operator-(uint3 a, uint3 b)
1286 {
1287  return make_uint3(a.x - b.x, a.y - b.y, a.z - b.z);
1288 }
1289 
1295 inline __host__ __device__ void operator-=(uint3 &a, uint3 b)
1296 {
1297  a.x -= b.x;
1298  a.y -= b.y;
1299  a.z -= b.z;
1300 }
1301 
1307 inline __host__ __device__ uint3 operator-(uint3 a, uint b)
1308 {
1309  return make_uint3(a.x - b, a.y - b, a.z - b);
1310 }
1311 
1317 inline __host__ __device__ uint3 operator-(uint b, uint3 a)
1318 {
1319  return make_uint3(b - a.x, b - a.y, b - a.z);
1320 }
1321 
1327 inline __host__ __device__ void operator-=(uint3 &a, uint b)
1328 {
1329  a.x -= b;
1330  a.y -= b;
1331  a.z -= b;
1332 }
1333 
1339 inline __host__ __device__ float4 operator-(float4 a, float4 b)
1340 {
1341  return make_float4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
1342 }
1343 
1349 inline __host__ __device__ void operator-=(float4 &a, float4 b)
1350 {
1351  a.x -= b.x;
1352  a.y -= b.y;
1353  a.z -= b.z;
1354  a.w -= b.w;
1355 }
1356 
1362 inline __host__ __device__ float4 operator-(float4 a, float b)
1363 {
1364  return make_float4(a.x - b, a.y - b, a.z - b, a.w - b);
1365 }
1366 
1372 inline __host__ __device__ void operator-=(float4 &a, float b)
1373 {
1374  a.x -= b;
1375  a.y -= b;
1376  a.z -= b;
1377  a.w -= b;
1378 }
1379 
1385 inline __host__ __device__ int4 operator-(int4 a, int4 b)
1386 {
1387  return make_int4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
1388 }
1389 
1395 inline __host__ __device__ void operator-=(int4 &a, int4 b)
1396 {
1397  a.x -= b.x;
1398  a.y -= b.y;
1399  a.z -= b.z;
1400  a.w -= b.w;
1401 }
1402 
1408 inline __host__ __device__ int4 operator-(int4 a, int b)
1409 {
1410  return make_int4(a.x - b, a.y - b, a.z - b, a.w - b);
1411 }
1412 
1418 inline __host__ __device__ int4 operator-(int b, int4 a)
1419 {
1420  return make_int4(b - a.x, b - a.y, b - a.z, b - a.w);
1421 }
1422 
1428 inline __host__ __device__ void operator-=(int4 &a, int b)
1429 {
1430  a.x -= b;
1431  a.y -= b;
1432  a.z -= b;
1433  a.w -= b;
1434 }
1435 
1441 inline __host__ __device__ uint4 operator-(uint4 a, uint4 b)
1442 {
1443  return make_uint4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
1444 }
1445 
1451 inline __host__ __device__ void operator-=(uint4 &a, uint4 b)
1452 {
1453  a.x -= b.x;
1454  a.y -= b.y;
1455  a.z -= b.z;
1456  a.w -= b.w;
1457 }
1458 
1464 inline __host__ __device__ uint4 operator-(uint4 a, uint b)
1465 {
1466  return make_uint4(a.x - b, a.y - b, a.z - b, a.w - b);
1467 }
1468 
1474 inline __host__ __device__ uint4 operator-(uint b, uint4 a)
1475 {
1476  return make_uint4(b - a.x, b - a.y, b - a.z, b - a.w);
1477 }
1478 
1484 inline __host__ __device__ void operator-=(uint4 &a, uint b)
1485 {
1486  a.x -= b;
1487  a.y -= b;
1488  a.z -= b;
1489  a.w -= b;
1490 }
1491 
1493 // Multiply.
1495 
1501 inline __host__ __device__ float2 operator*(float2 a, float2 b)
1502 {
1503  return make_float2(a.x * b.x, a.y * b.y);
1504 }
1505 
1511 inline __host__ __device__ void operator*=(float2 &a, float2 b)
1512 {
1513  a.x *= b.x;
1514  a.y *= b.y;
1515 }
1516 
1522 inline __host__ __device__ float2 operator*(float2 a, float b)
1523 {
1524  return make_float2(a.x * b, a.y * b);
1525 }
1526 
1532 inline __host__ __device__ float2 operator*(float b, float2 a)
1533 {
1534  return make_float2(b * a.x, b * a.y);
1535 }
1536 
1542 inline __host__ __device__ void operator*=(float2 &a, float b)
1543 {
1544  a.x *= b;
1545  a.y *= b;
1546 }
1547 
1553 inline __host__ __device__ int2 operator*(int2 a, int2 b)
1554 {
1555  return make_int2(a.x * b.x, a.y * b.y);
1556 }
1557 
1563 inline __host__ __device__ void operator*=(int2 &a, int2 b)
1564 {
1565  a.x *= b.x;
1566  a.y *= b.y;
1567 }
1568 
1574 inline __host__ __device__ int2 operator*(int2 a, int b)
1575 {
1576  return make_int2(a.x * b, a.y * b);
1577 }
1578 
1584 inline __host__ __device__ int2 operator*(int b, int2 a)
1585 {
1586  return make_int2(b * a.x, b * a.y);
1587 }
1588 
1594 inline __host__ __device__ void operator*=(int2 &a, int b)
1595 {
1596  a.x *= b;
1597  a.y *= b;
1598 }
1599 
1605 inline __host__ __device__ uint2 operator*(uint2 a, uint2 b)
1606 {
1607  return make_uint2(a.x * b.x, a.y * b.y);
1608 }
1609 
1615 inline __host__ __device__ void operator*=(uint2 &a, uint2 b)
1616 {
1617  a.x *= b.x;
1618  a.y *= b.y;
1619 }
1620 
1626 inline __host__ __device__ uint2 operator*(uint2 a, uint b)
1627 {
1628  return make_uint2(a.x * b, a.y * b);
1629 }
1630 
1636 inline __host__ __device__ uint2 operator*(uint b, uint2 a)
1637 {
1638  return make_uint2(b * a.x, b * a.y);
1639 }
1640 
1646 inline __host__ __device__ void operator*=(uint2 &a, uint b)
1647 {
1648  a.x *= b;
1649  a.y *= b;
1650 }
1651 
1657 inline __host__ __device__ float3 operator*(float3 a, float3 b)
1658 {
1659  return make_float3(a.x * b.x, a.y * b.y, a.z * b.z);
1660 }
1661 
1667 inline __host__ __device__ void operator*=(float3 &a, float3 b)
1668 {
1669  a.x *= b.x;
1670  a.y *= b.y;
1671  a.z *= b.z;
1672 }
1673 
1679 inline __host__ __device__ float3 operator*(float3 a, float b)
1680 {
1681  return make_float3(a.x * b, a.y * b, a.z * b);
1682 }
1683 
1689 inline __host__ __device__ float3 operator*(float b, float3 a)
1690 {
1691  return make_float3(b * a.x, b * a.y, b * a.z);
1692 }
1693 
1699 inline __host__ __device__ void operator*=(float3 &a, float b)
1700 {
1701  a.x *= b;
1702  a.y *= b;
1703  a.z *= b;
1704 }
1705 
1711 inline __host__ __device__ int3 operator*(int3 a, int3 b)
1712 {
1713  return make_int3(a.x * b.x, a.y * b.y, a.z * b.z);
1714 }
1715 
1721 inline __host__ __device__ void operator*=(int3 &a, int3 b)
1722 {
1723  a.x *= b.x;
1724  a.y *= b.y;
1725  a.z *= b.z;
1726 }
1727 
1733 inline __host__ __device__ int3 operator*(int3 a, int b)
1734 {
1735  return make_int3(a.x * b, a.y * b, a.z * b);
1736 }
1737 
1743 inline __host__ __device__ int3 operator*(int b, int3 a)
1744 {
1745  return make_int3(b * a.x, b * a.y, b * a.z);
1746 }
1747 
1753 inline __host__ __device__ void operator*=(int3 &a, int b)
1754 {
1755  a.x *= b;
1756  a.y *= b;
1757  a.z *= b;
1758 }
1759 
1765 inline __host__ __device__ uint3 operator*(uint3 a, uint3 b)
1766 {
1767  return make_uint3(a.x * b.x, a.y * b.y, a.z * b.z);
1768 }
1769 
1775 inline __host__ __device__ void operator*=(uint3 &a, uint3 b)
1776 {
1777  a.x *= b.x;
1778  a.y *= b.y;
1779  a.z *= b.z;
1780 }
1781 
1787 inline __host__ __device__ uint3 operator*(uint3 a, uint b)
1788 {
1789  return make_uint3(a.x * b, a.y * b, a.z * b);
1790 }
1791 
1797 inline __host__ __device__ uint3 operator*(uint b, uint3 a)
1798 {
1799  return make_uint3(b * a.x, b * a.y, b * a.z);
1800 }
1801 
1807 inline __host__ __device__ void operator*=(uint3 &a, uint b)
1808 {
1809  a.x *= b;
1810  a.y *= b;
1811  a.z *= b;
1812 }
1813 
1819 inline __host__ __device__ float4 operator*(float4 a, float4 b)
1820 {
1821  return make_float4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
1822 }
1823 
1829 inline __host__ __device__ void operator*=(float4 &a, float4 b)
1830 {
1831  a.x *= b.x;
1832  a.y *= b.y;
1833  a.z *= b.z;
1834  a.w *= b.w;
1835 }
1836 
1842 inline __host__ __device__ float4 operator*(float4 a, float b)
1843 {
1844  return make_float4(a.x * b, a.y * b, a.z * b, a.w * b);
1845 }
1846 
1852 inline __host__ __device__ float4 operator*(float b, float4 a)
1853 {
1854  return make_float4(b * a.x, b * a.y, b * a.z, b * a.w);
1855 }
1856 
1862 inline __host__ __device__ void operator*=(float4 &a, float b)
1863 {
1864  a.x *= b;
1865  a.y *= b;
1866  a.z *= b;
1867  a.w *= b;
1868 }
1869 
1875 inline __host__ __device__ int4 operator*(int4 a, int4 b)
1876 {
1877  return make_int4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
1878 }
1879 
1885 inline __host__ __device__ void operator*=(int4 &a, int4 b)
1886 {
1887  a.x *= b.x;
1888  a.y *= b.y;
1889  a.z *= b.z;
1890  a.w *= b.w;
1891 }
1892 
1898 inline __host__ __device__ int4 operator*(int4 a, int b)
1899 {
1900  return make_int4(a.x * b, a.y * b, a.z * b, a.w * b);
1901 }
1902 
1908 inline __host__ __device__ int4 operator*(int b, int4 a)
1909 {
1910  return make_int4(b * a.x, b * a.y, b * a.z, b * a.w);
1911 }
1912 
1918 inline __host__ __device__ void operator*=(int4 &a, int b)
1919 {
1920  a.x *= b;
1921  a.y *= b;
1922  a.z *= b;
1923  a.w *= b;
1924 }
1925 
1931 inline __host__ __device__ uint4 operator*(uint4 a, uint4 b)
1932 {
1933  return make_uint4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
1934 }
1935 
1941 inline __host__ __device__ void operator*=(uint4 &a, uint4 b)
1942 {
1943  a.x *= b.x;
1944  a.y *= b.y;
1945  a.z *= b.z;
1946  a.w *= b.w;
1947 }
1948 
1954 inline __host__ __device__ uint4 operator*(uint4 a, uint b)
1955 {
1956  return make_uint4(a.x * b, a.y * b, a.z * b, a.w * b);
1957 }
1958 
1964 inline __host__ __device__ uint4 operator*(uint b, uint4 a)
1965 {
1966  return make_uint4(b * a.x, b * a.y, b * a.z, b * a.w);
1967 }
1968 
1974 inline __host__ __device__ void operator*=(uint4 &a, uint b)
1975 {
1976  a.x *= b;
1977  a.y *= b;
1978  a.z *= b;
1979  a.w *= b;
1980 }
1981 
1983 // Divide.
1985 
1991 inline __host__ __device__ float2 operator/(float2 a, float2 b)
1992 {
1993  return make_float2(a.x / b.x, a.y / b.y);
1994 }
1995 
2001 inline __host__ __device__ void operator/=(float2 &a, float2 b)
2002 {
2003  a.x /= b.x;
2004  a.y /= b.y;
2005 }
2006 
2012 inline __host__ __device__ float2 operator/(float2 a, float b)
2013 {
2014  return make_float2(a.x / b, a.y / b);
2015 }
2016 
2022 inline __host__ __device__ void operator/=(float2 &a, float b)
2023 {
2024  a.x /= b;
2025  a.y /= b;
2026 }
2027 
2033 inline __host__ __device__ float2 operator/(float b, float2 a)
2034 {
2035  return make_float2(b / a.x, b / a.y);
2036 }
2037 
2043 inline __host__ __device__ float3 operator/(float3 a, float3 b)
2044 {
2045  return make_float3(a.x / b.x, a.y / b.y, a.z / b.z);
2046 }
2047 
2053 inline __host__ __device__ void operator/=(float3 &a, float3 b)
2054 {
2055  a.x /= b.x;
2056  a.y /= b.y;
2057  a.z /= b.z;
2058 }
2059 
2065 inline __host__ __device__ float3 operator/(float3 a, float b)
2066 {
2067  return make_float3(a.x / b, a.y / b, a.z / b);
2068 }
2069 
2075 inline __host__ __device__ void operator/=(float3 &a, float b)
2076 {
2077  a.x /= b;
2078  a.y /= b;
2079  a.z /= b;
2080 }
2081 
2087 inline __host__ __device__ float3 operator/(float b, float3 a)
2088 {
2089  return make_float3(b / a.x, b / a.y, b / a.z);
2090 }
2091 
2097 inline __host__ __device__ float4 operator/(float4 a, float4 b)
2098 {
2099  return make_float4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
2100 }
2101 
2107 inline __host__ __device__ void operator/=(float4 &a, float4 b)
2108 {
2109  a.x /= b.x;
2110  a.y /= b.y;
2111  a.z /= b.z;
2112  a.w /= b.w;
2113 }
2114 
2120 inline __host__ __device__ float4 operator/(float4 a, float b)
2121 {
2122  return make_float4(a.x / b, a.y / b, a.z / b, a.w / b);
2123 }
2124 
2130 inline __host__ __device__ void operator/=(float4 &a, float b)
2131 {
2132  a.x /= b;
2133  a.y /= b;
2134  a.z /= b;
2135  a.w /= b;
2136 }
2137 
2143 inline __host__ __device__ float4 operator/(float b, float4 a)
2144 {
2145  return make_float4(b / a.x, b / a.y, b / a.z, b / a.w);
2146 }
2147 
2149 // Min.
2151 
2157 inline __host__ __device__ float2 fminf(float2 a, float2 b)
2158 {
2159  return make_float2(fminf(a.x,b.x), fminf(a.y,b.y));
2160 }
2161 
2167 inline __host__ __device__ float3 fminf(float3 a, float3 b)
2168 {
2169  return make_float3(fminf(a.x,b.x), fminf(a.y,b.y), fminf(a.z,b.z));
2170 }
2171 
2177 inline __host__ __device__ float4 fminf(float4 a, float4 b)
2178 {
2179  return make_float4(fminf(a.x,b.x), fminf(a.y,b.y), fminf(a.z,b.z), fminf(a.w,b.w));
2180 }
2181 
2187 inline __host__ __device__ int2 min(int2 a, int2 b)
2188 {
2189  return make_int2(min(a.x,b.x), min(a.y,b.y));
2190 }
2191 
2197 inline __host__ __device__ int3 min(int3 a, int3 b)
2198 {
2199  return make_int3(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z));
2200 }
2201 
2207 inline __host__ __device__ int4 min(int4 a, int4 b)
2208 {
2209  return make_int4(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z), min(a.w,b.w));
2210 }
2211 
2217 inline __host__ __device__ uint2 min(uint2 a, uint2 b)
2218 {
2219  return make_uint2(min(a.x,b.x), min(a.y,b.y));
2220 }
2221 
2227 inline __host__ __device__ uint3 min(uint3 a, uint3 b)
2228 {
2229  return make_uint3(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z));
2230 }
2231 
2237 inline __host__ __device__ uint4 min(uint4 a, uint4 b)
2238 {
2239  return make_uint4(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z), min(a.w,b.w));
2240 }
2241 
2243 // Max.
2245 
2251 inline __host__ __device__ float2 fmaxf(float2 a, float2 b)
2252 {
2253  return make_float2(fmaxf(a.x,b.x), fmaxf(a.y,b.y));
2254 }
2255 
2261 inline __host__ __device__ float3 fmaxf(float3 a, float3 b)
2262 {
2263  return make_float3(fmaxf(a.x,b.x), fmaxf(a.y,b.y), fmaxf(a.z,b.z));
2264 }
2265 
2271 inline __host__ __device__ float4 fmaxf(float4 a, float4 b)
2272 {
2273  return make_float4(fmaxf(a.x,b.x), fmaxf(a.y,b.y), fmaxf(a.z,b.z), fmaxf(a.w,b.w));
2274 }
2275 
2281 inline __host__ __device__ int2 max(int2 a, int2 b)
2282 {
2283  return make_int2(max(a.x,b.x), max(a.y,b.y));
2284 }
2285 
2291 inline __host__ __device__ int3 max(int3 a, int3 b)
2292 {
2293  return make_int3(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z));
2294 }
2295 
2301 inline __host__ __device__ int4 max(int4 a, int4 b)
2302 {
2303  return make_int4(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z), max(a.w,b.w));
2304 }
2305 
2311 inline __host__ __device__ uint2 max(uint2 a, uint2 b)
2312 {
2313  return make_uint2(max(a.x,b.x), max(a.y,b.y));
2314 }
2315 
2321 inline __host__ __device__ uint3 max(uint3 a, uint3 b)
2322 {
2323  return make_uint3(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z));
2324 }
2325 
2331 inline __host__ __device__ uint4 max(uint4 a, uint4 b)
2332 {
2333  return make_uint4(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z), max(a.w,b.w));
2334 }
2335 
2337 // Linear interpolation between a and b, based on value t in [0, 1] range.
2339 
2346 inline __device__ __host__ float lerp(float a, float b, float t)
2347 {
2348  return a + t*(b-a);
2349 }
2350 
2357 inline __device__ __host__ float2 lerp(float2 a, float2 b, float t)
2358 {
2359  return a + t*(b-a);
2360 }
2361 
2368 inline __device__ __host__ float3 lerp(float3 a, float3 b, float t)
2369 {
2370  return a + t*(b-a);
2371 }
2372 
2379 inline __device__ __host__ float4 lerp(float4 a, float4 b, float t)
2380 {
2381  return a + t*(b-a);
2382 }
2383 
2385 // Clamp the value v to be in the range [a, b].
2387 
2394 inline __device__ __host__ float clamp(float f, float a, float b)
2395 {
2396  return fmaxf(a, fminf(f, b));
2397 }
2398 
2405 inline __device__ __host__ int clamp(int f, int a, int b)
2406 {
2407  return max(a, min(f, b));
2408 }
2409 
2416 inline __device__ __host__ uint clamp(uint f, uint a, uint b)
2417 {
2418  return max(a, min(f, b));
2419 }
2420 
2427 inline __device__ __host__ float2 clamp(float2 v, float a, float b)
2428 {
2429  return make_float2(clamp(v.x, a, b), clamp(v.y, a, b));
2430 }
2431 
2438 inline __device__ __host__ float2 clamp(float2 v, float2 a, float2 b)
2439 {
2440  return make_float2(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y));
2441 }
2442 
2449 inline __device__ __host__ float3 clamp(float3 v, float a, float b)
2450 {
2451  return make_float3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b));
2452 }
2453 
2460 inline __device__ __host__ float3 clamp(float3 v, float3 a, float3 b)
2461 {
2462  return make_float3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z));
2463 }
2464 
2471 inline __device__ __host__ float4 clamp(float4 v, float a, float b)
2472 {
2473  return make_float4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b));
2474 }
2475 
2482 inline __device__ __host__ float4 clamp(float4 v, float4 a, float4 b)
2483 {
2484  return make_float4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w));
2485 }
2486 
2493 inline __device__ __host__ int2 clamp(int2 v, int a, int b)
2494 {
2495  return make_int2(clamp(v.x, a, b), clamp(v.y, a, b));
2496 }
2497 
2504 inline __device__ __host__ int2 clamp(int2 v, int2 a, int2 b)
2505 {
2506  return make_int2(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y));
2507 }
2508 
2515 inline __device__ __host__ int3 clamp(int3 v, int a, int b)
2516 {
2517  return make_int3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b));
2518 }
2519 
2526 inline __device__ __host__ int3 clamp(int3 v, int3 a, int3 b)
2527 {
2528  return make_int3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z));
2529 }
2530 
2537 inline __device__ __host__ int4 clamp(int4 v, int a, int b)
2538 {
2539  return make_int4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b));
2540 }
2541 
2548 inline __device__ __host__ int4 clamp(int4 v, int4 a, int4 b)
2549 {
2550  return make_int4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w));
2551 }
2552 
2559 inline __device__ __host__ uint2 clamp(uint2 v, uint a, uint b)
2560 {
2561  return make_uint2(clamp(v.x, a, b), clamp(v.y, a, b));
2562 }
2563 
2570 inline __device__ __host__ uint2 clamp(uint2 v, uint2 a, uint2 b)
2571 {
2572  return make_uint2(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y));
2573 }
2574 
2581 inline __device__ __host__ uint3 clamp(uint3 v, uint a, uint b)
2582 {
2583  return make_uint3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b));
2584 }
2585 
2592 inline __device__ __host__ uint3 clamp(uint3 v, uint3 a, uint3 b)
2593 {
2594  return make_uint3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z));
2595 }
2596 
2603 inline __device__ __host__ uint4 clamp(uint4 v, uint a, uint b)
2604 {
2605  return make_uint4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b));
2606 }
2607 
2614 inline __device__ __host__ uint4 clamp(uint4 v, uint4 a, uint4 b)
2615 {
2616  return make_uint4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w));
2617 }
2618 
2620 // Dot product.
2622 
2628 inline __host__ __device__ float dot(float2 a, float2 b)
2629 {
2630  return a.x * b.x + a.y * b.y;
2631 }
2632 
2638 inline __host__ __device__ float dot(float3 a, float3 b)
2639 {
2640  return a.x * b.x + a.y * b.y + a.z * b.z;
2641 }
2642 
2648 inline __host__ __device__ float dot(float4 a, float4 b)
2649 {
2650  return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
2651 }
2652 
2658 inline __host__ __device__ int dot(int2 a, int2 b)
2659 {
2660  return a.x * b.x + a.y * b.y;
2661 }
2662 
2668 inline __host__ __device__ int dot(int3 a, int3 b)
2669 {
2670  return a.x * b.x + a.y * b.y + a.z * b.z;
2671 }
2672 
2678 inline __host__ __device__ int dot(int4 a, int4 b)
2679 {
2680  return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
2681 }
2682 
2688 inline __host__ __device__ uint dot(uint2 a, uint2 b)
2689 {
2690  return a.x * b.x + a.y * b.y;
2691 }
2692 
2698 inline __host__ __device__ uint dot(uint3 a, uint3 b)
2699 {
2700  return a.x * b.x + a.y * b.y + a.z * b.z;
2701 }
2702 
2708 inline __host__ __device__ uint dot(uint4 a, uint4 b)
2709 {
2710  return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
2711 }
2712 
2714 // Length.
2716 
2721 inline __host__ __device__ float length(float2 v)
2722 {
2723  return sqrtf(dot(v, v));
2724 }
2725 
2730 inline __host__ __device__ float length(float3 v)
2731 {
2732  return sqrtf(dot(v, v));
2733 }
2734 
2739 inline __host__ __device__ float length(float4 v)
2740 {
2741  return sqrtf(dot(v, v));
2742 }
2743 
2745 // Normalize.
2747 
2752 inline __host__ __device__ float2 normalize(float2 v)
2753 {
2754  float invLen = rsqrtf(dot(v, v));
2755  return v * invLen;
2756 }
2757 
2762 inline __host__ __device__ float3 normalize(float3 v)
2763 {
2764  float invLen = rsqrtf(dot(v, v));
2765  return v * invLen;
2766 }
2767 
2772 inline __host__ __device__ float4 normalize(float4 v)
2773 {
2774  float invLen = rsqrtf(dot(v, v));
2775  return v * invLen;
2776 }
2777 
2779 // Floor.
2781 
2786 inline __host__ __device__ float2 floorf(float2 v)
2787 {
2788  return make_float2(floorf(v.x), floorf(v.y));
2789 }
2790 
2795 inline __host__ __device__ float3 floorf(float3 v)
2796 {
2797  return make_float3(floorf(v.x), floorf(v.y), floorf(v.z));
2798 }
2799 
2804 inline __host__ __device__ float4 floorf(float4 v)
2805 {
2806  return make_float4(floorf(v.x), floorf(v.y), floorf(v.z), floorf(v.w));
2807 }
2808 
2810 // Return the fractional portion of a scalar or each vector component.
2812 
2817 inline __host__ __device__ float fracf(float v)
2818 {
2819  return v - floorf(v);
2820 }
2821 
2826 inline __host__ __device__ float2 fracf(float2 v)
2827 {
2828  return make_float2(fracf(v.x), fracf(v.y));
2829 }
2830 
2835 inline __host__ __device__ float3 fracf(float3 v)
2836 {
2837  return make_float3(fracf(v.x), fracf(v.y), fracf(v.z));
2838 }
2839 
2844 inline __host__ __device__ float4 fracf(float4 v)
2845 {
2846  return make_float4(fracf(v.x), fracf(v.y), fracf(v.z), fracf(v.w));
2847 }
2848 
2850 // Fmod.
2852 
2858 inline __host__ __device__ float2 fmodf(float2 a, float2 b)
2859 {
2860  return make_float2(fmodf(a.x, b.x), fmodf(a.y, b.y));
2861 }
2862 
2868 inline __host__ __device__ float3 fmodf(float3 a, float3 b)
2869 {
2870  return make_float3(fmodf(a.x, b.x), fmodf(a.y, b.y), fmodf(a.z, b.z));
2871 }
2872 
2878 inline __host__ __device__ float4 fmodf(float4 a, float4 b)
2879 {
2880  return make_float4(fmodf(a.x, b.x), fmodf(a.y, b.y), fmodf(a.z, b.z), fmodf(a.w, b.w));
2881 }
2882 
2884 // Absolute value.
2886 
2891 inline __host__ __device__ float2 fabs(float2 v)
2892 {
2893  return make_float2(fabs(v.x), fabs(v.y));
2894 }
2895 
2900 inline __host__ __device__ float3 fabs(float3 v)
2901 {
2902  return make_float3(fabs(v.x), fabs(v.y), fabs(v.z));
2903 }
2904 
2909 inline __host__ __device__ float4 fabs(float4 v)
2910 {
2911  return make_float4(fabs(v.x), fabs(v.y), fabs(v.z), fabs(v.w));
2912 }
2913 
2918 inline __host__ __device__ int2 abs(int2 v)
2919 {
2920  return make_int2(abs(v.x), abs(v.y));
2921 }
2922 
2927 inline __host__ __device__ int3 abs(int3 v)
2928 {
2929  return make_int3(abs(v.x), abs(v.y), abs(v.z));
2930 }
2931 
2936 inline __host__ __device__ int4 abs(int4 v)
2937 {
2938  return make_int4(abs(v.x), abs(v.y), abs(v.z), abs(v.w));
2939 }
2940 
2942 // Return the reflection of incident ray I around a normalized surface normal N, with the reflected length equal to the length of I.
2944 
2950 inline __host__ __device__ float3 reflect(float3 i, float3 n)
2951 {
2952  return i - 2.0f * n * dot(n,i);
2953 }
2954 
2956 // Cross product.
2958 
2964 inline __host__ __device__ float3 cross(float3 a, float3 b)
2965 {
2966  return make_float3(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x);
2967 }
2968 
2970 // Return 0 if x < a, 1 if x > b, and otherwise a smooth interpolation between 0 and 1 based on x.
2972 
2979 inline __device__ __host__ float smoothstep(float a, float b, float x)
2980 {
2981  float y = clamp((x - a) / (b - a), 0.0f, 1.0f);
2982  return (y*y*(3.0f - (2.0f*y)));
2983 }
2984 
2991 inline __device__ __host__ float2 smoothstep(float2 a, float2 b, float2 x)
2992 {
2993  float2 y = clamp((x - a) / (b - a), 0.0f, 1.0f);
2994  return (y*y*(make_float2(3.0f) - (make_float2(2.0f)*y)));
2995 }
2996 
3003 inline __device__ __host__ float3 smoothstep(float3 a, float3 b, float3 x)
3004 {
3005  float3 y = clamp((x - a) / (b - a), 0.0f, 1.0f);
3006  return (y*y*(make_float3(3.0f) - (make_float3(2.0f)*y)));
3007 }
3008 
3015 inline __device__ __host__ float4 smoothstep(float4 a, float4 b, float4 x)
3016 {
3017  float4 y = clamp((x - a) / (b - a), 0.0f, 1.0f);
3018  return (y*y*(make_float4(3.0f) - (make_float4(2.0f)*y)));
3019 }
3020 
3021 #endif // HELPER_MATH_H
operator-=
__host__ __device__ void operator-=(float2 &a, float2 b)
Subtract the second operand from the first in place.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:1031
make_int2
__host__ __device__ int2 make_int2(int s)
Construct a int2 value from the supplied components.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:129
length
__host__ __device__ float length(float2 v)
Compute the Euclidean length of a vector.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:2721
fabs
__host__ __device__ float2 fabs(float2 v)
Compute the absolute value component-wise.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:2891
floorf
__host__ __device__ float2 floorf(float2 v)
Apply the floor operation component-wise.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:2786
fracf
__host__ __device__ float fracf(float v)
Compute the fractional part component-wise.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:2817
make_float2
__host__ __device__ float2 make_float2(float s)
Construct a float2 value from the supplied components.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:93
smoothstep
__device__ __host__ float smoothstep(float a, float b, float x)
Apply smooth Hermite interpolation between two edges.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:2979
operator+=
__host__ __device__ void operator+=(float2 &a, float2 b)
Add the second operand to the first in place.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:541
make_float4
__host__ __device__ float4 make_float4(float s)
Construct a float4 value from the supplied components.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:339
make_uint2
__host__ __device__ uint2 make_uint2(uint s)
Construct a uint2 value from the supplied components.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:165
uint
unsigned int uint
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:25
lerp
__device__ __host__ float lerp(float a, float b, float t)
Linearly interpolate between two values.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:2346
ushort
unsigned short ushort
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:26
operator*=
__host__ __device__ void operator*=(float2 &a, float2 b)
Multiply the first operand by the second in place.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:1511
make_float3
__host__ __device__ float3 make_float3(float s)
Construct a float3 value from the supplied components.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:192
max
int max(int a, int b)
Compute the component-wise maximum.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:60
make_uint3
__host__ __device__ uint3 make_uint3(uint s)
Construct a uint3 value from the supplied components.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:293
abs
__host__ __device__ int2 abs(int2 v)
Compute the absolute value component-wise.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:2918
dot
__host__ __device__ float dot(float2 a, float2 b)
Compute the dot product of two vectors.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:2628
reflect
__host__ __device__ float3 reflect(float3 i, float3 n)
Reflect an incident vector about a normal.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:2950
make_int4
__host__ __device__ int4 make_int4(int s)
Construct a int4 value from the supplied components.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:385
operator*
__host__ __device__ float2 operator*(float2 a, float2 b)
Multiply two operands component-wise.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:1501
rsqrtf
float rsqrtf(float x)
Compute the reciprocal square root.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:79
min
int min(int a, int b)
Compute the component-wise minimum.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:70
normalize
__host__ __device__ float2 normalize(float2 v)
Normalize a vector to unit length.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:2752
cross
__host__ __device__ float3 cross(float3 a, float3 b)
Compute the cross product of two vectors.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:2964
fminf
float fminf(float a, float b)
Compute the component-wise minimum.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:40
operator/
__host__ __device__ float2 operator/(float2 a, float2 b)
Divide the first operand by the second component-wise.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:1991
operator/=
__host__ __device__ void operator/=(float2 &a, float2 b)
Divide the first operand by the second in place.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:2001
operator-
__host__ __device__ float2 operator-(float2 &a)
Negate the operand component-wise.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:472
fmaxf
float fmaxf(float a, float b)
Compute the component-wise maximum.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:50
make_int3
__host__ __device__ int3 make_int3(int s)
Construct a int3 value from the supplied components.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:247
operator+
__host__ __device__ float2 operator+(float2 a, float2 b)
Add two operands component-wise.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:531
fmodf
__host__ __device__ float2 fmodf(float2 a, float2 b)
Compute the floating-point remainder component-wise.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:2858
make_uint4
__host__ __device__ uint4 make_uint4(uint s)
Construct a uint4 value from the supplied components.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:431
clamp
__device__ __host__ float clamp(float f, float a, float b)
Clamp a value between lower and upper bounds.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:2394