[Mlir-commits] [mlir] [mlir][vector] Update doc for vector.broadcast (nfc) (PR #228727)

Federico Bruzzone llvmlistbot at llvm.org
Sun Oct 4 04:51:06 PDT 2026


https://github.com/FedericoBruzzone approved this pull request.

LGTM, thank you, Andrzej! It looks great to me. I used pen and paper, BTW :'D

---

I just wanted to share an example in the hope that it might help streamline the work for the other folks, specifically for the *otherwise* case.

Consider, for instance, `broadcast(source: vector<2x3>, result: vector<4x2x3>)`, where `rank(source) = N = 2` and `rank(result) = K = 3`. In this case, for `i in [2, 3]` and `j in [1, 2]`, we have `N-K < i <= N` and `j = i + K - N`.

The question is: **given an element of `result`, what is its corresponding coordinate in `source`?**

For example, consider `result[1,0,2]`. Its linear offset is

`off = (1 * 6) + (0 * 3) + (2 * 1) = 8`,

where `6 = 3 * 2`, `3`, and `1` are the strides of the first, second, and third dimensions of `result`, respectively.

Since `source` has rank 2, we need to recover two coordinates from this offset:

* For `j = 1`: `floor(8 / 3) % 2 = 0`, since `result_stride(2) = 3`.
* For `j = 2`: `floor(8 / 1) % 3 = 2`, since `result_stride(3) = 1`.

Therefore, the element mapping is: `result[1,0,2] -> source[0,2]`.


https://github.com/llvm/llvm-project/pull/228727


More information about the Mlir-commits mailing list