-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor impls and spike for tensor builder
- Loading branch information
Riley Sutton
authored and
Riley Sutton
committed
Mar 21, 2024
1 parent
5fb329d
commit abf594b
Showing
19 changed files
with
286 additions
and
357 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
use std::ops::RangeBounds; | ||
|
||
use crate::engine::unit::UnitCompatible; | ||
use crate::{engine::unit::UnitCompatible, helper::Shape}; | ||
|
||
use super::EngineTensor; | ||
|
||
trait EngineTensorBuilder { | ||
pub trait EngineTensorBuilder { | ||
type Unit: UnitCompatible; | ||
type Tensor: EngineTensor; | ||
|
||
fn splice<R: RangeBounds<usize>, I: IntoIterator<Item = Self::Unit>>(range: R, replace_with: I); | ||
fn new(shape: Shape) -> Self; | ||
|
||
fn construct() -> Box<dyn EngineTensor<Unit = Self::Unit>>; | ||
} | ||
fn splice<R: RangeBounds<usize>, I: IntoIterator<Item = Self::Unit>>(&mut self, range: R, replace_with: I); | ||
|
||
struct ArrayBuilder; | ||
fn construct(self) -> Self::Tensor; | ||
} |
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 |
---|---|---|
@@ -1,51 +1,14 @@ | ||
use std::sync::Arc; | ||
use crate::helper::{Shape, Stride}; | ||
use super::{allowed_unit::{AllowedArray, AllowedQuant}, generic::EngineTensorGeneric, Array, EngineTensor, Quant}; | ||
use crate::helper::Shape; | ||
use super::EngineTensor; | ||
|
||
pub trait EngineTensorFactory: EngineTensor + EngineTensorGeneric | ||
where Self: Sized | ||
pub trait EngineTensorFactory: EngineTensor | ||
where Self: Sized + 'static | ||
{ | ||
fn from_iter(iter: impl Iterator<Item = Self::Unit>, shape: Shape) -> Self; | ||
fn from_slice(data: &[Self::Unit], shape: Shape) -> Self; | ||
//fn builder() -> impl EngineTensorBuilder<Unit = Self::Unit>; | ||
} | ||
|
||
impl<T: AllowedArray> EngineTensorFactory for Array<T> { | ||
fn from_iter(iter: impl Iterator<Item = T>, shape: Shape) -> Self { | ||
Array { | ||
stride: Stride::default_from_shape(&shape), | ||
shape, | ||
data: iter.collect(), | ||
offset: 0, | ||
} | ||
} | ||
|
||
fn from_slice(data: &[T], shape: Shape) -> Self { | ||
Array { | ||
stride: Stride::default_from_shape(&shape), | ||
shape, | ||
data: Arc::from(data), | ||
offset: 0, | ||
} | ||
} | ||
} | ||
|
||
impl<T: AllowedQuant> EngineTensorFactory for Quant<T> { | ||
fn from_iter(iter: impl Iterator<Item = T>, shape: Shape) -> Self { | ||
Quant { | ||
stride: Stride::default_from_shape(&shape), | ||
shape, | ||
data: iter.collect(), | ||
offset: 0, | ||
} | ||
} | ||
|
||
fn from_slice(data: &[T], shape: Shape) -> Self { | ||
Quant { | ||
stride: Stride::default_from_shape(&shape), | ||
shape, | ||
data: Arc::from(data), | ||
offset: 0, | ||
} | ||
fn generic(self) -> Box<dyn EngineTensor<Unit = Self::Unit>> { | ||
Box::from(self) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.