[Type] ndarray typing 4: Make primitive dtypes Python classes wrapping DataTypeCxx#414
[Type] ndarray typing 4: Make primitive dtypes Python classes wrapping DataTypeCxx#414hughperkins wants to merge 8 commits intohp/typing-t4-3-cook-dtypefrom
Conversation
89f34d8 to
72a9636
Compare
2ec1c5d to
24584de
Compare
|
Opus 4.6 review: PR Review: hp/typing-t4-4-dtype-classesSummaryThis PR refactors primitive dtypes (f32, i32, etc.) from bare Issues Found1.
|
24584de to
cb8f4a0
Compare
72a9636 to
9b5e1a8
Compare
cb8f4a0 to
9899efb
Compare
1adb863 to
71dcd62
Compare
bbc0f0b to
3a1b4f5
Compare
Convert primitive dtypes (f32, i32, etc.) from bare DataTypeCxx module-level variables into Python classes with a PrimitiveMeta metaclass. Each class has a .cxx attribute holding the underlying DataTypeCxx, and the metaclass delegates __eq__, __hash__, __getattr__ for backward compatibility. Update cook_dtype, to_quadrants_type, MAP_TYPE_IDS, and type utility functions to handle the new class-based types. Add PrimitiveBase checks in expr_init and quant.py.
3a1b4f5 to
9bbc16b
Compare
Move 'import inspect' in exception.py and the 'from quadrants.lang.exception import get_func_signature' in _kernel_impl_dataclass.py from inside functions to the module top-level, fixing the pylint import-outside-toplevel (C0415) errors introduced by the get_func_signature refactor. Made-with: Cursor
The Vulkan/Metal backends on macOS lack f64 support and crash when running this test, which uses qd.f64 fields. Add require=qd.extension.data64 to skip on backends without double-precision support. Made-with: Cursor
The branch is out of date with main, missing the workflow fix from #428 that pins torch to CUDA 12.8 for CUDA tests. Without this, `pip install torch` pulls torch 2.11.0 built against CUDA 13, which is incompatible with the CUDA 12.8 toolkit on the runner, causing all torch+CUDA dlpack tests to fail. Made-with: Cursor
After the dtype refactor, calling primitive dtype classes (e.g. qd.u32(value), qd.i32(value)) inside @qd.func bodies broke because the new Python classes inherited type.__call__ which tried to instantiate them with no __init__ args. This surfaced as pyright errors in main's _tile16.py once merged with this branch. Add a metaclass __call__ that delegates to cls.cxx(value), preserving the DataTypeCxx-style cast/IR-emit semantics expected by call sites. Made-with: Cursor
Pyright uses __init__/__new__ signatures (not metaclass __call__) when type-checking class instantiation. With the new PrimitiveBase classes, calls like qd.u32(j) and qd.i32(...) reported "Expected 0 positional arguments" because PrimitiveBase had no __init__. Add a typing-only __init__ stub (never invoked at runtime since PrimitiveMeta.__call__ short-circuits instantiation). Also reference PrimitiveMeta directly in _install_python_backend_dtype_call instead of going through the misleadingly-named ``type(f32)`` indirection, so pyright sees the correct ``(cls, value)`` signature when calling the saved ``_original`` callable. Made-with: Cursor
The C++ binding for data_type_size only accepts DataTypeCxx instances. With the new dtype Python wrapper classes (qd.i8, qd.f32, etc.), callers that pass qd.i8 directly to qd._lib.core.data_type_size hit a TypeError. Monkey-patch the binding to transparently unwrap PrimitiveBase subclasses to their underlying .cxx attribute before calling the C++ implementation. This unblocks the merged-with-main test_shared_array_not_accumulated_across_offloads test which passes qd.i8/qd.f32/qd.u32 directly to the C++ binding. Made-with: Cursor
…hp/typing-t4-4-dtype-classes Made-with: Cursor # Conflicts: # python/quadrants/lang/exception.py # tests/python/test_ad_basics_fwd.py
Convert primitive dtypes (f32, i32, etc.) from bare DataTypeCxx module-level variables into Python classes with a PrimitiveMeta metaclass. Each class has a .cxx attribute holding the underlying DataTypeCxx, and the metaclass delegates eq, hash, getattr for backward compatibility.
Update cook_dtype, to_quadrants_type, MAP_TYPE_IDS, and type utility functions to handle the new class-based types. Add PrimitiveBase checks in expr_init and quant.py.
Issue: #
Brief Summary
copilot:summary
Walkthrough
copilot:walkthrough