FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
fm_utils.h
1 /*
2  * Copyright 2014 Open Connectome Project (http://openconnecto.me)
3  * Written by Da Zheng (zhengda1936@gmail.com)
4  *
5  * This file is part of FlashMatrix.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef __FM_UTILS_H__
21 #define __FM_UTILS_H__
22 
23 #include <Rcpp.h>
24 #include <memory>
25 
26 namespace fm
27 {
28  class vector;
29  class factor_vector;
30  class dense_matrix;
31  class sparse_matrix;
32 
33 namespace detail
34 {
35  class vec_store;
36 }
37 }
38 
39 template<class ObjectType>
40 class object_ref
41 {
42  typename ObjectType::ptr o;
43 public:
44  object_ref(typename ObjectType::ptr o) {
45  this->o = o;
46  }
47 
48  typename ObjectType::ptr get_object() {
49  return o;
50  }
51 };
52 
53 template<class MatrixType>
54 typename MatrixType::ptr get_matrix(const Rcpp::S4 &matrix)
55 {
56  object_ref<MatrixType> *ref
57  = (object_ref<MatrixType> *) R_ExternalPtrAddr(matrix.slot("pointer"));
58  return ref->get_object();
59 }
60 
61 std::shared_ptr<fm::vector> get_vector(const Rcpp::S4 &vec);
62 std::shared_ptr<fm::factor_vector> get_factor_vector(const Rcpp::S4 &vec);
63 
64 SEXP create_FMR_vector(std::shared_ptr<const fm::detail::vec_store> vec, const std::string &name);
65 SEXP create_FMR_vector(std::shared_ptr<fm::dense_matrix> m, const std::string &name);
66 SEXP create_FMR_factor_vector(std::shared_ptr<fm::dense_matrix> m, int num_levels,
67  const std::string &name);
68 SEXP create_FMR_matrix(std::shared_ptr<fm::dense_matrix> m, const std::string &name);
69 SEXP create_FMR_matrix(std::shared_ptr<fm::sparse_matrix> m, const std::string &name);
70 SEXP create_FMR_data_frame(std::shared_ptr<fm::data_frame> df, const std::string &name);
71 
72 #endif