ai_comparison.h
Go to the documentation of this file.
1// Copyright 2021 Autodesk, Inc. All rights reserved.
2//
3// Use of this software is subject to the terms of the Autodesk license
4// agreement provided at the time of installation or download, or which
5// otherwise accompanies this software in either electronic or hard copy form.
6
12#pragma once
13#include "ai_api.h"
14
15template<unsigned dim>
17{
18 AI_DEVICE static AtBooleanMask<dim> lt(const float* x, const float* y)
19 {
21 for (unsigned i=0; i < dim; ++i)
22 r.data[i] = x[i] < y[i];
23 return r;
24 }
25 AI_DEVICE static AtBooleanMask<dim> le(const float* x, const float* y)
26 {
28 for (unsigned i=0; i < dim; ++i)
29 r.data[i] = x[i] <= y[i];
30 return r;
31 }
32
33 AI_DEVICE static AtBooleanMask<dim> gt(const float* x, const float* y)
34 {
36 for (unsigned i=0; i < dim; ++i)
37 r.data[i] = x[i] > y[i];
38 return r;
39 }
40
41 AI_DEVICE static AtBooleanMask<dim> ge(const float* x, const float* y)
42 {
44 for (unsigned i=0; i < dim; ++i)
45 r.data[i] = x[i] >= y[i];
46 return r;
47 }
48
49
50 AI_DEVICE static AtBooleanMask<dim> lt(const float* x, const float y)
51 {
53 for (unsigned i=0; i < dim; ++i)
54 r.data[i] = x[i] < y;
55 return r;
56 }
57
58 AI_DEVICE static AtBooleanMask<dim> le(const float* x, const float y)
59 {
61 for (unsigned i=0; i < dim; ++i)
62 r.data[i] = x[i] <= y;
63 return r;
64 }
65
66 AI_DEVICE static AtBooleanMask<dim> gt(const float* x, const float y)
67 {
69 for (unsigned i=0; i < dim; ++i)
70 r.data[i] = x[i] > y;
71 return r;
72 }
73
74 AI_DEVICE static AtBooleanMask<dim> ge(const float* x, const float y)
75 {
77 for (unsigned i=0; i < dim; ++i)
78 r.data[i] = x[i] >= y;
79 return r;
80 }
81
82 bool data[dim];
83};
84
85// some compilers (clang is fine, but at least icc 13 is not), aren't able to
86// properly optimize with a for loop over the AtBooleanMask dim, so we have to
87// do this manually
88AI_DEVICE inline constexpr bool AiAny(const AtBooleanMask<2>& bm)
89{
90 return (bm.data[0] || bm.data[1]);
91}
92
93AI_DEVICE inline constexpr bool AiAll(const AtBooleanMask<2>& bm)
94{
95 return (bm.data[0] && bm.data[1]);
96}
97
98AI_DEVICE inline constexpr bool AiAny(const AtBooleanMask<3>& bm)
99{
100 return (bm.data[0] || bm.data[1] || bm.data[2]);
101}
102
103AI_DEVICE inline constexpr bool AiAll(const AtBooleanMask<3>& bm)
104{
105 return (bm.data[0] && bm.data[1] && bm.data[2]);
106}
107
108AI_DEVICE inline constexpr bool AiAny(const AtBooleanMask<4>& bm)
109{
110 return (bm.data[0] || bm.data[1] || bm.data[2] || bm.data[3]);
111}
112
113AI_DEVICE inline constexpr bool AiAll(const AtBooleanMask<4>& bm)
114{
115 return (bm.data[0] && bm.data[1] && bm.data[2] && bm.data[3]);
116}
DLL export prefix for API functions (necessary for multi-platform development)
Definition: ai_comparison.h:17

© 2022 Autodesk, Inc. · All rights reserved · www.arnoldrenderer.com