9#ifndef __VECTOR_SOLVER_H__
10#define __VECTOR_SOLVER_H__
11#define EIGEN_MPL2_ONLY
15#include "llvm/ADT/SmallVector.h"
21typedef std::vector<std::vector<double>> matrix;
23MatrixXd calculate(MatrixXd A, MatrixXd B) {
24 if (A.determinant() != 0) {
25 return A.fullPivHouseholderQr().solve(B);
28 llvm_unreachable(
"inconsistent/infinitely many solutions");
32MatrixXd formMatrix(std::vector<std::vector<double>> a,
int r,
int l) {
34 for (
int i = 0; i < r; i++)
35 M.row(i) = VectorXd::Map(&a[i][0], a[i].size());
40matrix solve(matrix A, matrix B) {
44 mA = formMatrix(A, r, c);
49 mB = formMatrix(B, r, c);
53 x = calculate(mA, mB);
54 std::vector<std::vector<double>> raw_data;
56 for (
unsigned i = 0; i < x.rows(); i++) {
57 std::vector<double> tmp;
59 VectorXd::Map(&tmp[0], x.cols()) = x.row(i);
60 raw_data.push_back(tmp);