Skip to content

[Add] broadcast function to Operator

The following discussion from !351 (merged) should be addressed:

  • @pineapple started a discussion:

    Is it the same operation as a specific broadcast? If so maybe you could add Tensor::broadcast and call it with the right parameters instead

Example

public:
    Tensor& broadcast(const std::vector<std::size_t>& dims, bool inplace = false);
    Tensor& repeat(std::size_t nbTimes) {
        std::vector<std::size_t> newDims(nbDims() + 1);
        newDims[0] = nbTimes;
        for (std::size_t i = 0; i < nbDims(); ++i) {
            newDims[i+1] = mDims[i];
        }
        return broadcast(newDims, false);
    }
private:
    Tensor& broadcast_inplace(const std::vector<std::size_t>& dims);