Skylark (Sketching Library)
0.1
|
00001 #include "boost/property_tree/ptree.hpp" 00002 00003 #include "sketchc.hpp" 00004 #include "../../base/exception.hpp" 00005 #include "../../base/sparse_matrix.hpp" 00006 00007 #ifdef SKYLARK_HAVE_COMBBLAS 00008 #include "CombBLAS.h" 00009 #include "SpParMat.h" 00010 #include "SpParVec.h" 00011 #include "DenseParVec.h" 00012 #endif 00013 00014 # define STRCMP_TYPE(STR, TYPE) \ 00015 if (std::strcmp(str, #STR) == 0) \ 00016 return TYPE; 00017 00018 static sketchc::matrix_type_t str2matrix_type(const char *str) { 00019 STRCMP_TYPE(Matrix, sketchc::MATRIX); 00020 STRCMP_TYPE(SharedMatrix, sketchc::SHARED_MATRIX); 00021 STRCMP_TYPE(RootMatrix, sketchc::ROOT_MATRIX); 00022 STRCMP_TYPE(DistMatrix, sketchc::DIST_MATRIX); 00023 STRCMP_TYPE(DistMatrix_VC_STAR, sketchc::DIST_MATRIX_VC_STAR); 00024 STRCMP_TYPE(DistMatrix_VR_STAR, sketchc::DIST_MATRIX_VR_STAR); 00025 STRCMP_TYPE(DistMatrix_STAR_VC, sketchc::DIST_MATRIX_VC_STAR); 00026 STRCMP_TYPE(DistMatrix_STAR_VR, sketchc::DIST_MATRIX_VR_STAR); 00027 STRCMP_TYPE(SparseMatrix, sketchc::SPARSE_MATRIX); 00028 STRCMP_TYPE(DistSparseMatrix, sketchc::DIST_SPARSE_MATRIX); 00029 00030 return sketchc::MATRIX_TYPE_ERROR; 00031 } 00032 00033 static sketchc::transform_type_t str2transform_type(const char *str) { 00034 STRCMP_TYPE(JLT, sketchc::JLT); 00035 STRCMP_TYPE(CT, sketchc::CT); 00036 STRCMP_TYPE(FJLT, sketchc::FJLT); 00037 STRCMP_TYPE(CWT, sketchc::CWT); 00038 STRCMP_TYPE(MMT, sketchc::MMT); 00039 STRCMP_TYPE(WZT, sketchc::WZT); 00040 STRCMP_TYPE(PPT, sketchc::PPT); 00041 STRCMP_TYPE(GaussianRFT, sketchc::GaussianRFT); 00042 STRCMP_TYPE(LaplacianRFT, sketchc::LaplacianRFT); 00043 STRCMP_TYPE(FastGaussianRFT, sketchc::FastGaussianRFT); 00044 STRCMP_TYPE(ExpSemigroupRLT, sketchc::ExpSemigroupRLT); 00045 00046 return sketchc::TRANSFORM_TYPE_ERROR; 00047 } 00048 00049 // Just for shorter notation 00050 #if SKYLARK_HAVE_ELEMENTAL 00051 typedef elem::Matrix<double> Matrix; 00052 typedef elem::DistMatrix<double, elem::STAR, elem::STAR> SharedMatrix; 00053 typedef elem::DistMatrix<double, elem::CIRC, elem::CIRC> RootMatrix; 00054 typedef elem::DistMatrix<double> DistMatrix; 00055 typedef elem::DistMatrix<double, elem::VR, elem::STAR> DistMatrix_VR_STAR; 00056 typedef elem::DistMatrix<double, elem::VC, elem::STAR> DistMatrix_VC_STAR; 00057 typedef elem::DistMatrix<double, elem::STAR, elem::VR> DistMatrix_STAR_VR; 00058 typedef elem::DistMatrix<double, elem::STAR, elem::VC> DistMatrix_STAR_VC; 00059 #endif 00060 typedef base::sparse_matrix_t<double> SparseMatrix; 00061 #ifdef SKYLARK_HAVE_COMBBLAS 00062 typedef SpDCCols< size_t, double > col_t; 00063 typedef SpParMat< size_t, double, col_t > DistSparseMatrix; 00064 #endif 00065 00066 00067 extern "C" { 00068 00070 SKYLARK_EXTERN_API char *sl_supported_sketch_transforms() { 00071 #define QUOTE(x) #x 00072 #define SKDEF(t,i,o) "(\"" QUOTE(t) "\",\"" QUOTE(i) "\",\"" QUOTE(o) "\") " 00073 00074 return 00075 #if SKYLARK_HAVE_ELEMENTAL 00076 SKDEF(JLT, Matrix, Matrix) 00077 SKDEF(JLT, SparseMatrix, Matrix) 00078 SKDEF(JLT, DistMatrix, Matrix) 00079 SKDEF(JLT, DistMatrix, DistMatrix) 00080 SKDEF(JLT, DistMatrix_VR_STAR, Matrix) 00081 SKDEF(JLT, DistMatrix_VC_STAR, Matrix) 00082 SKDEF(JLT, DistMatrix_VR_STAR, SharedMatrix) 00083 SKDEF(JLT, DistMatrix_VC_STAR, SharedMatrix) 00084 SKDEF(JLT, DistMatrix_VR_STAR, DistMatrix_VR_STAR) 00085 SKDEF(JLT, DistMatrix_VC_STAR, DistMatrix_VC_STAR) 00086 SKDEF(JLT, DistMatrix_STAR_VR, Matrix) 00087 SKDEF(JLT, DistMatrix_STAR_VC, Matrix) 00088 SKDEF(JLT, DistMatrix_STAR_VR, DistMatrix_STAR_VR) 00089 SKDEF(JLT, DistMatrix_STAR_VC, DistMatrix_STAR_VC) 00090 SKDEF(CT, Matrix, Matrix) 00091 SKDEF(CT, DistMatrix, Matrix) 00092 SKDEF(CT, SparseMatrix, Matrix) 00093 SKDEF(CT, DistMatrix, DistMatrix) 00094 SKDEF(CT, DistMatrix_VR_STAR, Matrix) 00095 SKDEF(CT, DistMatrix_VC_STAR, Matrix) 00096 SKDEF(CT, DistMatrix_VR_STAR, SharedMatrix) 00097 SKDEF(CT, DistMatrix_VC_STAR, SharedMatrix) 00098 SKDEF(CT, DistMatrix_VR_STAR, DistMatrix_VR_STAR) 00099 SKDEF(CT, DistMatrix_VC_STAR, DistMatrix_VC_STAR) 00100 SKDEF(CT, DistMatrix_STAR_VR, Matrix) 00101 SKDEF(CT, DistMatrix_STAR_VC, Matrix) 00102 SKDEF(CT, DistMatrix_STAR_VR, DistMatrix_STAR_VR) 00103 SKDEF(CT, DistMatrix_STAR_VC, DistMatrix_STAR_VC) 00104 SKDEF(CWT, Matrix, Matrix) 00105 SKDEF(CWT, SparseMatrix, Matrix) 00106 SKDEF(CWT, SparseMatrix, SparseMatrix) 00107 SKDEF(CWT, DistMatrix, Matrix) 00108 SKDEF(CWT, DistMatrix_VR_STAR, Matrix) 00109 SKDEF(CWT, DistMatrix_VC_STAR, Matrix) 00110 SKDEF(CWT, DistMatrix_STAR_VR, Matrix) 00111 SKDEF(CWT, DistMatrix_STAR_VC, Matrix) 00112 SKDEF(MMT, Matrix, Matrix) 00113 SKDEF(MMT, SparseMatrix, Matrix) 00114 SKDEF(MMT, SparseMatrix, SparseMatrix) 00115 SKDEF(MMT, DistMatrix, Matrix) 00116 SKDEF(MMT, DistMatrix_VR_STAR, Matrix) 00117 SKDEF(MMT, DistMatrix_VC_STAR, Matrix) 00118 SKDEF(MMT, DistMatrix_STAR_VR, Matrix) 00119 SKDEF(MMT, DistMatrix_STAR_VC, Matrix) 00120 SKDEF(WZT, Matrix, Matrix) 00121 SKDEF(WZT, SparseMatrix, Matrix) 00122 SKDEF(WZT, SparseMatrix, SparseMatrix) 00123 SKDEF(WZT, DistMatrix, Matrix) 00124 SKDEF(WZT, DistMatrix_VR_STAR, Matrix) 00125 SKDEF(WZT, DistMatrix_VC_STAR, Matrix) 00126 SKDEF(WZT, DistMatrix_STAR_VR, Matrix) 00127 SKDEF(WZT, DistMatrix_STAR_VC, Matrix) 00128 SKDEF(PPT, Matrix, Matrix) 00129 SKDEF(PPT, SparseMatrix, Matrix) 00130 SKDEF(GaussianRFT, Matrix, Matrix) 00131 SKDEF(GaussianRFT, SparseMatrix, Matrix) 00132 SKDEF(GaussianRFT, DistMatrix_VR_STAR, DistMatrix_VR_STAR) 00133 SKDEF(GaussianRFT, DistMatrix_VC_STAR, DistMatrix_VC_STAR) 00134 SKDEF(LaplacianRFT, Matrix, Matrix) 00135 SKDEF(LaplacianRFT, SparseMatrix, Matrix) 00136 SKDEF(LaplacianRFT, DistMatrix_VR_STAR, DistMatrix_VR_STAR) 00137 SKDEF(LaplacianRFT, DistMatrix_VC_STAR, DistMatrix_VC_STAR) 00138 SKDEF(ExpSemigroupRLT, Matrix, Matrix) 00139 SKDEF(ExpSemigroupRLT, SparseMatrix, Matrix) 00140 00141 #ifdef SKYLARK_HAVE_COMBBLAS 00142 SKDEF(CWT, DistSparseMatrix, Matrix) 00143 SKDEF(CWT, DistSparseMatrix, DistMatrix) 00144 SKDEF(CWT, DistSparseMatrix, DistMatrix_VC_STAR) 00145 SKDEF(CWT, DistSparseMatrix, DistMatrix_VR_STAR) 00146 SKDEF(MMT, DistSparseMatrix, Matrix) 00147 SKDEF(MMT, DistSparseMatrix, DistMatrix) 00148 SKDEF(MMT, DistSparseMatrix, DistMatrix_VC_STAR) 00149 SKDEF(MMT, DistSparseMatrix, DistMatrix_VR_STAR) 00150 #endif 00151 00152 #if SKYLARK_HAVE_FFTW || SKYLARK_HAVE_SPIRALWHT 00153 SKDEF(FJLT, DistMatrix_VR_STAR, Matrix) 00154 SKDEF(FJLT, DistMatrix_VC_STAR, Matrix) 00155 SKDEF(FastGaussianRFT, Matrix, Matrix) 00156 SKDEF(FastGaussianRFT, SparseMatrix, Matrix) 00157 #endif 00158 00159 #endif 00160 00161 #ifdef SKYLARK_HAVE_COMBBLAS 00162 SKDEF(CWT, DistSparseMatrix, DistSparseMatrix) 00163 SKDEF(CWT, DistSparseMatrix, SparseMatrix) 00164 SKDEF(MMT, DistSparseMatrix, DistSparseMatrix) 00165 SKDEF(MMT, DistSparseMatrix, SparseMatrix) 00166 #endif 00167 00168 ""; 00169 } 00170 00171 SKYLARK_EXTERN_API const char* sl_strerror(const int error_code) { 00172 return skylark_strerror(error_code); 00173 } 00174 00175 SKYLARK_EXTERN_API bool sl_has_elemental() { 00176 #if SKYLARK_HAVE_ELEMENTAL 00177 return true; 00178 #else 00179 return false; 00180 #endif 00181 } 00182 00183 SKYLARK_EXTERN_API bool sl_has_combblas() { 00184 #if SKYLARK_HAVE_COMBBLAS 00185 return true; 00186 #else 00187 return false; 00188 #endif 00189 } 00190 00192 SKYLARK_EXTERN_API int sl_create_default_context(int seed, 00193 base::context_t **ctxt) { 00194 SKYLARK_BEGIN_TRY() 00195 *ctxt = new base::context_t(seed); 00196 SKYLARK_END_TRY() 00197 SKYLARK_CATCH_AND_RETURN_ERROR_CODE(); 00198 return 0; 00199 } 00200 00201 SKYLARK_EXTERN_API int sl_create_context(int seed, 00202 MPI_Comm comm, base::context_t **ctxt) { 00203 SKYLARK_BEGIN_TRY() 00204 *ctxt = new base::context_t(seed); 00205 SKYLARK_END_TRY() 00206 SKYLARK_CATCH_AND_RETURN_ERROR_CODE(); 00207 return 0; 00208 } 00209 00210 SKYLARK_EXTERN_API int sl_free_context(base::context_t *ctxt) { 00211 SKYLARK_BEGIN_TRY() 00212 delete ctxt; 00213 SKYLARK_END_TRY() 00214 SKYLARK_CATCH_AND_RETURN_ERROR_CODE(); 00215 return 0; 00216 } 00217 00219 SKYLARK_EXTERN_API int sl_create_sketch_transform(base::context_t *ctxt, 00220 char *type_, int n, int s, 00221 sketchc::sketch_transform_t **sketch, ...) { 00222 00223 sketchc::transform_type_t type = str2transform_type(type_); 00224 00225 # define AUTO_NEW_DISPATCH(T, C) \ 00226 SKYLARK_BEGIN_TRY() \ 00227 if (type == T) \ 00228 *sketch = new sketchc::sketch_transform_t(type, \ 00229 new C(n, s, *ctxt)); \ 00230 SKYLARK_END_TRY() \ 00231 SKYLARK_CATCH_AND_RETURN_ERROR_CODE(); 00232 00233 # define AUTO_NEW_DISPATCH_1P(T, C) \ 00234 SKYLARK_BEGIN_TRY() \ 00235 if (type == T) { \ 00236 va_list argp; \ 00237 va_start(argp, sketch); \ 00238 double p1 = va_arg(argp, double); \ 00239 sketchc::sketch_transform_t *r = \ 00240 new sketchc::sketch_transform_t(type, \ 00241 new C(n, s, p1, *ctxt)); \ 00242 va_end(argp); \ 00243 *sketch = r; \ 00244 } \ 00245 SKYLARK_END_TRY() \ 00246 SKYLARK_CATCH_AND_RETURN_ERROR_CODE(); 00247 00248 AUTO_NEW_DISPATCH(sketchc::JLT, sketch::JLT_data_t); 00249 AUTO_NEW_DISPATCH(sketchc::FJLT, sketch::FJLT_data_t); 00250 AUTO_NEW_DISPATCH_1P(sketchc::CT, sketch::CT_data_t); 00251 AUTO_NEW_DISPATCH(sketchc::CWT, sketch::CWT_data_t); 00252 AUTO_NEW_DISPATCH(sketchc::MMT, sketch::MMT_data_t); 00253 AUTO_NEW_DISPATCH_1P(sketchc::WZT, sketch::WZT_data_t) 00254 AUTO_NEW_DISPATCH_1P(sketchc::GaussianRFT, sketch::GaussianRFT_data_t); 00255 AUTO_NEW_DISPATCH_1P(sketchc::LaplacianRFT, sketch::LaplacianRFT_data_t); 00256 AUTO_NEW_DISPATCH_1P(sketchc::ExpSemigroupRLT, sketch::ExpSemigroupRLT_data_t); 00257 AUTO_NEW_DISPATCH_1P(sketchc::FastGaussianRFT, sketch::FastGaussianRFT_data_t); 00258 00259 SKYLARK_BEGIN_TRY() 00260 if (type == sketchc::PPT) { 00261 va_list argp; 00262 va_start(argp, sketch); 00263 double q = va_arg(argp, int); 00264 double c = va_arg(argp, double); 00265 double g = va_arg(argp, double); 00266 sketchc::sketch_transform_t *r = 00267 new sketchc::sketch_transform_t(sketchc::PPT, 00268 new sketch::PPT_data_t(n, s, q, c, g, *ctxt)); 00269 va_end(argp); 00270 *sketch = r; 00271 } 00272 SKYLARK_END_TRY() 00273 SKYLARK_CATCH_AND_RETURN_ERROR_CODE(); 00274 00275 return 0; 00276 } 00277 00278 SKYLARK_EXTERN_API int sl_deserialize_sketch_transform(const char *data, 00279 sketchc::sketch_transform_t **sketch) { 00280 00281 std::stringstream json_data(data); 00282 boost::property_tree::ptree pt; 00283 boost::property_tree::read_json(json_data, pt); 00284 00285 sketch::sketch_transform_data_t *sketch_data = 00286 sketch::sketch_transform_data_t::from_ptree(pt); 00287 sketchc::transform_type_t type = 00288 str2transform_type(sketch_data->get_type().c_str()); 00289 *sketch = new sketchc::sketch_transform_t(type, sketch_data); 00290 00291 return 0; 00292 } 00293 00294 SKYLARK_EXTERN_API int sl_serialize_sketch_transform( 00295 const sketchc::sketch_transform_t *sketch, char **data) { 00296 00297 boost::property_tree::ptree pt = sketch->transform_obj->to_ptree(); 00298 std::stringstream json_data; 00299 boost::property_tree::write_json(json_data, pt); 00300 *data = new char[json_data.str().length() + 1]; 00301 std::strcpy(*data, json_data.str().c_str()); 00302 00303 return 0; 00304 } 00305 00306 SKYLARK_EXTERN_API 00307 int sl_free_sketch_transform(sketchc::sketch_transform_t *S) { 00308 00309 sketchc::transform_type_t type = S->type; 00310 00311 # define AUTO_DELETE_DISPATCH(T, C) \ 00312 SKYLARK_BEGIN_TRY() \ 00313 if (type == T) \ 00314 delete static_cast<C *>(S->transform_obj); \ 00315 SKYLARK_END_TRY() \ 00316 SKYLARK_CATCH_AND_RETURN_ERROR_CODE(); 00317 00318 AUTO_DELETE_DISPATCH(sketchc::JLT, sketch::JLT_data_t); 00319 AUTO_DELETE_DISPATCH(sketchc::FJLT, sketch::FJLT_data_t); 00320 AUTO_DELETE_DISPATCH(sketchc::CT, sketch::CT_data_t); 00321 AUTO_DELETE_DISPATCH(sketchc::CWT, sketch::CWT_data_t); 00322 AUTO_DELETE_DISPATCH(sketchc::MMT, sketch::MMT_data_t); 00323 AUTO_DELETE_DISPATCH(sketchc::WZT, sketch::WZT_data_t); 00324 AUTO_DELETE_DISPATCH(sketchc::PPT, sketch::PPT_data_t); 00325 AUTO_DELETE_DISPATCH(sketchc::GaussianRFT, sketch::GaussianRFT_data_t); 00326 AUTO_DELETE_DISPATCH(sketchc::LaplacianRFT, sketch::LaplacianRFT_data_t); 00327 AUTO_DELETE_DISPATCH(sketchc::ExpSemigroupRLT, sketch::ExpSemigroupRLT_data_t); 00328 AUTO_DELETE_DISPATCH(sketchc::FastGaussianRFT, sketch::FastGaussianRFT_data_t); 00329 00330 // Now can delete object 00331 delete S; 00332 return 0; 00333 } 00334 00335 SKYLARK_EXTERN_API int 00336 sl_apply_sketch_transform(sketchc::sketch_transform_t *S_, 00337 char *input_, void *A_, 00338 char *output_, void *SA_, int dim) { 00339 00340 sketchc::transform_type_t type = S_->type; 00341 sketchc::matrix_type_t input = str2matrix_type(input_); 00342 sketchc::matrix_type_t output = str2matrix_type(output_); 00343 00344 # define AUTO_APPLY_DISPATCH(T, I, O, C, IT, OT, CD) \ 00345 if (type == T && input == I && output == O) { \ 00346 C<IT, OT> S(*static_cast<CD*>(S_->transform_obj)); \ 00347 IT &A = * static_cast<IT*>(A_); \ 00348 OT &SA = * static_cast<OT*>(SA_); \ 00349 \ 00350 SKYLARK_BEGIN_TRY() \ 00351 if (dim == SL_COLUMNWISE) \ 00352 S.apply(A, SA, sketch::columnwise_tag()); \ 00353 if (dim == SL_ROWWISE) \ 00354 S.apply(A, SA, sketch::rowwise_tag()); \ 00355 SKYLARK_END_TRY() \ 00356 SKYLARK_CATCH_AND_RETURN_ERROR_CODE(); \ 00357 } 00358 00359 #if SKYLARK_HAVE_ELEMENTAL 00360 00361 AUTO_APPLY_DISPATCH(sketchc::JLT, 00362 sketchc::MATRIX, sketchc::MATRIX, 00363 sketch::JLT_t, Matrix, Matrix, sketch::JLT_data_t); 00364 00365 AUTO_APPLY_DISPATCH(sketchc::JLT, 00366 sketchc::SPARSE_MATRIX, sketchc::MATRIX, 00367 sketch::JLT_t, SparseMatrix, Matrix, sketch::JLT_data_t); 00368 00369 AUTO_APPLY_DISPATCH(sketchc::JLT, 00370 sketchc::DIST_MATRIX, sketchc::MATRIX, 00371 sketch::JLT_t, DistMatrix, Matrix, sketch::JLT_data_t); 00372 00373 AUTO_APPLY_DISPATCH(sketchc::JLT, 00374 sketchc::DIST_MATRIX, sketchc::DIST_MATRIX, 00375 sketch::JLT_t, DistMatrix, DistMatrix, sketch::JLT_data_t); 00376 00377 AUTO_APPLY_DISPATCH(sketchc::JLT, 00378 sketchc::DIST_MATRIX_VR_STAR, sketchc::MATRIX, 00379 sketch::JLT_t, DistMatrix_VR_STAR, Matrix, sketch::JLT_data_t); 00380 00381 AUTO_APPLY_DISPATCH(sketchc::JLT, 00382 sketchc::DIST_MATRIX_VC_STAR, sketchc::MATRIX, 00383 sketch::JLT_t, DistMatrix_VC_STAR, Matrix, sketch::JLT_data_t); 00384 00385 AUTO_APPLY_DISPATCH(sketchc::JLT, 00386 sketchc::DIST_MATRIX_VR_STAR, sketchc::DIST_MATRIX_VR_STAR, 00387 sketch::JLT_t, DistMatrix_VR_STAR, DistMatrix_VR_STAR, sketch::JLT_data_t); 00388 00389 AUTO_APPLY_DISPATCH(sketchc::JLT, 00390 sketchc::DIST_MATRIX_VC_STAR, sketchc::DIST_MATRIX_VC_STAR, 00391 sketch::JLT_t, DistMatrix_VC_STAR, DistMatrix_VC_STAR, sketch::JLT_data_t); 00392 00393 AUTO_APPLY_DISPATCH(sketchc::JLT, 00394 sketchc::DIST_MATRIX_STAR_VR, sketchc::MATRIX, 00395 sketch::JLT_t, DistMatrix_STAR_VR, Matrix, sketch::JLT_data_t); 00396 00397 AUTO_APPLY_DISPATCH(sketchc::JLT, 00398 sketchc::DIST_MATRIX_STAR_VC, sketchc::MATRIX, 00399 sketch::JLT_t, DistMatrix_STAR_VC, Matrix, sketch::JLT_data_t); 00400 00401 AUTO_APPLY_DISPATCH(sketchc::JLT, 00402 sketchc::DIST_MATRIX_STAR_VR, sketchc::DIST_MATRIX_STAR_VR, 00403 sketch::JLT_t, DistMatrix_STAR_VR, DistMatrix_STAR_VR, sketch::JLT_data_t); 00404 00405 AUTO_APPLY_DISPATCH(sketchc::JLT, 00406 sketchc::DIST_MATRIX_STAR_VC, sketchc::DIST_MATRIX_STAR_VC, 00407 sketch::JLT_t, DistMatrix_STAR_VC, DistMatrix_STAR_VC, sketch::JLT_data_t); 00408 00409 AUTO_APPLY_DISPATCH(sketchc::CT, 00410 sketchc::MATRIX, sketchc::MATRIX, 00411 sketch::CT_t, Matrix, Matrix, sketch::CT_data_t); 00412 00413 AUTO_APPLY_DISPATCH(sketchc::CT, 00414 sketchc::SPARSE_MATRIX, sketchc::MATRIX, 00415 sketch::CT_t, SparseMatrix, Matrix, sketch::CT_data_t); 00416 00417 AUTO_APPLY_DISPATCH(sketchc::CT, 00418 sketchc::DIST_MATRIX, sketchc::MATRIX, 00419 sketch::CT_t, DistMatrix, Matrix, sketch::CT_data_t); 00420 00421 AUTO_APPLY_DISPATCH(sketchc::CT, 00422 sketchc::DIST_MATRIX, sketchc::DIST_MATRIX, 00423 sketch::CT_t, DistMatrix, DistMatrix, sketch::CT_data_t); 00424 00425 AUTO_APPLY_DISPATCH(sketchc::CT, 00426 sketchc::DIST_MATRIX_VR_STAR, sketchc::MATRIX, 00427 sketch::CT_t, DistMatrix_VR_STAR, Matrix, sketch::CT_data_t); 00428 00429 AUTO_APPLY_DISPATCH(sketchc::CT, 00430 sketchc::DIST_MATRIX_VC_STAR, sketchc::MATRIX, 00431 sketch::CT_t, DistMatrix_VC_STAR, Matrix, sketch::CT_data_t); 00432 00433 AUTO_APPLY_DISPATCH(sketchc::CT, 00434 sketchc::DIST_MATRIX_VR_STAR, sketchc::DIST_MATRIX_VR_STAR, 00435 sketch::CT_t, DistMatrix_VR_STAR, DistMatrix_VR_STAR, sketch::CT_data_t); 00436 00437 AUTO_APPLY_DISPATCH(sketchc::CT, 00438 sketchc::DIST_MATRIX_VC_STAR, sketchc::DIST_MATRIX_VC_STAR, 00439 sketch::CT_t, DistMatrix_VC_STAR, DistMatrix_VC_STAR, sketch::CT_data_t); 00440 00441 AUTO_APPLY_DISPATCH(sketchc::CT, 00442 sketchc::DIST_MATRIX_STAR_VR, sketchc::MATRIX, 00443 sketch::CT_t, DistMatrix_STAR_VR, Matrix, sketch::CT_data_t); 00444 00445 AUTO_APPLY_DISPATCH(sketchc::CT, 00446 sketchc::DIST_MATRIX_STAR_VC, sketchc::MATRIX, 00447 sketch::CT_t, DistMatrix_STAR_VC, Matrix, sketch::CT_data_t); 00448 00449 AUTO_APPLY_DISPATCH(sketchc::CT, 00450 sketchc::DIST_MATRIX_STAR_VR, sketchc::DIST_MATRIX_STAR_VR, 00451 sketch::CT_t, DistMatrix_STAR_VR, DistMatrix_STAR_VR, sketch::CT_data_t); 00452 00453 AUTO_APPLY_DISPATCH(sketchc::CT, 00454 sketchc::DIST_MATRIX_STAR_VC, sketchc::DIST_MATRIX_STAR_VC, 00455 sketch::CT_t, DistMatrix_STAR_VC, DistMatrix_STAR_VC, sketch::CT_data_t); 00456 00457 AUTO_APPLY_DISPATCH(sketchc::CWT, 00458 sketchc::MATRIX, sketchc::MATRIX, 00459 sketch::CWT_t, Matrix, Matrix, sketch::CWT_data_t); 00460 00461 AUTO_APPLY_DISPATCH(sketchc::CWT, 00462 sketchc::SPARSE_MATRIX, sketchc::MATRIX, 00463 sketch::CWT_t, SparseMatrix, Matrix, sketch::CWT_data_t); 00464 00465 AUTO_APPLY_DISPATCH(sketchc::CWT, 00466 sketchc::SPARSE_MATRIX, sketchc::SPARSE_MATRIX, 00467 sketch::CWT_t, SparseMatrix, SparseMatrix, 00468 sketch::CWT_data_t); 00469 00470 AUTO_APPLY_DISPATCH(sketchc::CWT, 00471 sketchc::DIST_MATRIX, sketchc::MATRIX, 00472 sketch::CWT_t, DistMatrix, Matrix, sketch::CWT_data_t); 00473 00474 AUTO_APPLY_DISPATCH(sketchc::CWT, 00475 sketchc::DIST_MATRIX_VR_STAR, sketchc::MATRIX, 00476 sketch::CWT_t, DistMatrix_VR_STAR, Matrix, sketch::CWT_data_t); 00477 00478 AUTO_APPLY_DISPATCH(sketchc::CWT, 00479 sketchc::DIST_MATRIX_VC_STAR, sketchc::MATRIX, 00480 sketch::CWT_t, DistMatrix_VC_STAR, Matrix, sketch::CWT_data_t); 00481 00482 AUTO_APPLY_DISPATCH(sketchc::CWT, 00483 sketchc::DIST_MATRIX_STAR_VR, sketchc::MATRIX, 00484 sketch::CWT_t, DistMatrix_STAR_VR, Matrix, sketch::CWT_data_t); 00485 00486 AUTO_APPLY_DISPATCH(sketchc::CWT, 00487 sketchc::DIST_MATRIX_STAR_VC, sketchc::MATRIX, 00488 sketch::CWT_t, DistMatrix_STAR_VC, Matrix, sketch::CWT_data_t); 00489 00490 AUTO_APPLY_DISPATCH(sketchc::MMT, 00491 sketchc::MATRIX, sketchc::MATRIX, 00492 sketch::MMT_t, Matrix, Matrix, sketch::MMT_data_t); 00493 00494 AUTO_APPLY_DISPATCH(sketchc::MMT, 00495 sketchc::SPARSE_MATRIX, sketchc::MATRIX, 00496 sketch::MMT_t, SparseMatrix, Matrix, sketch::MMT_data_t); 00497 00498 AUTO_APPLY_DISPATCH(sketchc::MMT, 00499 sketchc::SPARSE_MATRIX, sketchc::SPARSE_MATRIX, 00500 sketch::MMT_t, SparseMatrix, SparseMatrix, 00501 sketch::MMT_data_t); 00502 00503 AUTO_APPLY_DISPATCH(sketchc::MMT, 00504 sketchc::DIST_MATRIX, sketchc::MATRIX, 00505 sketch::MMT_t, DistMatrix, Matrix, sketch::MMT_data_t); 00506 00507 AUTO_APPLY_DISPATCH(sketchc::MMT, 00508 sketchc::DIST_MATRIX_VR_STAR, sketchc::MATRIX, 00509 sketch::MMT_t, DistMatrix_VR_STAR, Matrix, sketch::MMT_data_t); 00510 00511 AUTO_APPLY_DISPATCH(sketchc::MMT, 00512 sketchc::DIST_MATRIX_VC_STAR, sketchc::MATRIX, 00513 sketch::MMT_t, DistMatrix_VC_STAR, Matrix, sketch::MMT_data_t); 00514 00515 AUTO_APPLY_DISPATCH(sketchc::MMT, 00516 sketchc::DIST_MATRIX_STAR_VR, sketchc::MATRIX, 00517 sketch::MMT_t, DistMatrix_STAR_VR, Matrix, sketch::MMT_data_t); 00518 00519 AUTO_APPLY_DISPATCH(sketchc::MMT, 00520 sketchc::DIST_MATRIX_STAR_VC, sketchc::MATRIX, 00521 sketch::MMT_t, DistMatrix_STAR_VC, Matrix, sketch::MMT_data_t); 00522 00523 AUTO_APPLY_DISPATCH(sketchc::WZT, 00524 sketchc::MATRIX, sketchc::MATRIX, 00525 sketch::WZT_t, Matrix, Matrix, sketch::WZT_data_t); 00526 00527 AUTO_APPLY_DISPATCH(sketchc::WZT, 00528 sketchc::SPARSE_MATRIX, sketchc::MATRIX, 00529 sketch::WZT_t, SparseMatrix, Matrix, sketch::WZT_data_t); 00530 00531 AUTO_APPLY_DISPATCH(sketchc::WZT, 00532 sketchc::SPARSE_MATRIX, sketchc::SPARSE_MATRIX, 00533 sketch::WZT_t, SparseMatrix, SparseMatrix, 00534 sketch::WZT_data_t); 00535 00536 AUTO_APPLY_DISPATCH(sketchc::WZT, 00537 sketchc::DIST_MATRIX, sketchc::MATRIX, 00538 sketch::WZT_t, DistMatrix, Matrix, sketch::WZT_data_t); 00539 00540 AUTO_APPLY_DISPATCH(sketchc::WZT, 00541 sketchc::DIST_MATRIX_VR_STAR, sketchc::MATRIX, 00542 sketch::WZT_t, DistMatrix_VR_STAR, Matrix, sketch::WZT_data_t); 00543 00544 AUTO_APPLY_DISPATCH(sketchc::WZT, 00545 sketchc::DIST_MATRIX_VC_STAR, sketchc::MATRIX, 00546 sketch::WZT_t, DistMatrix_VC_STAR, Matrix, sketch::WZT_data_t); 00547 00548 AUTO_APPLY_DISPATCH(sketchc::WZT, 00549 sketchc::DIST_MATRIX_STAR_VR, sketchc::MATRIX, 00550 sketch::WZT_t, DistMatrix_STAR_VR, Matrix, sketch::WZT_data_t); 00551 00552 AUTO_APPLY_DISPATCH(sketchc::WZT, 00553 sketchc::DIST_MATRIX_STAR_VC, sketchc::MATRIX, 00554 sketch::WZT_t, DistMatrix_STAR_VC, Matrix, sketch::WZT_data_t); 00555 00556 AUTO_APPLY_DISPATCH(sketchc::PPT, 00557 sketchc::MATRIX, sketchc::MATRIX, 00558 sketch::PPT_t, Matrix, Matrix, 00559 sketch::PPT_data_t); 00560 00561 AUTO_APPLY_DISPATCH(sketchc::PPT, 00562 sketchc::SPARSE_MATRIX, sketchc::MATRIX, 00563 sketch::PPT_t, SparseMatrix, Matrix, 00564 sketch::PPT_data_t); 00565 00566 AUTO_APPLY_DISPATCH(sketchc::GaussianRFT, 00567 sketchc::MATRIX, sketchc::MATRIX, 00568 sketch::GaussianRFT_t, Matrix, Matrix, 00569 sketch::GaussianRFT_data_t); 00570 00571 AUTO_APPLY_DISPATCH(sketchc::GaussianRFT, 00572 sketchc::SPARSE_MATRIX, sketchc::MATRIX, 00573 sketch::GaussianRFT_t, SparseMatrix, Matrix, 00574 sketch::GaussianRFT_data_t); 00575 00576 AUTO_APPLY_DISPATCH(sketchc::GaussianRFT, 00577 sketchc::DIST_MATRIX_VR_STAR, sketchc::DIST_MATRIX_VR_STAR, 00578 sketch::GaussianRFT_t, DistMatrix_VR_STAR, DistMatrix_VR_STAR, 00579 sketch::GaussianRFT_data_t); 00580 00581 AUTO_APPLY_DISPATCH(sketchc::GaussianRFT, 00582 sketchc::DIST_MATRIX_VC_STAR, sketchc::DIST_MATRIX_VC_STAR, 00583 sketch::GaussianRFT_t, DistMatrix_VC_STAR, DistMatrix_VC_STAR, 00584 sketch::GaussianRFT_data_t); 00585 00586 AUTO_APPLY_DISPATCH(sketchc::LaplacianRFT, 00587 sketchc::MATRIX, sketchc::MATRIX, 00588 sketch::LaplacianRFT_t, Matrix, Matrix, 00589 sketch::LaplacianRFT_data_t); 00590 00591 AUTO_APPLY_DISPATCH(sketchc::LaplacianRFT, 00592 sketchc::SPARSE_MATRIX, sketchc::MATRIX, 00593 sketch::LaplacianRFT_t, SparseMatrix, Matrix, 00594 sketch::LaplacianRFT_data_t); 00595 00596 AUTO_APPLY_DISPATCH(sketchc::LaplacianRFT, 00597 sketchc::DIST_MATRIX_VR_STAR, sketchc::DIST_MATRIX_VR_STAR, 00598 sketch::LaplacianRFT_t, DistMatrix_VR_STAR, DistMatrix_VR_STAR, 00599 sketch::LaplacianRFT_data_t); 00600 00601 AUTO_APPLY_DISPATCH(sketchc::LaplacianRFT, 00602 sketchc::DIST_MATRIX_VC_STAR, sketchc::DIST_MATRIX_VC_STAR, 00603 sketch::LaplacianRFT_t, DistMatrix_VC_STAR, DistMatrix_VC_STAR, 00604 sketch::LaplacianRFT_data_t); 00605 00606 AUTO_APPLY_DISPATCH(sketchc::ExpSemigroupRLT, 00607 sketchc::MATRIX, sketchc::MATRIX, 00608 sketch::ExpSemigroupRLT_t, Matrix, Matrix, 00609 sketch::ExpSemigroupRLT_data_t); 00610 00611 AUTO_APPLY_DISPATCH(sketchc::ExpSemigroupRLT, 00612 sketchc::SPARSE_MATRIX, sketchc::MATRIX, 00613 sketch::ExpSemigroupRLT_t, SparseMatrix, Matrix, 00614 sketch::ExpSemigroupRLT_data_t); 00615 00616 #if SKYLARK_HAVE_FFTW || SKYLARK_HAVE_SPIRALWHT 00617 00618 AUTO_APPLY_DISPATCH(sketchc::FJLT, 00619 sketchc::DIST_MATRIX_VR_STAR, sketchc::MATRIX, 00620 sketch::FJLT_t, DistMatrix_VR_STAR, Matrix, 00621 sketch::FJLT_data_t); 00622 00623 AUTO_APPLY_DISPATCH(sketchc::FJLT, 00624 sketchc::DIST_MATRIX_VC_STAR, sketchc::MATRIX, 00625 sketch::FJLT_t, DistMatrix_VC_STAR, Matrix, 00626 sketch::FJLT_data_t); 00627 00628 AUTO_APPLY_DISPATCH(sketchc::FastGaussianRFT, 00629 sketchc::MATRIX, sketchc::MATRIX, 00630 sketch::FastGaussianRFT_t, Matrix, Matrix, 00631 sketch::FastGaussianRFT_data_t); 00632 00633 AUTO_APPLY_DISPATCH(sketchc::FastGaussianRFT, 00634 sketchc::SPARSE_MATRIX, sketchc::MATRIX, 00635 sketch::FastGaussianRFT_t, SparseMatrix, Matrix, 00636 sketch::FastGaussianRFT_data_t); 00637 00638 #endif 00639 00640 #ifdef SKYLARK_HAVE_COMBBLAS 00641 00642 // adding a bunch of sp -> sp_sketch -> dense types 00643 //FIXME: only tested types, */SOMETHING should work as well... 00644 AUTO_APPLY_DISPATCH(sketchc::CWT, 00645 sketchc::DIST_SPARSE_MATRIX, sketchc::MATRIX, 00646 sketch::CWT_t, DistSparseMatrix, Matrix, 00647 sketch::CWT_data_t); 00648 00649 AUTO_APPLY_DISPATCH(sketchc::CWT, 00650 sketchc::DIST_SPARSE_MATRIX, sketchc::DIST_MATRIX, 00651 sketch::CWT_t, DistSparseMatrix, DistMatrix, 00652 sketch::CWT_data_t); 00653 00654 AUTO_APPLY_DISPATCH(sketchc::CWT, 00655 sketchc::DIST_SPARSE_MATRIX, sketchc::DIST_MATRIX_VC_STAR, 00656 sketch::CWT_t, DistSparseMatrix, DistMatrix_VC_STAR, 00657 sketch::CWT_data_t); 00658 00659 AUTO_APPLY_DISPATCH(sketchc::CWT, 00660 sketchc::DIST_SPARSE_MATRIX, sketchc::DIST_MATRIX_VR_STAR, 00661 sketch::CWT_t, DistSparseMatrix, DistMatrix_VR_STAR, 00662 sketch::CWT_data_t); 00663 00664 AUTO_APPLY_DISPATCH(sketchc::MMT, 00665 sketchc::DIST_SPARSE_MATRIX, sketchc::MATRIX, 00666 sketch::MMT_t, DistSparseMatrix, Matrix, 00667 sketch::MMT_data_t); 00668 00669 AUTO_APPLY_DISPATCH(sketchc::MMT, 00670 sketchc::DIST_SPARSE_MATRIX, sketchc::DIST_MATRIX, 00671 sketch::MMT_t, DistSparseMatrix, DistMatrix, 00672 sketch::MMT_data_t); 00673 00674 AUTO_APPLY_DISPATCH(sketchc::MMT, 00675 sketchc::DIST_SPARSE_MATRIX, sketchc::DIST_MATRIX_VC_STAR, 00676 sketch::MMT_t, DistSparseMatrix, DistMatrix_VC_STAR, 00677 sketch::MMT_data_t); 00678 00679 AUTO_APPLY_DISPATCH(sketchc::MMT, 00680 sketchc::DIST_SPARSE_MATRIX, sketchc::DIST_MATRIX_VR_STAR, 00681 sketch::MMT_t, DistSparseMatrix, DistMatrix_VR_STAR, 00682 sketch::MMT_data_t); 00683 #endif 00684 #endif 00685 00686 #ifdef SKYLARK_HAVE_COMBBLAS 00687 00688 AUTO_APPLY_DISPATCH(sketchc::CWT, 00689 sketchc::DIST_SPARSE_MATRIX, sketchc::DIST_SPARSE_MATRIX, 00690 sketch::CWT_t, DistSparseMatrix, DistSparseMatrix, 00691 sketch::CWT_data_t); 00692 00693 AUTO_APPLY_DISPATCH(sketchc::CWT, 00694 sketchc::DIST_SPARSE_MATRIX, sketchc::SPARSE_MATRIX, 00695 sketch::CWT_t, DistSparseMatrix, SparseMatrix, 00696 sketch::CWT_data_t); 00697 00698 AUTO_APPLY_DISPATCH(sketchc::MMT, 00699 sketchc::DIST_SPARSE_MATRIX, sketchc::DIST_SPARSE_MATRIX, 00700 sketch::MMT_t, DistSparseMatrix, DistSparseMatrix, 00701 sketch::MMT_data_t); 00702 00703 AUTO_APPLY_DISPATCH(sketchc::MMT, 00704 sketchc::DIST_SPARSE_MATRIX, sketchc::SPARSE_MATRIX, 00705 sketch::MMT_t, DistSparseMatrix, SparseMatrix, 00706 sketch::MMT_data_t); 00707 00708 #endif 00709 00710 return 0; 00711 } 00712 00713 SKYLARK_EXTERN_API int sl_wrap_raw_matrix(double *data, int m, int n, void **A) 00714 { 00715 #if SKYLARK_HAVE_ELEMENTAL 00716 Matrix *tmp = new Matrix(); 00717 tmp->Attach(m, n, data, m); 00718 *A = tmp; 00719 return 0; 00720 #else 00721 return 103; 00722 #endif 00723 00724 } 00725 00726 SKYLARK_EXTERN_API int sl_free_raw_matrix_wrap(void *A_) { 00727 #if SKYLARK_HAVE_ELEMENTAL 00728 delete static_cast<Matrix *>(A_); 00729 return 0; 00730 #else 00731 return 103; 00732 #endif 00733 } 00734 00735 00736 SKYLARK_EXTERN_API int sl_wrap_raw_sp_matrix(int *indptr, int *ind, double *data, 00737 int nnz, int n_rows, int n_cols, void **A) 00738 { 00739 SparseMatrix *tmp = new SparseMatrix(); 00740 tmp->attach(indptr, ind, data, nnz, n_rows, n_cols); 00741 *A = tmp; 00742 return 0; 00743 } 00744 00745 SKYLARK_EXTERN_API int sl_free_raw_sp_matrix_wrap(void *A_) { 00746 delete static_cast<SparseMatrix *>(A_); 00747 return 0; 00748 } 00749 00750 SKYLARK_EXTERN_API int sl_raw_sp_matrix_struct_updated(void *A_, 00751 bool *struct_updated) { 00752 *struct_updated = static_cast<SparseMatrix *>(A_)->struct_updated(); 00753 return 0; 00754 } 00755 00756 SKYLARK_EXTERN_API int sl_raw_sp_matrix_reset_update_flag(void *A_) { 00757 static_cast<SparseMatrix *>(A_)->reset_update_flag(); 00758 return 0; 00759 } 00760 00761 SKYLARK_EXTERN_API int sl_raw_sp_matrix_nnz(void *A_, int *nnz) { 00762 *nnz = static_cast<SparseMatrix *>(A_)->nonzeros(); 00763 return 0; 00764 } 00765 00766 SKYLARK_EXTERN_API int sl_raw_sp_matrix_data(void *A_, int32_t *indptr, 00767 int32_t *indices, double *values) { 00768 static_cast<SparseMatrix *>(A_)->detach(indptr, indices, values); 00769 return 0; 00770 } 00771 00772 } // extern "C"