ViennaCL - The Vienna Computing Library  1.5.2
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-2014, 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 PDF 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_SCALARTYPE(type) \
114  VIENNACL_MAKE_ANY_VECTOR_TRUE(type<float>)\
115  VIENNACL_MAKE_ANY_VECTOR_TRUE(type<double>)
116 
117  VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::vector)
118  VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::vector_range)
119  VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::vector_slice)
120  VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::unit_vector)
121  VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::zero_vector)
122  VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::one_vector)
123  VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::scalar_vector)
124 
125  #undef VIENNACL_MAKE_FOR_ALL_SCALARTYPE
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_SCALARTYPE(TYPE) \
135  VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<float>)\
136  VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<double>)
137 
138  #define COMMA ,
139  #define VIENNACL_MAKE_FOR_ALL_SCALARTYPE_LAYOUT(TYPE) \
140  VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<float COMMA viennacl::row_major>)\
141  VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<double COMMA viennacl::row_major>)\
142  VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<float COMMA viennacl::column_major>)\
143  VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<double COMMA viennacl::column_major>)
144 
145  VIENNACL_MAKE_FOR_ALL_SCALARTYPE_LAYOUT(viennacl::matrix)
146 // VIENNACL_MAKE_FOR_ALL_SCALARTYPE_LAYOUT(viennacl::matrix_range)
147 // VIENNACL_MAKE_FOR_ALL_SCALARTYPE_LAYOUT(viennacl::matrix_slice)
148  VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::identity_matrix)
149  VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::zero_matrix)
150  VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::scalar_matrix)
151 
152  #undef VIENNACL_MAKE_FOR_ALL_SCALARTYPE_LAYOUT
153  #undef VIENNACL_MAKE_FOR_ALL_SCALARTYPE
154  #undef VIENNACL_MAKE_ANY_MATRIX_TRUE
155 
157  //
158  // is_row_major
159  //
160  //template <typename T>
161  //struct is_row_major
162  //{
163  // enum { value = false };
164  //};
165 
167  template <typename ScalarType>
168  struct is_row_major<viennacl::matrix_base<ScalarType, viennacl::row_major> >
169  {
170  enum { value = true };
171  };
172 
173  template <>
174  struct is_row_major< viennacl::row_major >
175  {
176  enum { value = true };
177  };
178 
179  template <typename T>
180  struct is_row_major<viennacl::matrix_expression<T, T, viennacl::op_trans> >
181  {
182  enum { value = is_row_major<T>::value };
183  };
187  //
188  // is_circulant_matrix
189  //
190  //template <typename T>
191  //struct is_circulant_matrix
192  //{
193  // enum { value = false };
194  //};
195 
197  template <typename ScalarType, unsigned int ALIGNMENT>
198  struct is_circulant_matrix<viennacl::circulant_matrix<ScalarType, ALIGNMENT> >
199  {
200  enum { value = true };
201  };
202 
203  template <typename ScalarType, unsigned int ALIGNMENT>
204  struct is_circulant_matrix<const viennacl::circulant_matrix<ScalarType, ALIGNMENT> >
205  {
206  enum { value = true };
207  };
210  //
211  // is_hankel_matrix
212  //
213  //template <typename T>
214  //struct is_hankel_matrix
215  //{
216  // enum { value = false };
217  //};
218 
220  template <typename ScalarType, unsigned int ALIGNMENT>
221  struct is_hankel_matrix<viennacl::hankel_matrix<ScalarType, ALIGNMENT> >
222  {
223  enum { value = true };
224  };
225 
226  template <typename ScalarType, unsigned int ALIGNMENT>
227  struct is_hankel_matrix<const viennacl::hankel_matrix<ScalarType, ALIGNMENT> >
228  {
229  enum { value = true };
230  };
233  //
234  // is_toeplitz_matrix
235  //
236  //template <typename T>
237  //struct is_toeplitz_matrix
238  //{
239  // enum { value = false };
240  //};
241 
243  template <typename ScalarType, unsigned int ALIGNMENT>
244  struct is_toeplitz_matrix<viennacl::toeplitz_matrix<ScalarType, ALIGNMENT> >
245  {
246  enum { value = true };
247  };
248 
249  template <typename ScalarType, unsigned int ALIGNMENT>
250  struct is_toeplitz_matrix<const viennacl::toeplitz_matrix<ScalarType, ALIGNMENT> >
251  {
252  enum { value = true };
253  };
256  //
257  // is_vandermonde_matrix
258  //
259  //template <typename T>
260  //struct is_vandermonde_matrix
261  //{
262  // enum { value = false };
263  //};
264 
266  template <typename ScalarType, unsigned int ALIGNMENT>
267  struct is_vandermonde_matrix<viennacl::vandermonde_matrix<ScalarType, ALIGNMENT> >
268  {
269  enum { value = true };
270  };
271 
272  template <typename ScalarType, unsigned int ALIGNMENT>
273  struct is_vandermonde_matrix<const viennacl::vandermonde_matrix<ScalarType, ALIGNMENT> >
274  {
275  enum { value = true };
276  };
280  //
281  // is_compressed_matrix
282  //
283 
285  template <typename ScalarType, unsigned int ALIGNMENT>
286  struct is_compressed_matrix<viennacl::compressed_matrix<ScalarType, ALIGNMENT> >
287  {
288  enum { value = true };
289  };
292  //
293  // is_coordinate_matrix
294  //
295 
297  template <typename ScalarType, unsigned int ALIGNMENT>
298  struct is_coordinate_matrix<viennacl::coordinate_matrix<ScalarType, ALIGNMENT> >
299  {
300  enum { value = true };
301  };
304  //
305  // is_ell_matrix
306  //
308  template <typename ScalarType, unsigned int ALIGNMENT>
309  struct is_ell_matrix<viennacl::ell_matrix<ScalarType, ALIGNMENT> >
310  {
311  enum { value = true };
312  };
315  //
316  // is_hyb_matrix
317  //
319  template <typename ScalarType, unsigned int ALIGNMENT>
320  struct is_hyb_matrix<viennacl::hyb_matrix<ScalarType, ALIGNMENT> >
321  {
322  enum { value = true };
323  };
327  //
328  // is_any_sparse_matrix
329  //
330  //template <typename T>
331  //struct is_any_sparse_matrix
332  //{
333  // enum { value = false };
334  //};
335 
337  template <typename ScalarType, unsigned int ALIGNMENT>
338  struct is_any_sparse_matrix<viennacl::compressed_matrix<ScalarType, ALIGNMENT> >
339  {
340  enum { value = true };
341  };
342 
343  template <typename ScalarType>
344  struct is_any_sparse_matrix<viennacl::compressed_compressed_matrix<ScalarType> >
345  {
346  enum { value = true };
347  };
348 
349  template <typename ScalarType, unsigned int ALIGNMENT>
350  struct is_any_sparse_matrix<viennacl::coordinate_matrix<ScalarType, ALIGNMENT> >
351  {
352  enum { value = true };
353  };
354 
355  template <typename ScalarType, unsigned int ALIGNMENT>
356  struct is_any_sparse_matrix<viennacl::ell_matrix<ScalarType, ALIGNMENT> >
357  {
358  enum { value = true };
359  };
360 
361  template <typename ScalarType, unsigned int ALIGNMENT>
362  struct is_any_sparse_matrix<viennacl::hyb_matrix<ScalarType, ALIGNMENT> >
363  {
364  enum { value = true };
365  };
366 
367  template <typename T>
368  struct is_any_sparse_matrix<const T>
369  {
370  enum { value = is_any_sparse_matrix<T>::value };
371  };
372 
375 
377  //
378  // is_addition
379  //
381  template <typename T>
382  struct is_addition
383  {
384  enum { value = false };
385  };
386 
388  template <>
389  struct is_addition<viennacl::op_add>
390  {
391  enum { value = true };
392  };
395  //
396  // is_subtraction
397  //
399  template <typename T>
401  {
402  enum { value = false };
403  };
404 
406  template <>
407  struct is_subtraction<viennacl::op_sub>
408  {
409  enum { value = true };
410  };
413  //
414  // is_product
415  //
417  template <typename T>
418  struct is_product
419  {
420  enum { value = false };
421  };
422 
424  template <>
425  struct is_product<viennacl::op_prod>
426  {
427  enum { value = true };
428  };
429 
430  template <>
431  struct is_product<viennacl::op_mult>
432  {
433  enum { value = true };
434  };
435 
436  template <>
437  struct is_product<viennacl::op_element_binary<op_prod> >
438  {
439  enum { value = true };
440  };
443  //
444  // is_division
445  //
447  template <typename T>
448  struct is_division
449  {
450  enum { value = false };
451  };
452 
454  template <>
455  struct is_division<viennacl::op_div>
456  {
457  enum { value = true };
458  };
459 
460  template <>
461  struct is_division<viennacl::op_element_binary<op_div> >
462  {
463  enum { value = true };
464  };
467  // is_primitive_type
468  //
469 
471  template<class T>
472  struct is_primitive_type{ enum {value = false}; };
473 
475  template<> struct is_primitive_type<float> { enum { value = true }; };
476  template<> struct is_primitive_type<double> { enum { value = true }; };
477  template<> struct is_primitive_type<unsigned int> { enum { value = true }; };
478  template<> struct is_primitive_type<int> { enum { value = true }; };
479  template<> struct is_primitive_type<unsigned char> { enum { value = true }; };
480  template<> struct is_primitive_type<char> { enum { value = true }; };
481  template<> struct is_primitive_type<unsigned long> { enum { value = true }; };
482  template<> struct is_primitive_type<long> { enum { value = true }; };
483  template<> struct is_primitive_type<unsigned short>{ enum { value = true }; };
484  template<> struct is_primitive_type<short> { enum { value = true }; };
487 #ifdef VIENNACL_WITH_OPENCL
488 
490  template<class T>
491  struct is_cl_type{ enum { value = false }; };
492 
494  template<> struct is_cl_type<cl_float> { enum { value = true }; };
495  template<> struct is_cl_type<cl_double>{ enum { value = true }; };
496  template<> struct is_cl_type<cl_uint> { enum { value = true }; };
497  template<> struct is_cl_type<cl_int> { enum { value = true }; };
498  template<> struct is_cl_type<cl_uchar> { enum { value = true }; };
499  template<> struct is_cl_type<cl_char> { enum { value = true }; };
500  template<> struct is_cl_type<cl_ulong> { enum { value = true }; };
501  template<> struct is_cl_type<cl_long> { enum { value = true }; };
502  template<> struct is_cl_type<cl_ushort>{ enum { value = true }; };
503  template<> struct is_cl_type<cl_short> { enum { value = true }; };
506 #endif
507 
508 } //namespace viennacl
509 
510 
511 #endif
bool is_row_major(viennacl::row_major_tag)
Definition: common.hpp:73
Definition: forwards.h:415
Definition: forwards.h:429
Helper class for checking whether a type is a primitive type.
Definition: predicate.hpp:472
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:400
A dense matrix class.
Definition: forwards.h:293
Definition: forwards.h:436
Definition: forwards.h:401
Definition: forwards.h:365
Definition: predicate.hpp:472
Definition: predicate.hpp:450
Definition: forwards.h:444
Definition: forwards.h:379
Definition: forwards.h:458
Definition: forwards.h:465
Definition: predicate.hpp:384
A vector class representing a linear memory sequence on the GPU. Inspired by boost::numeric::ublas::v...
Definition: forwards.h:208
Helper metafunction for checking whether the provided type is viennacl::op_div (for division) ...
Definition: predicate.hpp:448
Definition: forwards.h:372
Definition: forwards.h:408
Definition: forwards.h:451
Helper metafunction for checking whether the provided type is viennacl::op_add (for addition) ...
Definition: predicate.hpp:382
Definition: predicate.hpp:402
Helper metafunction for checking whether the provided type is viennacl::op_prod (for products/multipl...
Definition: predicate.hpp:418
Definition: forwards.h:422
Definition: predicate.hpp:420