NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
static_vector_inl.h
Go to the documentation of this file.
1 /*
2  * nvbio
3  * Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the NVIDIA CORPORATION nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #pragma once
29 
30 namespace nvbio {
31 
32 #if 0
33 template <typename T, uint32 DIM>
36 {
37  #pragma unroll
38  for (uint32 d = 0; d < DIM; ++d)
39  this->operator[](d) = v[d];
40 }
41 #endif
42 
43 template <typename T, uint32 DIM>
46 {
47  #pragma unroll
48  for (uint32 d = 0; d < DIM; ++d)
49  this->operator[](d) = v;
50 }
51 
52 template <typename T, uint32 DIM>
55 {
56  #pragma unroll
57  for (uint32 d = 0; d < DIM; ++d)
58  this->operator[](d) = op[d];
59 
60  return *this;
61 }
62 
63 template <typename T, uint32 DIM>
66 {
68  #pragma unroll
69  for (uint32 d = 0; d < DIM; ++d)
70  r[d] = op1[d] + op2[d];
71  return r;
72 }
73 template <typename T, uint32 DIM>
76 {
77  #pragma unroll
78  for (uint32 d = 0; d < DIM; ++d)
79  op1[d] = op1[d] + op2[d];
80  return op1;
81 }
82 template <typename T, uint32 DIM>
85 {
87  #pragma unroll
88  for (uint32 d = 0; d < DIM; ++d)
89  r[d] = op1[d] - op2[d];
90  return r;
91 }
92 template <typename T, uint32 DIM>
95 {
96  #pragma unroll
97  for (uint32 d = 0; d < DIM; ++d)
98  op1[d] = op1[d] - op2[d];
99  return op1;
100 }
101 template <typename T, uint32 DIM>
104 {
106  #pragma unroll
107  for (uint32 d = 0; d < DIM; ++d)
108  r[d] = op1[d] - op2[d];
109  return r;
110 }
111 template <typename T, uint32 DIM>
114 {
115  #pragma unroll
116  for (uint32 d = 0; d < DIM; ++d)
117  op1[d] = op1[d] * op2[d];
118  return op1;
119 }
120 template <typename T, uint32 DIM>
123 {
125  #pragma unroll
126  for (uint32 d = 0; d < DIM; ++d)
127  r[d] = op1[d] / op2[d];
128  return r;
129 }
130 template <typename T, uint32 DIM>
133 {
134  #pragma unroll
135  for (uint32 d = 0; d < DIM; ++d)
136  op1[d] = op1[d] / op2[d];
137  return op1;
138 }
139 template <typename T, uint32 DIM>
142 {
144  #pragma unroll
145  for (uint32 d = 0; d < DIM; ++d)
146  r[d] = nvbio::min( op1[d], op2[d] );
147  return r;
148 }
149 template <typename T, uint32 DIM>
152 {
154  #pragma unroll
155  for (uint32 d = 0; d < DIM; ++d)
156  r[d] = nvbio::max( op1[d], op2[d] );
157  return r;
158 }
159 template <typename T, uint32 DIM>
161 bool any(const StaticVector<T,DIM>& op)
162 {
163  bool r = false;
164  #pragma unroll
165  for (uint32 d = 0; d < DIM; ++d)
166  r = r || (op[d] != 0);
167  return r;
168 }
169 template <typename T, uint32 DIM>
171 bool all(const StaticVector<T,DIM>& op)
172 {
173  bool r = true;
174  #pragma unroll
175  for (uint32 d = 0; d < DIM; ++d)
176  r = r && (op[d] != 0);
177  return r;
178 }
179 
180 template <typename T, uint32 DIM>
183 {
184  bool r = true;
185  #pragma unroll
186  for (uint32 d = 0; d < DIM; ++d)
187  r = r && (op1[d] == op2[d]);
188  return r;
189 }
190 
191 template <typename T, uint32 DIM>
194 {
195  bool r = false;
196  #pragma unroll
197  for (uint32 d = 0; d < DIM; ++d)
198  r = r || (op1[d] != op2[d]);
199  return r;
200 }
201 
202 } // namespace nvbio