ViennaCL - The Vienna Computing Library  1.5.2
viennacl/meta/predicate.hpp
Go to the documentation of this file.
00001 #ifndef VIENNACL_META_PREDICATE_HPP_
00002 #define VIENNACL_META_PREDICATE_HPP_
00003 
00004 /* =========================================================================
00005    Copyright (c) 2010-2014, Institute for Microelectronics,
00006                             Institute for Analysis and Scientific Computing,
00007                             TU Wien.
00008    Portions of this software are copyright by UChicago Argonne, LLC.
00009 
00010                             -----------------
00011                   ViennaCL - The Vienna Computing Library
00012                             -----------------
00013 
00014    Project Head:    Karl Rupp                   rupp@iue.tuwien.ac.at
00015 
00016    (A list of authors and contributors can be found in the PDF manual)
00017 
00018    License:         MIT (X11), see file LICENSE in the base directory
00019 ============================================================================= */
00020 
00025 #include <string>
00026 #include <fstream>
00027 #include <sstream>
00028 #include "viennacl/forwards.h"
00029 
00030 #ifdef VIENNACL_WITH_OPENCL
00031 #ifdef __APPLE__
00032 #include <OpenCL/cl.h>
00033 #else
00034 #include "CL/cl.h"
00035 #endif
00036 #endif
00037 
00038 namespace viennacl
00039 {
00040 
00041     //
00042     // is_cpu_scalar: checks for float or double
00043     //
00044     //template <typename T>
00045     //struct is_cpu_scalar
00046     //{
00047     //  enum { value = false };
00048     //};
00049 
00051     template <> struct is_cpu_scalar<char>           { enum { value = true }; };
00052     template <> struct is_cpu_scalar<unsigned char>  { enum { value = true }; };
00053     template <> struct is_cpu_scalar<short>          { enum { value = true }; };
00054     template <> struct is_cpu_scalar<unsigned short> { enum { value = true }; };
00055     template <> struct is_cpu_scalar<int>            { enum { value = true }; };
00056     template <> struct is_cpu_scalar<unsigned int>   { enum { value = true }; };
00057     template <> struct is_cpu_scalar<long>           { enum { value = true }; };
00058     template <> struct is_cpu_scalar<unsigned long>  { enum { value = true }; };
00059     template <> struct is_cpu_scalar<float>          { enum { value = true }; };
00060     template <> struct is_cpu_scalar<double>         { enum { value = true }; };
00064     //
00065     // is_scalar: checks for viennacl::scalar
00066     //
00067     //template <typename T>
00068     //struct is_scalar
00069     //{
00070     //  enum { value = false };
00071     //};
00072 
00074     template <typename T>
00075     struct is_scalar<viennacl::scalar<T> >
00076     {
00077       enum { value = true };
00078     };
00081     //
00082     // is_flip_sign_scalar: checks for viennacl::scalar modified with unary operator-
00083     //
00084     //template <typename T>
00085     //struct is_flip_sign_scalar
00086     //{
00087     //  enum { value = false };
00088     //};
00089 
00091     template <typename T>
00092     struct is_flip_sign_scalar<viennacl::scalar_expression< const scalar<T>,
00093                                                             const scalar<T>,
00094                                                             op_flip_sign> >
00095     {
00096       enum { value = true };
00097     };
00100     //
00101     // is_any_scalar: checks for either CPU and GPU scalars, i.e. is_cpu_scalar<>::value || is_scalar<>::value
00102     //
00103     //template <typename T>
00104     //struct is_any_scalar
00105     //{
00106     //  enum { value = (is_scalar<T>::value || is_cpu_scalar<T>::value || is_flip_sign_scalar<T>::value )};
00107     //};
00108 
00109     //
00110 
00112   #define VIENNACL_MAKE_ANY_VECTOR_TRUE(type) template<> struct is_any_vector< type > { enum { value = 1 }; };
00113   #define VIENNACL_MAKE_FOR_ALL_SCALARTYPE(type) \
00114     VIENNACL_MAKE_ANY_VECTOR_TRUE(type<float>)\
00115     VIENNACL_MAKE_ANY_VECTOR_TRUE(type<double>)
00116 
00117     VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::vector)
00118     VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::vector_range)
00119     VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::vector_slice)
00120     VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::unit_vector)
00121     VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::zero_vector)
00122     VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::one_vector)
00123     VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::scalar_vector)
00124 
00125   #undef VIENNACL_MAKE_FOR_ALL_SCALARTYPE
00126   #undef VIENNACL_MAKE_ANY_VECTOR_TRUE
00127 
00131   #define VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE)\
00132     template<> struct is_any_dense_matrix< TYPE > { enum { value = 1 }; };
00133 
00134   #define VIENNACL_MAKE_FOR_ALL_SCALARTYPE(TYPE) \
00135     VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<float>)\
00136     VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<double>)
00137 
00138   #define COMMA ,
00139   #define VIENNACL_MAKE_FOR_ALL_SCALARTYPE_LAYOUT(TYPE) \
00140     VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<float COMMA viennacl::row_major>)\
00141     VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<double COMMA viennacl::row_major>)\
00142     VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<float COMMA viennacl::column_major>)\
00143     VIENNACL_MAKE_ANY_MATRIX_TRUE(TYPE<double COMMA viennacl::column_major>)
00144 
00145     VIENNACL_MAKE_FOR_ALL_SCALARTYPE_LAYOUT(viennacl::matrix)
00146 //    VIENNACL_MAKE_FOR_ALL_SCALARTYPE_LAYOUT(viennacl::matrix_range)
00147 //    VIENNACL_MAKE_FOR_ALL_SCALARTYPE_LAYOUT(viennacl::matrix_slice)
00148     VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::identity_matrix)
00149     VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::zero_matrix)
00150     VIENNACL_MAKE_FOR_ALL_SCALARTYPE(viennacl::scalar_matrix)
00151 
00152   #undef VIENNACL_MAKE_FOR_ALL_SCALARTYPE_LAYOUT
00153   #undef VIENNACL_MAKE_FOR_ALL_SCALARTYPE
00154   #undef VIENNACL_MAKE_ANY_MATRIX_TRUE
00155 
00157     //
00158     // is_row_major
00159     //
00160     //template <typename T>
00161     //struct is_row_major
00162     //{
00163     //  enum { value = false };
00164     //};
00165 
00167     template <typename ScalarType>
00168     struct is_row_major<viennacl::matrix_base<ScalarType, viennacl::row_major> >
00169     {
00170       enum { value = true };
00171     };
00172 
00173     template <>
00174     struct is_row_major< viennacl::row_major >
00175     {
00176       enum { value = true };
00177     };
00178 
00179     template <typename T>
00180     struct is_row_major<viennacl::matrix_expression<T, T, viennacl::op_trans> >
00181     {
00182       enum { value = is_row_major<T>::value };
00183     };
00187     //
00188     // is_circulant_matrix
00189     //
00190     //template <typename T>
00191     //struct is_circulant_matrix
00192     //{
00193     //  enum { value = false };
00194     //};
00195 
00197     template <typename ScalarType, unsigned int ALIGNMENT>
00198     struct is_circulant_matrix<viennacl::circulant_matrix<ScalarType, ALIGNMENT> >
00199     {
00200       enum { value = true };
00201     };
00202 
00203     template <typename ScalarType, unsigned int ALIGNMENT>
00204     struct is_circulant_matrix<const viennacl::circulant_matrix<ScalarType, ALIGNMENT> >
00205     {
00206       enum { value = true };
00207     };
00210     //
00211     // is_hankel_matrix
00212     //
00213     //template <typename T>
00214     //struct is_hankel_matrix
00215     //{
00216     //  enum { value = false };
00217     //};
00218 
00220     template <typename ScalarType, unsigned int ALIGNMENT>
00221     struct is_hankel_matrix<viennacl::hankel_matrix<ScalarType, ALIGNMENT> >
00222     {
00223       enum { value = true };
00224     };
00225 
00226     template <typename ScalarType, unsigned int ALIGNMENT>
00227     struct is_hankel_matrix<const viennacl::hankel_matrix<ScalarType, ALIGNMENT> >
00228     {
00229       enum { value = true };
00230     };
00233     //
00234     // is_toeplitz_matrix
00235     //
00236     //template <typename T>
00237     //struct is_toeplitz_matrix
00238     //{
00239     //  enum { value = false };
00240     //};
00241 
00243     template <typename ScalarType, unsigned int ALIGNMENT>
00244     struct is_toeplitz_matrix<viennacl::toeplitz_matrix<ScalarType, ALIGNMENT> >
00245     {
00246       enum { value = true };
00247     };
00248 
00249     template <typename ScalarType, unsigned int ALIGNMENT>
00250     struct is_toeplitz_matrix<const viennacl::toeplitz_matrix<ScalarType, ALIGNMENT> >
00251     {
00252       enum { value = true };
00253     };
00256     //
00257     // is_vandermonde_matrix
00258     //
00259     //template <typename T>
00260     //struct is_vandermonde_matrix
00261     //{
00262     //  enum { value = false };
00263     //};
00264 
00266     template <typename ScalarType, unsigned int ALIGNMENT>
00267     struct is_vandermonde_matrix<viennacl::vandermonde_matrix<ScalarType, ALIGNMENT> >
00268     {
00269       enum { value = true };
00270     };
00271 
00272     template <typename ScalarType, unsigned int ALIGNMENT>
00273     struct is_vandermonde_matrix<const viennacl::vandermonde_matrix<ScalarType, ALIGNMENT> >
00274     {
00275       enum { value = true };
00276     };
00280     //
00281     // is_compressed_matrix
00282     //
00283 
00285     template <typename ScalarType, unsigned int ALIGNMENT>
00286     struct is_compressed_matrix<viennacl::compressed_matrix<ScalarType, ALIGNMENT> >
00287     {
00288       enum { value = true };
00289     };
00292     //
00293     // is_coordinate_matrix
00294     //
00295 
00297     template <typename ScalarType, unsigned int ALIGNMENT>
00298     struct is_coordinate_matrix<viennacl::coordinate_matrix<ScalarType, ALIGNMENT> >
00299     {
00300       enum { value = true };
00301     };
00304     //
00305     // is_ell_matrix
00306     //
00308     template <typename ScalarType, unsigned int ALIGNMENT>
00309     struct is_ell_matrix<viennacl::ell_matrix<ScalarType, ALIGNMENT> >
00310     {
00311       enum { value = true };
00312     };
00315     //
00316     // is_hyb_matrix
00317     //
00319     template <typename ScalarType, unsigned int ALIGNMENT>
00320     struct is_hyb_matrix<viennacl::hyb_matrix<ScalarType, ALIGNMENT> >
00321     {
00322       enum { value = true };
00323     };
00327     //
00328     // is_any_sparse_matrix
00329     //
00330     //template <typename T>
00331     //struct is_any_sparse_matrix
00332     //{
00333     //  enum { value = false };
00334     //};
00335 
00337     template <typename ScalarType, unsigned int ALIGNMENT>
00338     struct is_any_sparse_matrix<viennacl::compressed_matrix<ScalarType, ALIGNMENT> >
00339     {
00340       enum { value = true };
00341     };
00342 
00343     template <typename ScalarType>
00344     struct is_any_sparse_matrix<viennacl::compressed_compressed_matrix<ScalarType> >
00345     {
00346       enum { value = true };
00347     };
00348 
00349     template <typename ScalarType, unsigned int ALIGNMENT>
00350     struct is_any_sparse_matrix<viennacl::coordinate_matrix<ScalarType, ALIGNMENT> >
00351     {
00352       enum { value = true };
00353     };
00354 
00355     template <typename ScalarType, unsigned int ALIGNMENT>
00356     struct is_any_sparse_matrix<viennacl::ell_matrix<ScalarType, ALIGNMENT> >
00357     {
00358       enum { value = true };
00359     };
00360 
00361     template <typename ScalarType, unsigned int ALIGNMENT>
00362     struct is_any_sparse_matrix<viennacl::hyb_matrix<ScalarType, ALIGNMENT> >
00363     {
00364       enum { value = true };
00365     };
00366 
00367     template <typename T>
00368     struct is_any_sparse_matrix<const T>
00369     {
00370       enum { value = is_any_sparse_matrix<T>::value };
00371     };
00372 
00375 
00376 
00377     //
00378     // is_addition
00379     //
00381     template <typename T>
00382     struct is_addition
00383     {
00384       enum { value = false };
00385     };
00386 
00388     template <>
00389     struct is_addition<viennacl::op_add>
00390     {
00391       enum { value = true };
00392     };
00395     //
00396     // is_subtraction
00397     //
00399     template <typename T>
00400     struct is_subtraction
00401     {
00402       enum { value = false };
00403     };
00404 
00406     template <>
00407     struct is_subtraction<viennacl::op_sub>
00408     {
00409       enum { value = true };
00410     };
00413     //
00414     // is_product
00415     //
00417     template <typename T>
00418     struct is_product
00419     {
00420       enum { value = false };
00421     };
00422 
00424     template <>
00425     struct is_product<viennacl::op_prod>
00426     {
00427       enum { value = true };
00428     };
00429 
00430     template <>
00431     struct is_product<viennacl::op_mult>
00432     {
00433       enum { value = true };
00434     };
00435 
00436     template <>
00437     struct is_product<viennacl::op_element_binary<op_prod> >
00438     {
00439       enum { value = true };
00440     };
00443     //
00444     // is_division
00445     //
00447     template <typename T>
00448     struct is_division
00449     {
00450       enum { value = false };
00451     };
00452 
00454     template <>
00455     struct is_division<viennacl::op_div>
00456     {
00457       enum { value = true };
00458     };
00459 
00460     template <>
00461     struct is_division<viennacl::op_element_binary<op_div> >
00462     {
00463       enum { value = true };
00464     };
00467         // is_primitive_type
00468     //
00469 
00471     template<class T>
00472     struct is_primitive_type{ enum {value = false}; };
00473 
00475     template<> struct is_primitive_type<float>         { enum { value = true }; };
00476     template<> struct is_primitive_type<double>        { enum { value = true }; };
00477     template<> struct is_primitive_type<unsigned int>  { enum { value = true }; };
00478     template<> struct is_primitive_type<int>           { enum { value = true }; };
00479     template<> struct is_primitive_type<unsigned char> { enum { value = true }; };
00480     template<> struct is_primitive_type<char>          { enum { value = true }; };
00481     template<> struct is_primitive_type<unsigned long> { enum { value = true }; };
00482     template<> struct is_primitive_type<long>          { enum { value = true }; };
00483     template<> struct is_primitive_type<unsigned short>{ enum { value = true }; };
00484     template<> struct is_primitive_type<short>         { enum { value = true }; };
00487 #ifdef VIENNACL_WITH_OPENCL
00488 
00490     template<class T>
00491     struct is_cl_type{ enum { value = false }; };
00492 
00494     template<> struct is_cl_type<cl_float> { enum { value = true }; };
00495     template<> struct is_cl_type<cl_double>{ enum { value = true }; };
00496     template<> struct is_cl_type<cl_uint>  { enum { value = true }; };
00497     template<> struct is_cl_type<cl_int>   { enum { value = true }; };
00498     template<> struct is_cl_type<cl_uchar> { enum { value = true }; };
00499     template<> struct is_cl_type<cl_char>  { enum { value = true }; };
00500     template<> struct is_cl_type<cl_ulong> { enum { value = true }; };
00501     template<> struct is_cl_type<cl_long>  { enum { value = true }; };
00502     template<> struct is_cl_type<cl_ushort>{ enum { value = true }; };
00503     template<> struct is_cl_type<cl_short> { enum { value = true }; };
00506 #endif
00507 
00508 } //namespace viennacl
00509 
00510 
00511 #endif