romeric / Fastor

A lightweight high performance tensor algebra framework for modern C++
MIT License
752 stars 70 forks source link

Micro-feature: scalar-type tensor to scalar type #138

Closed Bbllaaddee closed 3 years ago

Bbllaaddee commented 3 years ago

Hello!

I wonder if there's any way of transforming a Tensor<double> to double, for example. I found the following way:

Tensor<double> a = 5;
double b = *a.data();

, but it seems a little verbose.

Probably implement

template<typename T>
T Tensor<T>::operator T() {} // pseudo-syntax

of some sort for conversion?

Cheers!

romeric commented 3 years ago

This is already implemented as

Tensor<double> a = 3;
double b = a.toscalar();