Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod display;
pub mod domain;
pub mod functions;
pub mod mapping;
pub mod signature;
pub mod tensor;

pub use display::{BoxedTensor, format_boxed};
Expand All @@ -15,10 +16,11 @@ pub use functions::{
zeros,
};
pub use mapping::{
BoxedMapping, BoxedPowersetMapping, COO, Concat, Diagonal, EmptyMapping, HRectSignature,
IndexMapping, InvProjection, Permutation, Powerset, PowersetMapping, Projection, Signature,
Squeeze, Stride, Unsqueeze, Where,
BoxedMapping, BoxedPowersetMapping, COO, Concat, Diagonal, EmptyMapping, IndexMapping,
InvProjection, Permutation, Powerset, PowersetMapping, Projection, Squeeze, Stride, Unsqueeze,
Where,
};
pub use signature::{HRectSignature, Signature};
pub use tensor::{
Inf, InfReduction, JaggedTensor, LeftComposition, Physical, Product, ProductReduction,
Reduction, ReductionTensor, RightComposition, Sum, SumReduction, Sup, SupReduction, Tensor,
Expand Down
26 changes: 2 additions & 24 deletions src/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::rc::Rc;

use crate::display::BoxedTensor;
use crate::domain::{Domain, HRect, JaggedDomain};
use crate::signature::{HRectSignature, Signature};

/// A set of indices, as returned by a `PowersetMapping`.
pub type Powerset = HashSet<Vec<usize>>;
Expand Down Expand Up @@ -39,29 +40,6 @@ pub trait BoxedPowersetMapping: PowersetMapping {
fn hrect(&self) -> &HRect;
}

/// The domain and codomain a mapping runs between.
pub struct Signature<D: Domain, C: Domain> {
domain: D,
codomain: C,
}

impl<D: Domain, C: Domain> Signature<D, C> {
pub fn new(domain: D, codomain: C) -> Self {
Self { domain, codomain }
}

pub fn domain(&self) -> &D {
&self.domain
}

pub fn codomain(&self) -> &C {
&self.codomain
}
}

/// The signature of a mapping between two hyperrectangles.
pub type HRectSignature = Signature<HRect, HRect>;

/// What a mapping from a hyperrectangle has to provide. Implementing this rather
/// than `IndexMapping` gets the domain accessors and printability below for
/// free, whatever the codomain; a mapping over a domain that is not a hrect
Expand Down Expand Up @@ -557,7 +535,7 @@ impl HRectMapping for Projection {
}

/// The inverse of the projection dropping axis `dim`.
/// e.g. with dim=1, f(m, p) = {[m n p]^T | n in [N]}
/// e.g. with dim=1, f(m, p) = {[m n p]^T | n in \[N\]}
pub struct InvProjection {
signature: HRectSignature,
dim: usize,
Expand Down
26 changes: 26 additions & 0 deletions src/signature.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! The domain and codomain a mapping runs between.

use crate::domain::{Domain, HRect};

/// The domain and codomain a mapping runs between.
pub struct Signature<D: Domain, C: Domain> {
domain: D,
codomain: C,
}

impl<D: Domain, C: Domain> Signature<D, C> {
pub fn new(domain: D, codomain: C) -> Self {
Self { domain, codomain }
}

pub fn domain(&self) -> &D {
&self.domain
}

pub fn codomain(&self) -> &C {
&self.codomain
}
}

/// The signature of a mapping between two hyperrectangles.
pub type HRectSignature = Signature<HRect, HRect>;
Loading