FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
vector_vector.h
1 #ifndef __VECTOR_VECTOR_H__
2 #define __VECTOR_VECTOR_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 <memory>
24 
25 #include "comm_exception.h"
26 #include "log.h"
27 
28 #include "vec_store.h"
29 #include "vector.h"
30 #include "vv_store.h"
31 
32 namespace fm
33 {
34 
35 class scalar_type;
36 class factor_vector;
37 class local_vv_store;
38 class data_frame;
39 
40 namespace detail
41 {
42 class raw_data_array;
43 }
44 
45 /*
46  * This stores a vector of vectors. It's similar to the row-wise matrix,
47  * but this allows each vector to have different lengths.
48  */
49 class vector_vector: public vector
50 {
51  vector_vector(detail::vv_store::const_ptr store): vector(store) {
52  }
53 public:
54  typedef std::shared_ptr<vector_vector> ptr;
55 
56  static bool is_vector_vector(const vector &vec) {
57  return vec.get_entry_size() == 0;
58  }
59 
60  static ptr cast(vector::ptr vec) {
61  if (!is_vector_vector(*vec)) {
62  BOOST_LOG_TRIVIAL(error) << "This isn't a vector of vectors";
63  return ptr();
64  }
65  return std::static_pointer_cast<vector_vector>(vec);
66  }
67 
68  static ptr create(detail::vv_store::ptr store) {
69  return ptr(new vector_vector(store));
70  }
71 
72  static ptr create(const detail::raw_data_array &data,
73  const std::vector<off_t> &offs, const scalar_type &type);
74 
75  virtual size_t get_entry_size() const {
76  return 0;
77  }
78 
79  size_t get_num_vecs() const {
80  return get_length();
81  }
82 
83  /*
84  * This return the number of vectors in the vector vector.
85  */
86  virtual size_t get_length() const {
87  return static_cast<const detail::vv_store &>(
88  get_data()).get_num_vecs();
89  }
90 
91  virtual size_t get_length(off_t idx) const {
92  return static_cast<const detail::vv_store &>(
93  get_data()).get_length(idx);
94  }
95 
96  virtual size_t get_tot_num_entries() const {
97  return static_cast<const detail::vv_store &>(
98  get_data()).get_num_bytes() / get_type().get_size();
99  }
100 
101  /*
102  * Catenate all vectors into a single vector.
103  */
104  virtual std::shared_ptr<vector> cat() const;
105 
106  virtual vector_vector::ptr groupby(const factor_vector &labels,
107  const gr_apply_operate<local_vv_store> &op) const;
108  virtual vector_vector::ptr apply(const arr_apply_operate &op) const;
109 
110  virtual vector::ptr sort() const {
111  return vector::ptr();
112  }
113  virtual std::shared_ptr<data_frame> sort_with_index() const {
114  return std::shared_ptr<data_frame>();
115  }
116  virtual std::shared_ptr<data_frame> groupby(
117  const gr_apply_operate<local_vec_store> &op,
118  bool with_val) const {
119  return std::shared_ptr<data_frame>();
120  }
121  virtual scalar_variable::ptr aggregate(const bulk_operate &op) const {
122  return scalar_variable::ptr();
123  }
124  virtual scalar_variable::ptr dot_prod(const vector &vec) const {
125  return scalar_variable::ptr();
126  }
127  virtual std::shared_ptr<dense_matrix> conv2mat(size_t nrow, size_t ncol,
128  bool byrow) const {
129  return std::shared_ptr<dense_matrix>();
130  }
131 };
132 
133 }
134 
135 #endif