FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
eigensolver.h
1 #ifndef __EIGENSOLVER_H__
2 #define __EIGENSOLVER_H__
3 
4 /*
5  * Copyright 2015 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 #include <vector>
23 #include <string>
24 #include <memory>
25 
26 #include "dense_matrix.h"
27 #include "matrix_store.h"
28 
29 namespace fm
30 {
31 
32 namespace eigen
33 {
34 
35 class spm_function
36 {
37 public:
38  typedef std::shared_ptr<const spm_function> const_ptr;
39 
40  /*
41  * We pass a reference of the shared pointer to the run method.
42  * So the user-defined run method can deallocate the input dense matrix.
43  */
44  virtual fm::dense_matrix::ptr run(fm::dense_matrix::ptr &x) const = 0;
45  virtual size_t get_num_cols() const = 0;
46  virtual size_t get_num_rows() const = 0;
47 };
48 
49 struct eigen_res
50 {
51  std::vector<double> vals;
52  fm::dense_matrix::ptr vecs;
53 };
54 
55 struct eigen_options
56 {
57  double tol;
58  int num_blocks;
59  int max_restarts;
60  int max_iters;
61  int block_size;
62  int nev;
63  std::string solver;
64  std::string which;
65  bool in_mem;
66 
67  eigen_options();
68 
69  bool init(int nev, std::string solver = "KrylovSchur");
70 };
71 
72 /*
73  * `func' will be destroyed by this function.
74  */
75 eigen_res compute_eigen(spm_function *func, bool sym,
76  struct eigen_options &opts);
77 
78 }
79 
80 }
81 
82 #endif