expanded predict.gemm function