-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tensor): reform 直接拷贝只需要二者非 1 维度 stride 相同
Signed-off-by: YdrMaster <[email protected]>
- Loading branch information
Showing
4 changed files
with
136 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::Tensor; | ||
use std::ops::{Deref, DerefMut}; | ||
|
||
pub trait PhysicalCell { | ||
type Raw: ?Sized; | ||
type Access<'a>: Deref<Target = Self::Raw> | ||
where | ||
Self: 'a; | ||
type AccessMut<'a>: DerefMut<Target = Self::Raw> | ||
where | ||
Self: 'a; | ||
|
||
unsafe fn get_unchecked(&self) -> &Self::Raw; | ||
unsafe fn get_unchecked_mut(&mut self) -> &mut Self::Raw; | ||
fn access(&self) -> Self::Access<'_>; | ||
fn access_mut(&mut self) -> Self::AccessMut<'_>; | ||
} | ||
|
||
impl<Physical: PhysicalCell> Tensor<Physical> { | ||
#[inline] | ||
pub unsafe fn access_unchecked(&self) -> Tensor<&Physical::Raw> { | ||
Tensor { | ||
data_type: self.data_type, | ||
shape: self.shape.clone(), | ||
pattern: self.pattern.clone(), | ||
physical: self.physical.get_unchecked(), | ||
} | ||
} | ||
|
||
#[inline] | ||
pub unsafe fn access_unchecked_mut(&mut self) -> Tensor<&mut Physical::Raw> { | ||
Tensor { | ||
data_type: self.data_type, | ||
shape: self.shape.clone(), | ||
pattern: self.pattern.clone(), | ||
physical: self.physical.get_unchecked_mut(), | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn access(&self) -> Tensor<Physical::Access<'_>> { | ||
Tensor { | ||
data_type: self.data_type, | ||
shape: self.shape.clone(), | ||
pattern: self.pattern.clone(), | ||
physical: self.physical.access(), | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn access_mut(&mut self) -> Tensor<Physical::AccessMut<'_>> { | ||
Tensor { | ||
data_type: self.data_type, | ||
shape: self.shape.clone(), | ||
pattern: self.pattern.clone(), | ||
physical: self.physical.access_mut(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters