what is the best way to convert a gsl_matrix_float to gsl_matrix? - gsl

What is the best way to convert a gsl_matrix_float to gsl_matrix (double data)? Seems not finding some existing GSL API. Maybe some kind of pointer casting?

Related

How do I convert a matrix in Swift to cv::Mat?

Bigger context: I'm trying to use CoreMotion's CMRotationMatrix in C++ code. I'm using a wrapper to bring Swift code into C++.
However, I don't know how to bring the CMRotationMatrix into my C++ opencv code. With this question (How to retrieve value from C++ matrix in Swift?) I get the sense that I'm supposed to convert the CMRotationMatrix into uint8_t array of arrays but I'm not sure if this is the right path and even if it is, I don't know how to convert uint8_t to cv::Mat.
Any help would be appreciated. Thanks!

convert a dolfin::matrix in a eigen::matrix

I'm coding in c++ and i'm using FEniCSĀ  fenics/2016.1.0. A part of my code is
Matrix A;
Vector f;
std::vector<std::shared_ptr<const DirichletBC>> dirichlet_matrici({dirichlet});
assemble_system(A,f,a,L,dirichlet_matrici);
solve(A, *(u.vector()), f);
I want so solve the system with Eigen, so I need to convert the dolfin::Matrix A and the dolfin::Vector f in Eigen objects. Is it possible?
Thank you for your help
I am not sure if it is possible to do a direct conversion. However, it is possible to create a new Eigen matrix and then feed each individual value from the first matrix into the second.

Why Eigen's sample codes tend to use <float> class?

I'm trying to use Eigen in C++ for matrix manipulation.
It looks like I can choose float or double type for real numbers,
such as Eigen::Matrix4f or Eigen::Matrix4d.
In normal C++ code, I guess double is more popular nowadays than float.
However, in Eigen's documentation, float seems to be more frequently used than double.
Is there any special reason???
I know this is very immature question but I need help......
Thank you in advance.
float is usually faster. Performance makes a lot of sense for math.

CString to Float conversion

One common question ,may be I am wrong at this point but last two hours on google not give me any answer,
Question is how to convert CString to float without using std: library in c++.
I tried with wcstod() function but, This function has very different behaviour.
Please find following code,
CString Tempconvert = "32.001";
double TempConvertedValue = wcstod(Tempconvert,NULL);
So, Finally TempConvertedValue should have value 32.001. But i am getting TempConvertedValue = 32.000999999999998
Please provide me any help which convert
String "32.001" to float 32.001 only. Without using std: library.
What you see is an example of floating point internal representation. You can have a look here to see how double are stored in memory. See also this question to know why debugger shows you this value.
With this storing format, it is not possible to represent a decimal number exactly. That is why money calculations usually use special decimal types that are either custom or part of the programming language.

Convert half to float in OpenCL

I apologize if this is trivial, but I've been unable to find an answer by google.
As per the OpenCL standard (since 1.0), the half type is supported for storage reasons.
It seems to me however, that without the cl_khr_fp16 extension, it's impossible to use this for anything?
What I would like to do is to save my values as half, but perform all calculations in float.
I tried using convert_half(), but that's not supported without the cl_khr_fp16.
I tried just writing (float) before the half for auto c-style conversion, didn't work eighter.
So my question is, how do I utilize half for storage?
I need to be able to both read and write half's.
Use vload_halfN and store_halfN. The halfN values stored will be converted to/from floatN.
As far as I know the type half is only supported on the GPU, but you can convert it to and back from a float fairly simply, as long as you know a bit about bitwise manipulation.
Have a look at the following link for a good explanation on how to do so.
ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf
Since it wasn't mentioned in any of the other answers I thought I'd add: You can also use half float in OpenCL images and the read_imagef and write_imagef functions will do the conversion to/from float for you (cl_khr_fp16 extension not required). That extension is only for having variables in (and doing math in) half.