FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
virtual_matrix_store.h
1 #ifndef __VIRTUAL_MATRIX_STORE_H__
2 #define __VIRTUAL_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 "comm_exception.h"
24 
25 #include "mem_matrix_store.h"
26 
27 namespace fm
28 {
29 
30 namespace detail
31 {
32 
33 /*
34  * This class is the base class for the classes whose data isn't stored
35  * physically. The data of these classes materializes data when being
36  * requested. All these classes are read-only.
37  */
38 class virtual_matrix_store: public matrix_store
39 {
40 public:
41  typedef std::shared_ptr<const virtual_matrix_store> const_ptr;
42 
43  static const_ptr cast(matrix_store::const_ptr mat) {
44  assert(mat->is_virtual());
45  return std::static_pointer_cast<const virtual_matrix_store>(mat);
46  }
47 
48  virtual_matrix_store(size_t nrow, size_t ncol, bool in_mem,
49  const scalar_type &type): matrix_store(nrow, ncol, in_mem, type) {
50  }
51 
52  virtual bool is_virtual() const {
53  return true;
54  }
55 
56  /*
57  * When we materialize the matrix, we can specify where the materialized
58  * matrix is stored.
59  */
60  virtual matrix_store::const_ptr materialize(bool in_mem,
61  int num_nodes) const = 0;
62 
63  virtual void reset_data() {
64  assert(0);
65  }
66 
67  virtual void set_data(const set_operate &op) {
68  assert(0);
69  }
70 
71  virtual std::shared_ptr<local_matrix_store> get_portion(size_t id) {
72  assert(0);
73  return std::shared_ptr<local_matrix_store>();
74  }
75  virtual std::shared_ptr<local_matrix_store> get_portion(
76  size_t start_row, size_t start_col, size_t num_rows,
77  size_t num_cols) {
78  assert(0);
79  return std::shared_ptr<local_matrix_store>();
80  }
81  virtual async_res_t get_portion_async(
82  size_t start_row, size_t start_col, size_t num_rows,
83  size_t num_cols, std::shared_ptr<portion_compute> compute) {
84  assert(0);
85  return async_res_t();
86  }
87  virtual void write_portion_async(
88  std::shared_ptr<const local_matrix_store> portion,
89  off_t start_row, off_t start_col) {
90  assert(0);
91  }
92 
93  virtual bool write2file(const std::string &file_name) const {
94  assert(0);
95  return false;
96  }
97 };
98 
99 }
100 
101 }
102 
103 #endif