ComplexEigenSolver for complex matrix with boost multiprecision - c++

I can't compute eigen values and eigen vectors for new type of matrix initialized by means of boost multiprecision.
#include<iostream>
#include<Eigen/Dense>
#include<Eigen/Eigenvalues>
#include<boost/multiprecision/eigen.hpp>
#include<boost/multiprecision/cpp_complex.hpp>
#include<complex>
using namespace std;
using namespace Eigen;
using namespace boost::multiprecision;
int main() {
Matrix<cpp_complex_single, Dynamic, Dynamic> A = Matrix<cpp_complex_single, Dynamic, Dynamic>::Identity(3,3);
ComplexEigenSolver<Matrix<cpp_complex_single, Dynamic, Dynamic>> ces(A);
return 0;
}
Error log is quite long, so I decided to put it on pastebin, here is the link https://pastebin.com/XfvLT9y4. Summarizing: is there any way to compute eigen problem for new type of complex matrix initialized with boost multiprecision ?

Related

using std Namespace in R instead of RCPP

I'm learning C++ with plans to implement it almost entirely in conjunction with R. I get a little tired of appending the namespace "std" to tons of code though. Is there a way to use namespace std for most of the code and switch the namespace to Rcpp just for the compile and sourcing?
Below is a C++ "Hello World" function with namespace Rcpp. This is a trivial example, but lays out the problem. "string" is not a class in Rcpp, so I have to append std:: to it. Again, I know this is a trivial example, but I just want to know if it is possible.
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
std::string hello(std::string x) {
return x;
}
/*** R
hello("Hello World")
*/
Output works as expected, but I'd love if I could make the code look something like this:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
using namespace std;
string hello(string x) {
return x;
}
using namespace Rcpp;
/*** R
hello("Hello World")
*/
This way, as the bulk of the code expands, I don't have to append std to everything.

How to save Eigen::DiagonalMatrix in MarketIO format in Eigen?

Using Eigen 3.2.1, I am trying to save an Eigen::DiagonalMatrix in MarketIO format as below:
#include <Eigen/Sparse>
#include <Unsupported/Eigen/SparseExtra>
using namespace Eigen;
...
size_t n = XX;
DiagonalMatrix<num_t, Dynamic> W(n);
...
saveMarket(W, "W.txt"); // error propagates from here
However, I am getting the following error:
MarketIO.h|236|error: 'const class Eigen::DiagonalMatrix<double, -1>' has no
member named 'nonZeros'
What is the problem here? Is this implemented at all for Diagonal Matrices?
Thanks in advance for any help.
Okay! The only solution for now with minimal effort is to use the following:
saveMarketVector(W.diagonal(), "W.txt");

Error: 'array': ambiguous symbol

I'm tring to use boost array
but I got this error:
error: 'array': ambiguous symbol
here is my code:
#include <iostream>
#include <boost/array.hpp>
#include <boost/regex.hpp>
using namespace boost;
using namespace std;
int main(int argc, char* argv[])
{
array<int, 10> a{3};
cout << "a[0]= " << a[0];
return 0;
}
This error arise when I include the boost library
any idea ?
boost::array and std::array are not ambiguous because they are scoped by different namespaces.
When you do:
using namespace boost;
using namespace std;
You tell the compiler to look symbols up in both these namespaces. But the compiler now doesn't know which array you're talking about when you just type array. It could be boost::array or it could be std::array thus it is ambiguous.
You could fix this by either removing the using namespace std; or by specifying that you're using the Boost version by using boost::array instead of just array.
Incidentally I understand trying to learn Boost functionality, but you shouldn't bother learning boost::array, right in the Introduction to boost::array it tells you:
std::array is (as of C++11) part of the C++ standard. The differences between boost::array and std::array are minimal. If you are using C++11, you should consider using std::array instead of boost::array.
add core:: before the array
so core::array

Calculating Covarince matrix using Eigen library, C++ Linux

I'm trying to do some operations on matrices using a matrix library named, "Eigen Library". I've a 50 X 100000 matrix in size and I want to find its covariance matrix. So, can I get a built_in function to to find covariance matrix?
C++ sample code:
#include "Eigen/Core"
#include "Eigen/Dense"
using namespace Eigen;
using namespace std;
int main()
{
MatrixXf my_matrx = MatrixXf::Random(50,100000);
//Now, i want to find a function to find the covariance matrix of "my_matrx", like below:
MatrixXf my_cov_matrix = any_function(my_matrx);
}

eigen library selfadjointView problem

I am persistently getting error messages whenever I try to use the selfadjointView property of any matrix or sparse matrix using the eigen library. Below is a simple code to check that. In my program I do try with self-adjoint matrix:
#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
#include <Eigen/Sparse>
#include <Eigen/Dense>
#include <Eigen/Core>
#include <iostream>
using namespace Eigen;
int main ()
{
SparseMatrix<float> mat(3,3);
Matrix<float, 3, 1> vec;
std::cout<<mat.selfadjointView<>()*vec;
}
The error message I get is:
error: no matching function for call to ‚'Eigen::SparseMatrix::selfadjointView()‚
You have to specify the template argument, so it should read mat.selfadjointView<Upper>() or mat.selfadjointView<Lower>() . The first one means that it should use the entries in the upper triangular part of mat and fill the lower triangular part to make the matrix self-adjoint. The second one is the other way around.