I need to create a matrix with alglib because I need to use a function contained in the library, but I need my matrix to contain element of type double (or something similar to double implemented in alglib) how can I do it?
if it is not possible does someone knows a library that implments the SVD function even for matrix of type double?
I'm using c++.
thank you
For the current release of alglib as of writing, a 2D matrix of double precision values can be created as follows:
ap::real_2d_array matrix;
double data[4] = {0.1, 0.2,
0.3, 0.4};
matrix.setcontent(1, 2, 1, 2, data);
The matrix produced by the code would appear as:
0.1 0.2
0.3 0.4
The setcontent function is what determines the dimensions and content of the matrix. It has the following definition:
setcontent(int row_start_index, int row_end_index, int col_start_index, int col_end_index, data)
Alternatively, if you wanted to set the dimensions of the matrix without filling it with data, you could use the following:
setbounds(int row_start_index, int row_end_index, int col_start_index, int col_end_index)
In the manual it's written:
ALGLIB (ap.h header) defines several "basic" datatypes (types which are used by all packages) and many package-specific datatypes. "Basic" datatypes are:
alglib::ae_int_t - signed integer type used by library
alglib::complex - double precision complex datatype, safer replacement for std::complex
alglib::ap_error - exception which is thrown by library
boolean_1d_array - 1-dimensional boolean array
integer_1d_array - 1-dimensional integer array
real_1d_array - 1-dimensional real (double precision) array
complex_1d_array - 1-dimensional complex array
boolean_2d_array - 2-dimensional boolean array
integer_2d_array - 2-dimensional integer array
real_2d_array - 2-dimensional real (double precision) array
complex_2d_array - 2-dimensional complex array
The rest should be pretty straightforward.
This should create a 2x2 matrix:
alglib::real_2d_array r2("[[1.1,2.2],[3.3,4.4]]");
result:
1.1 2.2
3.3 4.4
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.