-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from termoshtt/factorize-using-tensor-names
Factorize with tensor names, instead of along index
- Loading branch information
Showing
6 changed files
with
118 additions
and
115 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
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,35 @@ | ||
/// Names of tensors | ||
/// | ||
/// As the crate level document explains, | ||
/// einsum factorization requires to track names of tensors | ||
/// in addition to subscripts, and this struct manages it. | ||
/// This works as a simple counter, which counts how many intermediate | ||
/// tensor denoted `out{N}` appears and issues new `out{N+1}` identifier. | ||
/// | ||
#[derive(Debug, PartialEq, Eq, Clone)] | ||
pub struct Namespace { | ||
last: usize, | ||
} | ||
|
||
impl Namespace { | ||
/// Create new namespace | ||
pub fn init() -> Self { | ||
Namespace { last: 0 } | ||
} | ||
|
||
/// Issue new identifier | ||
pub fn new_ident(&mut self) -> Position { | ||
let pos = Position::Intermidiate(self.last); | ||
self.last += 1; | ||
pos | ||
} | ||
} | ||
|
||
/// Which tensor the subscript specifies | ||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)] | ||
pub enum Position { | ||
/// The tensor which user inputs as N-th argument of einsum | ||
User(usize), | ||
/// The tensor created by einsum in its N-th step | ||
Intermidiate(usize), | ||
} |
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