c++ – C++20 : N-dim matrix version 2, broadcasting binary operators

I’ve improved my previous N-dim Matrix class (C++20 : N-dimensional minimal Matrix class), adding some key feature from NumPy: Matrix broadcasting!

Broadcasting is a key required feature for taking inputs with possibly different shape in matrix binary operators.
https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md

Only binary addition has been implemented, other binary operators (sub, mul, div, …) are just similar boilerplates.

Since my code is getting bloated, I’ll post here the GitHub link of notable changes from the previous version:

https://github.com/frozenca/Ndim-Matrix/blob/main/ObjectBase.h

https://github.com/frozenca/Ndim-Matrix/blob/main/MatrixBase.h#L309

https://github.com/frozenca/Ndim-Matrix/blob/main/Matrix.h#L267

https://github.com/frozenca/Ndim-Matrix/blob/main/MatrixUtils.h#L56

https://github.com/frozenca/Ndim-Matrix/blob/main/MatrixUtils.h#L199

Simple broadcasting test:

#include "Matrix.h"
#include <iostream>
#include <iterator>
#include <numeric>

int main() {

    auto m6 = frozenca::ones<double, 3>({2, 3, 3});
    // {{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}}
    std::cout << m6 << 'n';

    auto m7 = frozenca::zeros<int, 2>({1, 3});
    std::iota(std::begin(m7), std::end(m7), 1);
    // {{1, 2, 3}}
    std::cout << m7 << 'n';

    auto m8 = m6 + m7; // type: Matrix<double, 3> with size (2, 3, 3)
    // {{{2, 3, 4}, {2, 3, 4}, {2, 3, 4}}, {{2, 3, 4}, {2, 3, 4}, {2, 3, 4}}}
    std::cout << m8 << 'n';
}

Feel free to comment anything!

Yet to come: Linear algebra stuffs (.dot(), .matmul(), SVD, inverse/pseudoinverse, etc)