mirror of
https://github.com/huggingface/candle.git
synced 2025-06-18 03:28:50 +00:00
Add an easy way to create tensor objects.
This commit is contained in:
14
src/dtype.rs
14
src/dtype.rs
@ -1,3 +1,5 @@
|
||||
use crate::CpuStorage;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum DType {
|
||||
F32,
|
||||
@ -13,14 +15,24 @@ impl DType {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait WithDType {
|
||||
pub trait WithDType: Sized + Copy {
|
||||
const DTYPE: DType;
|
||||
|
||||
fn to_cpu_storage(data: &[Self]) -> CpuStorage;
|
||||
}
|
||||
|
||||
impl WithDType for f32 {
|
||||
const DTYPE: DType = DType::F32;
|
||||
|
||||
fn to_cpu_storage(data: &[Self]) -> CpuStorage {
|
||||
CpuStorage::F32(data.to_vec())
|
||||
}
|
||||
}
|
||||
|
||||
impl WithDType for f64 {
|
||||
const DTYPE: DType = DType::F64;
|
||||
|
||||
fn to_cpu_storage(data: &[Self]) -> CpuStorage {
|
||||
CpuStorage::F64(data.to_vec())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user