FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
collected_col_matrix_store.h
1 #ifndef __COLLECTED_COL_MATRIX_STORE_H__
2 #define __COLLECTED_COL_MATRIX_STORE_H__
3 
4 /*
5  * Copyright 2014 Open Connectome Project (http://openconnecto.me)
6  * Written by Da Zheng (zhengda1936@gmail.com)
7  *
8  * This file is part of FlashMatrix.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include "virtual_matrix_store.h"
24 #include "local_matrix_store.h"
25 #include "EM_object.h"
26 
27 namespace fm
28 {
29 
30 namespace eigen
31 {
32 
33 class collected_matrix_store: public detail::virtual_matrix_store, public detail::EM_object
34 {
35  // Indicates a row/column in the original matrices.
36  struct rc_idx {
37  size_t mat_idx;
38  size_t inner_idx;
39 
40  rc_idx(size_t mat_idx, size_t inner_idx) {
41  this->mat_idx = mat_idx;
42  this->inner_idx = inner_idx;
43  }
44  };
45 
46  int num_nodes;
47  std::vector<rc_idx> rc_idxs;
48  std::vector<detail::matrix_store::const_ptr> orig_mats;
49  detail::matrix_store::const_ptr merged_mat;
50 
51  collected_matrix_store(
52  const std::vector<detail::matrix_store::const_ptr> &mats,
53  size_t num_cols);
54  collected_matrix_store(size_t num_rows, size_t num_cols, bool in_mem,
55  const scalar_type &type, size_t num_nodes);
56 public:
57  typedef std::shared_ptr<collected_matrix_store> ptr;
58 
59  static ptr create(const std::vector<detail::matrix_store::const_ptr> &mats,
60  size_t num_cols);
61 
62  virtual std::string get_name() const {
63  assert(merged_mat);
64  return merged_mat->get_name();
65  }
66 
67  virtual detail::matrix_store::const_ptr get_cols(
68  const std::vector<off_t> &idxs) const;
69  virtual detail::matrix_store::const_ptr transpose() const;
70 
71  virtual detail::async_cres_t get_portion_async(
72  size_t start_row, size_t start_col, size_t num_rows, size_t num_cols,
73  detail::portion_compute::ptr compute) const {
74  assert(merged_mat);
75  return merged_mat->get_portion_async(start_row, start_col,
76  num_rows, num_cols, compute);
77  }
78  virtual detail::local_matrix_store::const_ptr get_portion(size_t start_row,
79  size_t start_col, size_t num_rows, size_t num_cols) const {
80  assert(merged_mat);
81  return merged_mat->get_portion(start_row, start_col, num_rows, num_cols);
82  }
83  virtual std::pair<size_t, size_t> get_portion_size() const {
84  assert(merged_mat);
85  return merged_mat->get_portion_size();
86  }
87 
88  virtual int get_num_nodes() const {
89  return num_nodes;
90  }
91 
92  virtual std::unordered_map<size_t, size_t> get_underlying_mats() const {
93  return merged_mat->get_underlying_mats();
94  }
95 
96  matrix_layout_t store_layout() const {
97  assert(merged_mat);
98  return merged_mat->store_layout();
99  }
100 
101  virtual matrix_store::const_ptr materialize(bool in_mem, int num_nodes) const {
102  return static_cast<const detail::virtual_matrix_store *>(
103  merged_mat.get())->materialize(in_mem, num_nodes);
104  }
105 
106  virtual std::vector<safs::io_interface::ptr> create_ios() const {
107  assert(merged_mat);
108  const detail::EM_object *obj = dynamic_cast<const detail::EM_object *>(
109  merged_mat.get());
110  assert(obj);
111  return obj->create_ios();
112  }
113 
114  virtual void set_cache_portion(bool cache_portion) {
115  const_cast<detail::matrix_store &>(*merged_mat).set_cache_portion(
116  cache_portion);
117  }
118 };
119 
120 }
121 
122 }
123 
124 #endif