1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use tensor::Tensor;
use num::traits::cast;
use Numeric;
impl<T: Numeric> Tensor<T> {
pub fn convert<D: Numeric>(&self) -> Tensor<D> {
let mut t = Tensor::zeros(&self.shape);
{
let n = t.size();
let mut data = t.slice_mut();
for i in 0..n {
data[i] = cast(data[i]).unwrap();
}
}
t
}
pub fn to_f32(&self) -> Tensor<f32> {
self.convert::<f32>()
}
pub fn to_f64(&self) -> Tensor<f64> {
self.convert::<f64>()
}
}