mirror of
https://github.com/huggingface/candle.git
synced 2025-06-16 10:38:54 +00:00
Add some very basic backprop.
This commit is contained in:
@ -56,6 +56,25 @@ impl<S: crate::WithDType, const N: usize, const M: usize> NdArray for &[[S; N];
|
||||
}
|
||||
|
||||
impl Device {
|
||||
pub(crate) fn ones(&self, shape: &Shape, dtype: DType) -> Storage {
|
||||
match self {
|
||||
Device::Cpu => {
|
||||
let elem_count = shape.elem_count();
|
||||
let storage = match dtype {
|
||||
DType::F32 => {
|
||||
let data = vec![1f32; elem_count];
|
||||
CpuStorage::F32(data)
|
||||
}
|
||||
DType::F64 => {
|
||||
let data = vec![1f64; elem_count];
|
||||
CpuStorage::F64(data)
|
||||
}
|
||||
};
|
||||
Storage::Cpu(storage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn zeros(&self, shape: &Shape, dtype: DType) -> Storage {
|
||||
match self {
|
||||
Device::Cpu => {
|
||||
|
Reference in New Issue
Block a user