Question

How can I typecast a mat to fmat. One of my function is returning mat. However in the interest of memory, I want to convert it to fmat. How can I type cast it?

Was it helpful?

Solution

You can convert between matrix types using conv_to:

mat A = my_function();
fmat B = conv_to<fmat>::from(A);
fmat C = conv_to<fmat>::from(my_function());

Alternatively, you could change your function into a template; for example:

template <typename T>
Mat<T> other_function() {
  return Mat<T>(4,4);
}

...

fmat D = other_function<float>();
mat F = other_function<double>();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top