use crate::shapes::Dyn;
use crate::shapes::broadcast::ReverseShape;
use crate::shapes::dim::Dim;
use crate::shapes::idx::FromEnd;
use crate::shapes::shape::{DimCons, Shape};
use core::ops::Add;
#[diagnostic::on_unimplemented(
message = "Cannot concatenate shape `{Self}` with `{S2}` along axis `{Axis}`",
label = "Shape mismatch during concatenation",
note = "Concatenation requires all dimensions except the given axis to match exactly"
)]
pub trait ConcatShape<S2, Axis> {
type Output: Shape;
}
pub trait TryConcatShape<S2> {
type Output: Shape;
}
impl<S1: Shape, S2: Shape> TryConcatShape<S2> for S1 {
type Output = Dyn;
}
impl<H1: Dim + Add<H2>, H2: Dim, T: Shape> ConcatShape<DimCons<H2, T>, crate::shapes::idx::Here>
for DimCons<H1, T>
where
<H1 as Add<H2>>::Output: Dim,
{
type Output = DimCons<<H1 as Add<H2>>::Output, T>;
}
impl<H: Dim, T1: Shape, T2: Shape, SubCursor>
ConcatShape<DimCons<H, T2>, crate::shapes::idx::Next<SubCursor>> for DimCons<H, T1>
where
T1: ConcatShape<T2, SubCursor>,
{
type Output = DimCons<H, <T1 as ConcatShape<T2, SubCursor>>::Output>;
}
impl<S, S2, SR, S2R, O, Output> ConcatShape<S2, FromEnd<crate::shapes::idx::Here>> for S
where
S: Shape + ReverseShape<Output = SR>,
S2: Shape + ReverseShape<Output = S2R>,
SR: ConcatShape<S2R, crate::shapes::idx::Here, Output = O>,
O: Shape + ReverseShape<Output = Output>,
Output: Shape,
{
type Output = Output;
}
impl<S, S2, Cursor, SR, S2R, O, Output> ConcatShape<S2, FromEnd<crate::shapes::idx::Next<Cursor>>>
for S
where
Cursor: crate::shapes::shape::ForwardCursor,
S: Shape + ReverseShape<Output = SR>,
S2: Shape + ReverseShape<Output = S2R>,
SR: ConcatShape<S2R, crate::shapes::idx::Next<Cursor>, Output = O>,
O: Shape + ReverseShape<Output = Output>,
Output: Shape,
{
type Output = Output;
}