xtensor-stack / xtensor-blas

BLAS extension to xtensor
BSD 3-Clause "New" or "Revised" License
155 stars 54 forks source link

[Feature request] Support xt::linalg::outer for higher-dimensional objects #231

Open mircomarahrens opened 1 year ago

mircomarahrens commented 1 year ago

Hello,

currently xt::linalg::outer only supports 1D vectors and is missing higher-dimensional objects. A quick workaround could be:

template<typename T>
static inline auto outer(expression_type <T> &M, expression_type <T> &W) {
    auto &&dM = M.derived_cast(); auto &&dW = W.derived_cast();
    shape_type shapeM = shape(M);
    dM = expand_dims(dM, shapeM.size());
    dW = expand_dims(dW, 0);
    return tensordot(dM, dW, {shapeM.size()}, {0});;
}

Is there a particular reason why only 1D vectors are supported in xt::linalg::outer?

Best regards, Mirco