Obtains the input tensor ranks as template parameters from prod(). It then matches the bases of the input tensors and eventually calls prod_impl_impl via the pack expansion idiom to match the number of contracted indices also as a template parameter.