-
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.
- Loading branch information
0 parents
commit 01c6366
Showing
13 changed files
with
225 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,2 @@ | ||
/target | ||
/old_src |
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,3 @@ | ||
{ | ||
"rust-analyzer.showUnlinkedFileNotification": false | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,8 @@ | ||
[package] | ||
name = "therml" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
ord_subset = "3.1.1" | ||
wide = "0.7.8" |
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,8 @@ | ||
# Ideas | ||
|
||
## Context | ||
|
||
- Context creates tensors and handles data storage | ||
- Internally will create graphs for operations | ||
- Will handle gradient calc | ||
|
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,5 @@ | ||
mod tensor; | ||
|
||
pub trait Engine { | ||
type Data: | ||
} |
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,45 @@ | ||
use std::sync::Arc; | ||
use crate::helper::{Shape, Stride}; | ||
use super::EngineTensor; | ||
|
||
struct ArrayEngineTensor<T: Sized> { | ||
data: Arc<[T]>, | ||
shape: Shape, | ||
stride: Stride, | ||
} | ||
|
||
|
||
|
||
impl<T: Sized> EngineTensor<T> for ArrayEngineTensor<T> { | ||
type EngineTensorIterator = ArrayEngineTensorIterator<T>; | ||
|
||
fn shape(&self) -> Shape { | ||
todo!() | ||
} | ||
|
||
fn stride(&self) -> Stride { | ||
todo!() | ||
} | ||
|
||
fn view(&self, shape: Shape) -> Result<Self, ()> { | ||
todo!() | ||
} | ||
|
||
fn iter(&self, comp_range: &[std::ops::Range<usize>]) -> Self::EngineTensorIterator { | ||
todo!() | ||
} | ||
} | ||
|
||
struct ArrayEngineTensorIterator<T: Sized> { | ||
base: ArrayEngineTensor<T>, | ||
pos: Vec<usize>, | ||
end: Vec<usize>, | ||
} | ||
|
||
impl<T: Sized> Iterator for ArrayEngineTensorIterator<T> { | ||
type Item = T; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
|
||
} | ||
} |
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,27 @@ | ||
pub mod array; | ||
|
||
use std::ops::Range; | ||
|
||
use crate::helper::{Shape, Stride}; | ||
|
||
// No mutation should be done through this trait | ||
// It exists purely as a way to get data for the engine | ||
trait EngineTensor<T: Sized> | ||
where Self: Sized | ||
{ | ||
type EngineTensorIterator: Iterator<Item = T>; | ||
|
||
fn shape(&self) -> Shape; | ||
fn stride(&self) -> Stride; | ||
|
||
fn is_contiguous(&self) -> bool { | ||
Stride::from(self.shape()) == self.stride() | ||
} | ||
|
||
// Create a view into the same memory | ||
fn view(&self, shape: Shape) -> Result<Self, ()>; | ||
|
||
// Iterator from element to element in order | ||
fn iter(&self, comp_range: &[Range<usize>]) -> Self::EngineTensorIterator; | ||
//fn (comp_range: &[Range<usize>]) -> Self::DataSlice; | ||
} |
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,5 @@ | ||
mod shape; | ||
mod stride; | ||
|
||
pub use shape::*; | ||
pub use stride::*; |
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,7 @@ | ||
#[derive(Clone, PartialEq, Eq, Debug)] | ||
struct Position(Box<[usize]>); | ||
|
||
impl Position { | ||
|
||
} | ||
|
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,18 @@ | ||
#[derive(Clone, PartialEq, Eq, Debug)] | ||
pub struct Shape(Box<[usize]>); | ||
|
||
impl Shape { | ||
pub fn as_boxed_slice(&self) -> &Box<[usize]> { | ||
&self.0 | ||
} | ||
|
||
pub fn total_elements(&self) -> usize { | ||
self.0.iter().product() | ||
} | ||
} | ||
|
||
impl From<&[usize]> for Shape { | ||
fn from(value: &[usize]) -> Self { | ||
Self(Box::from(value)) | ||
} | ||
} |
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,49 @@ | ||
use crate::helper::Shape; | ||
|
||
#[derive(Clone, PartialEq, Eq, Debug)] | ||
pub struct Stride(Box<[usize]>); | ||
|
||
impl Stride { | ||
pub fn as_boxed_slice(&self) -> &Box<[usize]> { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl From<&[usize]> for Stride { | ||
fn from(value: &[usize]) -> Self { | ||
Self(Box::from(value)) | ||
} | ||
} | ||
|
||
impl From<Shape> for Stride { | ||
fn from(value: Shape) -> Self { | ||
let mut stride: Vec<usize> = Vec::with_capacity(value.as_boxed_slice().len()); | ||
|
||
let mut next = 1usize; | ||
for dim in value.as_boxed_slice().iter().rev() { | ||
stride.push(next); | ||
next = dim * next; | ||
} | ||
|
||
stride.reverse(); | ||
|
||
Stride(stride.into_boxed_slice()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn from_shape_examples() { | ||
let examples = [ | ||
(Shape::from([1].as_slice()), Stride::from([1].as_slice())), | ||
(Shape::from([20, 50, 4].as_slice()), Stride::from([200, 4, 1].as_slice())) | ||
]; | ||
|
||
for (shape, stride) in examples { | ||
assert_eq!(Stride::from(shape), stride); | ||
} | ||
} | ||
} |
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,6 @@ | ||
mod engine; | ||
mod helper; | ||
|
||
fn main() { | ||
|
||
} |