ViennaCL - The Vienna Computing Library  1.7.1
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
predicate.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_META_PREDICATE_HPP_
2 #define VIENNACL_META_PREDICATE_HPP_
3 
4 /* =========================================================================
5  Copyright (c) 2010-2016, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8  Portions of this software are copyright by UChicago Argonne, LLC.
9 
10  -----------------
11  ViennaCL - The Vienna Computing Library
12  -----------------
13 
14  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15 
16  (A list of authors and contributors can be found in the manual)
17 
18  License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20 
25 #include <string>
26 #include <fstream>
27 #include <sstream>
28 #include "viennacl/forwards.h"
29 
30 #ifdef VIENNACL_WITH_OPENCL
31 #ifdef __APPLE__
32 #include <OpenCL/cl.h>
33 #else
34 #include "CL/cl.h"
35 #endif
36 #endif
37 
38 namespace viennacl
39 {
40 
41 //
42 // is_cpu_scalar: checks for float or double
43 //
44 //template<typename T>
45 //struct is_cpu_scalar
46 //{
47 // enum { value = false };
48 //};
49 
51 template<> struct is_cpu_scalar<char> { enum { value = true }; };
52 template<> struct is_cpu_scalar<unsigned char> { enum { value = true }; };
53 template<> struct is_cpu_scalar<short> { enum { value = true }; };
54 template<> struct is_cpu_scalar<unsigned short> { enum { value = true }; };
55 template<> struct is_cpu_scalar<int> { enum { value = true }; };
56 template<> struct is_cpu_scalar<unsigned int> { enum { value = true }; };
57 template<> struct is_cpu_scalar<long> { enum { value = true }; };
58 template<> struct is_cpu_scalar<unsigned long> { enum { value = true }; };
59 template<> struct is_cpu_scalar<float> { enum { value = true }; };
60 template<> struct is_cpu_scalar<double> { enum { value = true }; };
64 //
65 // is_scalar: checks for viennacl::scalar
66 //
67 //template<typename T>
68 //struct is_scalar
69 //{
70 // enum { value = false };
71 //};
72 
74 template<typename T>
75 struct is_scalar<viennacl::scalar<T> >
76 {
77  enum { value = true };
78 };
81 //
82 // is_flip_sign_scalar: checks for viennacl::scalar modified with unary operator-
83 //
84 //template<typename T>
85 //struct is_flip_sign_scalar
86 //{
87 // enum { value = false };
88 //};
89 
91 template<typename T>
92 struct is_flip_sign_scalar<viennacl::scalar_expression< const scalar<T>,
93  const scalar<T>,
94  op_flip_sign> >
95 {
96  enum { value = true };
97 };
100 //
101 // is_any_scalar: checks for either CPU and GPU scalars, i.e. is_cpu_scalar<>::value || is_scalar<>::value
102 //
103 //template<typename T>
104 //struct is_any_scalar
105 //{
106 // enum { value = (is_scalar<T>::value || is_cpu_scalar<T>::value || is_flip_sign_scalar<T>::value )};
107 //};
108 
109 //
110 
112 #define VIENNACL_MAKE_ANY_VECTOR_TRUE(type) template<> struct is_any_vector< type > { enum { value = 1 }; };
113 #define VIENNACL_MAKE_FOR_ALL_NumericT(type) \
114  VIENNACL_MAKE_ANY_VECTOR_TRUE(type<float>)\
115  VIENNACL_MAKE_ANY_VECTOR_TRUE(type<double>)
116 
117  VIENNACL_MAKE_FOR_ALL_NumericT(viennacl::vector)
118  VIENNACL_MAKE_FOR_ALL_NumericT(viennacl::vector_range)
119  VIENNACL_MAKE_FOR_ALL_NumericT(viennacl::vector_slice)
120  VIENNACL_MAKE_FOR_ALL_NumericT(viennacl::unit_vector)
121  VIENNACL_MAKE_FOR_ALL_NumericT(viennacl::zero_vector)
122  VIENNACL_MAKE_FOR_ALL_NumericT(viennacl::one_vector)
123  VIENNACL_MAKE_FOR_ALL_NumericT(viennacl::scalar_vector)
124 
125 #undef VIENNACL_MAKE_FOR_ALL_NumericT
126 #undef VIENNACL_MAKE_ANY_VECTOR_TRUE
127 
131 #define VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE)\
132 template<> struct is_any_dense_matrix< TYPE > { enum { value = 1 }; };
133 
134 #define VIENNACL_MAKE_FOR_ALL_NumericT(TYPE) \
135  VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<float>)\
136  VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<double>)
137 
138 #define VIENNACL_COMMA ,
139 #define VIENNACL_MAKE_FOR_ALL_NumericT_LAYOUT(TYPE) \
140  VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<float VIENNACL_COMMA viennacl::row_major>)\
141  VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<double VIENNACL_COMMA viennacl::row_major>)\
142  VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<float VIENNACL_COMMA viennacl::column_major>)\
143  VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<double VIENNACL_COMMA viennacl::column_major>)
144 
145  VIENNACL_MAKE_FOR_ALL_NumericT_LAYOUT(viennacl::matrix)
146  // VIENNACL_MAKE_FOR_ALL_NumericT_LAYOUT(viennacl::matrix_range)
147  // VIENNACL_MAKE_FOR_ALL_NumericT_LAYOUT(viennacl::matrix_slice)
148  VIENNACL_MAKE_FOR_ALL_NumericT(viennacl::identity_matrix)
149  VIENNACL_MAKE_FOR_ALL_NumericT(viennacl::zero_matrix)
150  VIENNACL_MAKE_FOR_ALL_NumericT(viennacl::scalar_matrix)
151 
152 #undef VIENNACL_MAKE_FOR_ALL_NumericT_LAYOUT
153 #undef VIENNACL_MAKE_FOR_ALL_NumericT
154 #undef VIENNACL_MAKE_ANY_MATRIX_TRUE
155 #undef VIENNACL_COMMA
156 
158 //
159 // is_row_major
160 //
161 //template<typename T>
162 //struct is_row_major
163 //{
164 // enum { value = false };
165 //};
166 
168 template<typename ScalarType>
169 struct is_row_major<viennacl::matrix<ScalarType, viennacl::row_major> >
170 {
171  enum { value = true };
172 };
173 
174 template<>
175 struct is_row_major< viennacl::row_major >
176 {
177  enum { value = true };
178 };
179 
180 template<typename T>
181 struct is_row_major<viennacl::matrix_expression<T, T, viennacl::op_trans> >
182 {
183  enum { value = is_row_major<T>::value };
184 };
188 //
189 // is_circulant_matrix
190 //
191 //template<typename T>
192 //struct is_circulant_matrix
193 //{
194 // enum { value = false };
195 //};
196 
198 template<typename ScalarType, unsigned int AlignmentV>
199 struct is_circulant_matrix<viennacl::circulant_matrix<ScalarType, AlignmentV> >
200 {
201  enum { value = true };
202 };
203 
204 template<typename ScalarType, unsigned int AlignmentV>
205 struct is_circulant_matrix<const viennacl::circulant_matrix<ScalarType, AlignmentV> >
206 {
207  enum { value = true };
208 };
211 //
212 // is_hankel_matrix
213 //
214 //template<typename T>
215 //struct is_hankel_matrix
216 //{
217 // enum { value = false };
218 //};
219 
221 template<typename ScalarType, unsigned int AlignmentV>
222 struct is_hankel_matrix<viennacl::hankel_matrix<ScalarType, AlignmentV> >
223 {
224  enum { value = true };
225 };
226 
227 template<typename ScalarType, unsigned int AlignmentV>
228 struct is_hankel_matrix<const viennacl::hankel_matrix<ScalarType, AlignmentV> >
229 {
230  enum { value = true };
231 };
234 //
235 // is_toeplitz_matrix
236 //
237 //template<typename T>
238 //struct is_toeplitz_matrix
239 //{
240 // enum { value = false };
241 //};
242 
244 template<typename ScalarType, unsigned int AlignmentV>
245 struct is_toeplitz_matrix<viennacl::toeplitz_matrix<ScalarType, AlignmentV> >
246 {
247  enum { value = true };
248 };
249 
250 template<typename ScalarType, unsigned int AlignmentV>
251 struct is_toeplitz_matrix<const viennacl::toeplitz_matrix<ScalarType, AlignmentV> >
252 {
253  enum { value = true };
254 };
257 //
258 // is_vandermonde_matrix
259 //
260 //template<typename T>
261 //struct is_vandermonde_matrix
262 //{
263 // enum { value = false };
264 //};
265 
267 template<typename ScalarType, unsigned int AlignmentV>
268 struct is_vandermonde_matrix<viennacl::vandermonde_matrix<ScalarType, AlignmentV> >
269 {
270  enum { value = true };
271 };
272 
273 template<typename ScalarType, unsigned int AlignmentV>
274 struct is_vandermonde_matrix<const viennacl::vandermonde_matrix<ScalarType, AlignmentV> >
275 {
276  enum { value = true };
277 };
281 //
282 // is_compressed_matrix
283 //
284 
286 template<typename ScalarType, unsigned int AlignmentV>
287 struct is_compressed_matrix<viennacl::compressed_matrix<ScalarType, AlignmentV> >
288 {
289  enum { value = true };
290 };
293 //
294 // is_coordinate_matrix
295 //
296 
298 template<typename ScalarType, unsigned int AlignmentV>
299 struct is_coordinate_matrix<viennacl::coordinate_matrix<ScalarType, AlignmentV> >
300 {
301  enum { value = true };
302 };
305 //
306 // is_ell_matrix
307 //
309 template<typename ScalarType, unsigned int AlignmentV>
310 struct is_ell_matrix<viennacl::ell_matrix<ScalarType, AlignmentV> >
311 {
312  enum { value = true };
313 };
316 //
317 // is_sliced_ell_matrix
318 //
320 template<typename ScalarType, typename IndexT>
321 struct is_sliced_ell_matrix<viennacl::sliced_ell_matrix<ScalarType, IndexT> >
322 {
323  enum { value = true };
324 };
327 //
328 // is_hyb_matrix
329 //
331 template<typename ScalarType, unsigned int AlignmentV>
332 struct is_hyb_matrix<viennacl::hyb_matrix<ScalarType, AlignmentV> >
333 {
334  enum { value = true };
335 };
339 //
340 // is_any_sparse_matrix
341 //
342 //template<typename T>
343 //struct is_any_sparse_matrix
344 //{
345 // enum { value = false };
346 //};
347 
349 template<typename ScalarType, unsigned int AlignmentV>
350 struct is_any_sparse_matrix<viennacl::compressed_matrix<ScalarType, AlignmentV> >
351 {
352  enum { value = true };
353 };
354 
355 template<typename ScalarType>
356 struct is_any_sparse_matrix<viennacl::compressed_compressed_matrix<ScalarType> >
357 {
358  enum { value = true };
359 };
360 
361 template<typename ScalarType, unsigned int AlignmentV>
362 struct is_any_sparse_matrix<viennacl::coordinate_matrix<ScalarType, AlignmentV> >
363 {
364  enum { value = true };
365 };
366 
367 template<typename ScalarType, unsigned int AlignmentV>
368 struct is_any_sparse_matrix<viennacl::ell_matrix<ScalarType, AlignmentV> >
369 {
370  enum { value = true };
371 };
372 
373 template<typename ScalarType, typename IndexT>
374 struct is_any_sparse_matrix<viennacl::sliced_ell_matrix<ScalarType, IndexT> >
375 {
376  enum { value = true };
377 };
378 
379 template<typename ScalarType, unsigned int AlignmentV>
380 struct is_any_sparse_matrix<viennacl::hyb_matrix<ScalarType, AlignmentV> >
381 {
382  enum { value = true };
383 };
384 
385 template<typename T>
386 struct is_any_sparse_matrix<const T>
387 {
388  enum { value = is_any_sparse_matrix<T>::value };
389 };
390 
393 
395 //
396 // is_addition
397 //
399 template<typename T>
401 {
402  enum { value = false };
403 };
404 
406 template<>
407 struct is_addition<viennacl::op_add>
408 {
409  enum { value = true };
410 };
413 //
414 // is_subtraction
415 //
417 template<typename T>
419 {
420  enum { value = false };
421 };
422 
424 template<>
425 struct is_subtraction<viennacl::op_sub>
426 {
427  enum { value = true };
428 };
431 //
432 // is_product
433 //
435 template<typename T>
437 {
438  enum { value = false };
439 };
440 
442 template<>
443 struct is_product<viennacl::op_prod>
444 {
445  enum { value = true };
446 };
447 
448 template<>
449 struct is_product<viennacl::op_mult>
450 {
451  enum { value = true };
452 };
453 
454 template<>
455 struct is_product<viennacl::op_element_binary<op_prod> >
456 {
457  enum { value = true };
458 };
461 //
462 // is_division
463 //
465 template<typename T>
467 {
468  enum { value = false };
469 };
470 
472 template<>
473 struct is_division<viennacl::op_div>
474 {
475  enum { value = true };
476 };
477 
478 template<>
479 struct is_division<viennacl::op_element_binary<op_div> >
480 {
481  enum { value = true };
482 };
485 // is_primitive_type
486 //
487 
489 template<class T>
490 struct is_primitive_type{ enum {value = false}; };
491 
493 template<> struct is_primitive_type<float> { enum { value = true }; };
494 template<> struct is_primitive_type<double> { enum { value = true }; };
495 template<> struct is_primitive_type<unsigned int> { enum { value = true }; };
496 template<> struct is_primitive_type<int> { enum { value = true }; };
497 template<> struct is_primitive_type<unsigned char> { enum { value = true }; };
498 template<> struct is_primitive_type<char> { enum { value = true }; };
499 template<> struct is_primitive_type<unsigned long> { enum { value = true }; };
500 template<> struct is_primitive_type<long> { enum { value = true }; };
501 template<> struct is_primitive_type<unsigned short>{ enum { value = true }; };
502 template<> struct is_primitive_type<short> { enum { value = true }; };
505 #ifdef VIENNACL_WITH_OPENCL
506 
508 template<class T>
509 struct is_cl_type{ enum { value = false }; };
510 
512 template<> struct is_cl_type<cl_float> { enum { value = true }; };
513 template<> struct is_cl_type<cl_double>{ enum { value = true }; };
514 template<> struct is_cl_type<cl_uint> { enum { value = true }; };
515 template<> struct is_cl_type<cl_int> { enum { value = true }; };
516 template<> struct is_cl_type<cl_uchar> { enum { value = true }; };
517 template<> struct is_cl_type<cl_char> { enum { value = true }; };
518 template<> struct is_cl_type<cl_ulong> { enum { value = true }; };
519 template<> struct is_cl_type<cl_long> { enum { value = true }; };
520 template<> struct is_cl_type<cl_ushort>{ enum { value = true }; };
521 template<> struct is_cl_type<cl_short> { enum { value = true }; };
525 template<class T> struct is_floating_point { enum { value = false }; };
526 template<> struct is_floating_point<float> { enum { value = true }; };
527 template<> struct is_floating_point<double> { enum { value = true }; };
528 
529 #endif
530 
531 } //namespace viennacl
532 
533 
534 #endif
Helper class for checking whether a type is a primitive type.
Definition: predicate.hpp:490
This file provides the forward declarations for the main types used within ViennaCL.
Helper metafunction for checking whether the provided type is viennacl::op_sub (for subtraction) ...
Definition: predicate.hpp:418
A dense matrix class.
Definition: forwards.h:375
Helper metafunction for checking whether the provided type is viennacl::op_div (for division) ...
Definition: predicate.hpp:466
Helper metafunction for checking whether the provided type is viennacl::op_add (for addition) ...
Definition: predicate.hpp:400
bool row_major(T const &)
Definition: row_major.hpp:38
Helper metafunction for checking whether the provided type is viennacl::op_prod (for products/multipl...
Definition: predicate.hpp:436