(How) Is it possible to constrain a dimension trait to be the product of three other dimensions? e.g. Can one declare a structure with field of type VectorN<f64, DimProd<M, DimProd<N, P>>>
where M
, N
, and P
implement DimName
?
For context I’d like to implement a 2-d convolution operation to pool sub matrices. For pooling scalars, the following skeleton suffices, even being able to compute multiple values/characteristics for each pool.
pub struct Pooler2d<'a, NumRows, NumCols, NumOutputs>
where
NumRows: DimName + DimMul<NumCols>,
NumCols: DimName,
NumOutputs: DimName,
{
op: &'a dyn Operator<DimProd<NumRows, NumCols>, NumOutputs>,
}
Where Operator<NumInputs: DimName, NumOutputs: DimName>
is a trait with a method f(x: &VectorN<f64, NumInputs>) -> Vector<f64, NumOutputs>
.
I’d like to be able to extend Pooler2d
, however, to take as input multiple scalars or a vector for each element in the pool (effectively pooling in three dimensions), but I cannot get the type with the following field with a nested DimProd
to compile
NumChannels: DimName + DimMul<NumRows>,
...
op: &'a dyn Operator<DimProd<NumChannels, DimProd<NumRows, NumCols>>, NumOutputs>,
The error is something like
error[E0277]: cannot multiply `<NumChannels as DimName>::Value` by `_`
--> src/img/conv2d.rs:31:12
|
31 | model: &'a dyn Model<DimProd<NumChannels, DimProd<NumRows, NumCols>>, NumOutputs>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `<NumChannels as DimName>::Value * _`
|
= help: the trait `Mul<_>` is not implemented for `<NumChannels as DimName>::Value`
= note: required because of the requirements on the impl of `DimMul<<NumRows as DimMul<NumCols>>::Output>` for `NumChannels`
Am I just lost in the weeds and should consider dynamically sized vectors and matrices? Operating on VectorN<f64, xxx>
instead of f64
? Thanks for any attention reading this far.