Repository navigation
Conversation
…rnels and name the type in errors for complex sorting
…nd from rounding long double scalars
…where NumPy has no float128
…re NumPy has no float128
…nvert long double where it is double
…rings, builders, printing and conversions
…ON instead of raising
…omplex unique, JSON and builder conversions
…le values and update the license line of the new test files
…unding it to double
…and-float16 # Conflicts: # src/awkward/prettyprint.py
…s runs Python 3.11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI text below 🤖
Makes
float16, long double (float128) and long double complex (complex256) work in everything awkward does itself, and raise an error that names the type wherever another library has no such type. Before this, every reducer and sort on these types raised aKeyErrorfrom the kernel lookup (scikit-hep#4259), and a few other places crashed.What works now
kernel-specification.yml).float16data are given to thefloat32kernels and the result is cast back. NumPy computesfloat16the same way: it adds and multiplies infloat32and rounds once at the end.ak.types.from_datashapeandak.enforce_typeparsefloat16,float128andcomplex256, so a type can read back what it prints.LayoutBuilder::Numpy<long double>names its primitive the way NumPy does.ak.covarandak.corrkeep long double, asnp.covandnp.corrcoefdo. Narrower floats still becomefloat64.formatter={"float": ...}applies tofloat16. The long double formatters apply on platforms where NumPy has nofloat128name.ak.from_iterandArrayBuildertakenp.clongdoublescalars (segfault on Linux andRecursionErroron macOS before).ak.to_jsonwrites long double (TypeErrorbefore).ak.minandak.maxwith a long doubleinitialkeep its digits. ctypes would otherwise round the value to a double on its way into the kernel.ak.validity_erroruses for categorical data.What raises
float16TypeError. Passing the array through, slicing it and reading other fields still work.TypeErrorak.to_rdataframefloat16TypeErrorak.to_arrow,ak.to_parquet,ak.to_featherTypeErrorak.sort,ak.argsort, unique along an axisValueErrorValueErrorEach message for a missing type says how to convert the data first. Numba, Arrow and C++ have no such types. Sorting complex numbers has never had kernels, and the unique kernels sort.
Decisions to check
ArrayBuilderand JSON hold doubles. The builder has one real and one complex node type (float64,complex128), which is also whynp.float32scalars come out asfloat64. Python'sjsonmodule writes Python floats. So a long double scalar or value is rounded to the nearest double there, on platforms where long double is wider. Keeping long double in the builder needs new node types across the C++ builder classes, which this does not add.ArrowNotImplementedError: Unsupported numpy type 15forcomplex64andcomplex128too. Where long double is the same as double (macOS arm64, Windows) it converts.awkward-cppchanges without a version bump. It stays at 58.DTYPEpattern to exactly what Lark 0.12.0 produces from upstream's grammar with the three names added.float16total that overflows warns. The cast back tofloat16emits NumPy'sRuntimeWarning, asnp.sumdoes. Thefloat32andfloat64kernels stay silent, as before.ak.to_torch,ak.to_tensorflow,ak.to_jaxandak.to_cupy. Those libraries report unsupported types themselves.float128on Linux cannot be read where NumPy has no such type. Nothing here changes that.Tests
tests/test_4259_float16_and_longdouble.pycovers each area above, andheader-only/tests/test_4259-layout-builder-long-double.cppcovers the C++ naming. Run locally on three platforms:tests/Downstream suites against this branch (
pytest tests, macOS arm64, Python 3.14):Byte order. There is no big-endian CI job, so the diff was checked by inspection. The kernels only do typed arithmetic and comparisons, and the Python side converts values (
float16tofloat32, long double tofloat64) or reinterprets data only between types of the same size and native order. awkward accepts arrays in native byte order only, and buffers written and read in the opposite order round-trip for all three types, with each part of a complex number swapped on its own.The vector failure is
test_issue_621, which callsak.jax.register_and_check(). This repository has no JAX backend, so it does not depend on this change.