30 #include <cugar/basic/types.h> 31 #include <cugar/basic/numbers.h> 32 #include <cugar/linalg/vector.h> 33 #include <cugar/linalg/matrix.h> 42 template <
typename T, u
int32 ORDER, u
int32 N>
48 template <u
int32 ORDER>
69 operator uint32()
const {
return x; }
97 template <
typename T, u
int32 N>
100 typedef T value_type;
101 typedef T component_type;
103 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
106 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
107 explicit Tensor(
const value_type _d) : data(_d) {}
109 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
110 operator value_type()
const {
return data; }
112 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
113 value_type operator() ()
const {
return data; }
115 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
116 const value_type& operator() (
TensorIndex<0> i)
const {
return data; }
118 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
121 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
122 uint32 order()
const {
return 0; }
130 template <
typename T, u
int32 N>
133 typedef T value_type;
135 typedef T component_type;
137 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
140 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
141 explicit Tensor(
const value_type _v) : base_type(_v) {}
143 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
146 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
147 Tensor& operator=(
const Vector<T,N>& _v) { *
static_cast<base_type*
>(
this) = _v;
return *
this; }
149 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
150 Tensor& operator=(
const Tensor<T,1,N>& _v) { *
static_cast<base_type*
>(
this) = static_cast<base_type>(_v);
return *
this; }
152 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
153 const value_type& operator() (
TensorIndex<1> i)
const {
return base_type::operator[](i); }
155 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
156 value_type& operator() (
TensorIndex<1> i) {
return base_type::operator[](i); }
158 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
159 uint32 order()
const {
return 1; }
161 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
162 uint32 dimension()
const {
return N; }
168 template <
typename T, u
int32 N>
171 typedef T value_type;
175 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
178 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
179 explicit Tensor(
const value_type _v) : base_type(_v) {}
181 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
182 Tensor(
const base_type& _v) : base_type(_v) {}
184 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
185 Tensor& operator=(
const base_type& _v) { *
static_cast<base_type*
>(
this) = _v;
return *
this; }
187 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
188 Tensor& operator=(
const Tensor<T,2,N>& _v) { *
static_cast<base_type*
>(
this) = static_cast<base_type>(_v);
return *
this; }
190 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
191 const value_type& operator() (
const TensorIndex<2> i)
const {
return base_type::operator()(i.x, i.y); }
193 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
194 value_type& operator() (
const TensorIndex<2> i) {
return base_type::operator()(i.x, i.y); }
196 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
197 const value_type& operator() (
const uint32 i,
const uint32 j)
const {
return base_type::operator()(i,j); }
199 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
200 value_type& operator() (
const uint32 i,
const uint32 j) {
return base_type::operator()(i,j); }
202 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
203 const component_type& operator[] (
const uint32 i)
const {
return reinterpret_cast<const component_type&
>(base_type::operator[](i)); }
205 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
206 component_type& operator[] (
const uint32 i) {
return reinterpret_cast<component_type&
>(base_type::operator[](i)); }
208 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
209 uint32 order()
const {
return 2; }
211 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
212 uint32 dimension()
const {
return N; }
218 template <
typename T, u
int32 N>
221 typedef T value_type;
224 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
227 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
228 explicit Tensor(
const value_type _v)
231 for (uint32 i = 0; i < N; ++i)
232 data[i] = component_type(_v);
235 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
239 for (uint32 i = 0; i < N; ++i)
240 data[i] = _v.data[i];
244 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
245 const component_type& operator[] (
const uint32 i)
const {
return data[i]; }
247 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
248 component_type& operator[] (
const uint32 i) {
return data[i]; }
250 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
251 const value_type& operator() (
const uint32 i,
const uint32 j,
const uint32 k)
const {
return data[i](j,k); }
253 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
254 value_type& operator() (
const uint32 i,
const uint32 j,
const uint32 k) {
return data[i](j,k); }
256 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
257 const value_type& operator() (
const TensorIndex<3> i)
const {
return data[i.x](i.y, i.z); }
259 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
260 value_type& operator() (
const TensorIndex<3> i) {
return data[i.x](i.y, i.z); }
262 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
263 uint32 order()
const {
return 3; }
265 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
266 uint32 dimension()
const {
return N; }
268 component_type data[N];
273 CUGAR_API_CS CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
278 template <
typename T, u
int32 N> CUGAR_API_CS CUGAR_HOST_DEVICE
286 template <
typename T, u
int32 N> CUGAR_API_CS CUGAR_HOST_DEVICE
290 for (uint32 i = 0; i < N; ++i)
297 template <
typename T, u
int32 N> CUGAR_API_CS CUGAR_HOST_DEVICE
301 for (uint32 i = 0; i < N; ++i)
308 template <
typename T, u
int32 D1, u
int32 N> CUGAR_API_CS CUGAR_HOST_DEVICE
312 for (uint32 i = 0; i < N; ++i)
318 template <
typename T, u
int32 D2, u
int32 N> CUGAR_API_CS CUGAR_HOST_DEVICE
322 for (uint32 i = 0; i < N; ++i)
329 template <
typename T, u
int32 N> CUGAR_API_CS CUGAR_HOST_DEVICE
333 for (uint32 i = 0; i < N; ++i)
334 for (uint32 j = 0; j < N; ++j)
335 r(i,j) = op1[i] * op2[j];
340 template <
typename T, u
int32 D2, u
int32 N> CUGAR_API_CS CUGAR_HOST_DEVICE
344 for (uint32 i = 0; i < N; ++i)
350 template <
typename T, u
int32 N, u
int32 D1> CUGAR_API_CS CUGAR_HOST_DEVICE
354 for (uint32 i = 0; i < N; ++i)
361 template <
typename T, u
int32 N> CUGAR_API_CS CUGAR_HOST_DEVICE
365 for (uint32 i = 0; i < N; ++i)
371 template <
typename T, u
int32 N> CUGAR_API_CS CUGAR_HOST_DEVICE
375 for (uint32 i = 0; i < N; ++i)
382 template <
typename T, u
int32 D, u
int32 N> CUGAR_API_CS CUGAR_HOST_DEVICE
386 for (uint32 i = 0; i < N; ++i)
392 template <
typename T, u
int32 D, u
int32 N> CUGAR_API_CS CUGAR_HOST_DEVICE
396 for (uint32 i = 0; i < N; ++i)
403 template <
typename T, u
int32 D, u
int32 N> CUGAR_API_CS CUGAR_HOST_DEVICE
410 template <
typename T, u
int32 D, u
int32 N> CUGAR_API_CS CUGAR_HOST_DEVICE
418 template <
typename T, u
int32 D, u
int32 N> CUGAR_API_CS CUGAR_HOST_DEVICE
422 for (uint32 i = 0; i < N; ++i)
423 r[i] = op1[i] + op2[i];
428 template <
typename T, u
int32 D, u
int32 N> CUGAR_API_CS CUGAR_HOST_DEVICE
432 for (uint32 i = 0; i < N; ++i)
433 r[i] = op1[i] - op2[i];
439 template <
typename T, u
int32 D, u
int32 N> CUGAR_API_CS CUGAR_HOST_DEVICE
443 for (uint32 i = 0; i < N; ++i)
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
CUGAR_API_CS CUGAR_HOST_DEVICE Matrix< T, N, M > outer_product(const Vector< T, N > op1, const Vector< T, M > op2)
Definition: matrix_inline.h:503