Add fill() generator that yields a user-provided value at all indices#1162
Add fill() generator that yields a user-provided value at all indices#1162tbensonatl wants to merge 4 commits intomainfrom
Conversation
New matx::fill(shape, value) generator that returns an operator that yields the same value at every index. Modeled on ones/zeros, but with a caller-supplied value and no default for T — the type is deduced from value or specified explicitly. This avoids the case of a default type (e.g., int) causing unwanted conversions or truncations of the user-provided value. Signed-off-by: Thomas Benson <tbenson@nvidia.com>
|
Isn't this the same as https://github.com/NVIDIA/MatX/blob/main/include/matx/operators/constval.h? |
Greptile SummaryThis PR adds Confidence Score: 5/5Safe to merge; the single finding is a P2 documentation label mismatch that does not affect runtime behavior. All logic is correct and consistent with existing ones/zeros patterns. The only issue is a misleading section heading in the .rst file — the rendered example for 'Shapeless form' actually shows the ranked form. docs_input/api/creation/operators/fill.rst — section label for fill-gen-test-2 needs correction. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["fill(shape, value) call site"] --> B{Overload resolution}
B -->|"ShapeType&& (non-array)"| C["fill(ShapeType&&, T value)"]
B -->|"C-style array index_t[RANK]"| D["fill(const index_t(&)[RANK], T value)"]
B -->|"Empty brace {}"| E["fill(initializer_list<no_size_t>, T value)"]
B -->|"No shape argument"| F["fill(T value)"]
C --> G["ConstVal<T, ShapeType>(s, value)"]
D -->|"to_array(s)"| C
E -->|"array<index_t,0>{}"| C
F -->|"NoShape{}"| C
G --> H["Rank() = tuple_size<ShapeType> OR matxNoRank"]
Reviews (4): Last reviewed commit: "Add better-motivated examples for the fi..." | Re-trigger Greptile |
| .. doxygenfunction:: matx::fill(ShapeType &&s, T value) | ||
| .. doxygenfunction:: matx::fill(const index_t (&s)[RANK], T value) | ||
| .. doxygenfunction:: matx::fill(T value) |
There was a problem hiding this comment.
Missing doxygen directive for rank-0 empty-brace overload
The .rst file documents three of the four public overloads, but the rank-0 empty-brace form fill(const std::initializer_list<detail::no_size_t>, T value) has no doxygenfunction directive. The prose and fill-gen-test-3 example cover the usage, but the auto-generated API reference table will omit that overload signature. Consider adding:
.. doxygenfunction:: matx::fill(const std::initializer_list<detail::no_size_t>, T value)
Yes. This is just syntactic sugar over ConstVal -- it returns a ConstVal. Unless I missed the operator/generator wrapper, users would need to do something like:
to make their own ConstVal. We could call this matx::constval. I just used fill to align with numpy naming conventions. |
Signed-off-by: Thomas Benson <tbenson@nvidia.com>
|
/build |
cliffburdick
left a comment
There was a problem hiding this comment.
@tbensonatl is this effectively the same as just using a constant, but in situations where you may want the shape to be different? I'm looking at the tests and some of them can just be:
(A = 3.f).run();
The constant should adapt it's shape to anything on the lhs or rhs.
Yes, in that case it could just be a literal. The motivating case is that greptile is unhappy that I dropped support for a scalar argument input for the sar_bp operator so that it now requires either a rank-0 or rank-1 tensor. I mainly did that to clean up the sar_bp kernel code. This would basically be a drop-in replacement where users can now pass |
Signed-off-by: Thomas Benson <tbenson@nvidia.com>
|
/build |
Alternatively, if we only want to cover the scalar-to-rank-0 operator case, then we could just add something like |
Signed-off-by: Thomas Benson <tbenson@nvidia.com>
|
/build |
New matx::fill(shape, value) generator that returns an operator that yields the same value at every index. Modeled on ones/zeros, but with a caller-supplied value and no default for T — the type is deduced from value or specified explicitly. This avoids the case of a default type (e.g., int) causing unwanted conversions or truncations of the user-provided value.