joelberkeley/spidr

An `Isomorphic` type for isomorphic shapes?

Opened this issue · 0 comments

In some case it's useful to be able to say "this thing works for this shape and any shapes isomorphic to it". Isomorphic shapes include those with extra or fewer dimensions of length 1 e.g. [3, 1, 2], [3, 2] and [1, 3, 2]. It is essentially a cross between Squeezable and a subset of Broadcastable.

A use case I came across was ClosedFormDistribution for Gaussian. This is implemented for event shape [1], but could equally be implemented for [] or [1, 1], with sth like

Isomorphic shape [] => ClosedFormDistribution shape Gaussian where
  ...

and we'd presumably reshape within the implementation as appropriate. Similar could be done for GaussianProcess so that we don't need targets = [1]