ml-dtypes 0.3.2__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/PKG-INFO +1 -1
  2. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes/__init__.py +12 -12
  3. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes/_src/custom_float.h +62 -41
  4. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes/_src/dtypes.cc +1 -1
  5. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes/_src/int4_numpy.h +67 -46
  6. ml_dtypes-0.4.0/ml_dtypes/include/int4.h +8 -0
  7. ml_dtypes-0.4.0/ml_dtypes/include/intn.h +313 -0
  8. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes.egg-info/PKG-INFO +1 -1
  9. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes.egg-info/SOURCES.txt +1 -0
  10. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/pyproject.toml +3 -5
  11. ml_dtypes-0.3.2/ml_dtypes/include/int4.h +0 -312
  12. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/AUTHORS +0 -0
  13. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/LICENSE +0 -0
  14. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/LICENSE.eigen +0 -0
  15. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/MANIFEST.in +0 -0
  16. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/README.md +0 -0
  17. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes/_finfo.py +0 -0
  18. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes/_iinfo.py +0 -0
  19. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes/_src/common.h +0 -0
  20. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes/_src/numpy.cc +0 -0
  21. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes/_src/numpy.h +0 -0
  22. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes/_src/ufuncs.h +0 -0
  23. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes/include/float8.h +0 -0
  24. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes/py.typed +0 -0
  25. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes.egg-info/dependency_links.txt +0 -0
  26. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes.egg-info/requires.txt +0 -0
  27. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/ml_dtypes.egg-info/top_level.txt +0 -0
  28. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/setup.cfg +0 -0
  29. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/setup.py +0 -0
  30. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/Core +0 -0
  31. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ArithmeticSequence.h +0 -0
  32. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Array.h +0 -0
  33. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ArrayBase.h +0 -0
  34. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ArrayWrapper.h +0 -0
  35. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Assign.h +0 -0
  36. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/AssignEvaluator.h +0 -0
  37. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Assign_MKL.h +0 -0
  38. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/BandMatrix.h +0 -0
  39. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Block.h +0 -0
  40. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CommaInitializer.h +0 -0
  41. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ConditionEstimator.h +0 -0
  42. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CoreEvaluators.h +0 -0
  43. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CoreIterators.h +0 -0
  44. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CwiseBinaryOp.h +0 -0
  45. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CwiseNullaryOp.h +0 -0
  46. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CwiseTernaryOp.h +0 -0
  47. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CwiseUnaryOp.h +0 -0
  48. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CwiseUnaryView.h +0 -0
  49. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/DenseBase.h +0 -0
  50. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/DenseCoeffsBase.h +0 -0
  51. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/DenseStorage.h +0 -0
  52. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Diagonal.h +0 -0
  53. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/DiagonalMatrix.h +0 -0
  54. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/DiagonalProduct.h +0 -0
  55. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Dot.h +0 -0
  56. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/EigenBase.h +0 -0
  57. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ForceAlignedAccess.h +0 -0
  58. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Fuzzy.h +0 -0
  59. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/GeneralProduct.h +0 -0
  60. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/GenericPacketMath.h +0 -0
  61. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/GlobalFunctions.h +0 -0
  62. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/IO.h +0 -0
  63. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/IndexedView.h +0 -0
  64. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/InternalHeaderCheck.h +0 -0
  65. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Inverse.h +0 -0
  66. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Map.h +0 -0
  67. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/MapBase.h +0 -0
  68. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/MathFunctions.h +0 -0
  69. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/MathFunctionsImpl.h +0 -0
  70. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Matrix.h +0 -0
  71. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/MatrixBase.h +0 -0
  72. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/NestByValue.h +0 -0
  73. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/NoAlias.h +0 -0
  74. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/NumTraits.h +0 -0
  75. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/PartialReduxEvaluator.h +0 -0
  76. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/PermutationMatrix.h +0 -0
  77. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/PlainObjectBase.h +0 -0
  78. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Product.h +0 -0
  79. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ProductEvaluators.h +0 -0
  80. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Random.h +0 -0
  81. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Redux.h +0 -0
  82. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Ref.h +0 -0
  83. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Replicate.h +0 -0
  84. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Reshaped.h +0 -0
  85. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ReturnByValue.h +0 -0
  86. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Reverse.h +0 -0
  87. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Select.h +0 -0
  88. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/SelfAdjointView.h +0 -0
  89. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/SelfCwiseBinaryOp.h +0 -0
  90. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/SkewSymmetricMatrix3.h +0 -0
  91. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Solve.h +0 -0
  92. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/SolveTriangular.h +0 -0
  93. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/SolverBase.h +0 -0
  94. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/StableNorm.h +0 -0
  95. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/StlIterators.h +0 -0
  96. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Stride.h +0 -0
  97. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Swap.h +0 -0
  98. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Transpose.h +0 -0
  99. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Transpositions.h +0 -0
  100. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/TriangularMatrix.h +0 -0
  101. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/VectorBlock.h +0 -0
  102. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/VectorwiseOp.h +0 -0
  103. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Visitor.h +0 -0
  104. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX/Complex.h +0 -0
  105. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX/MathFunctions.h +0 -0
  106. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX/PacketMath.h +0 -0
  107. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX/TypeCasting.h +0 -0
  108. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/Complex.h +0 -0
  109. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/GemmKernel.h +0 -0
  110. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/MathFunctions.h +0 -0
  111. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/PacketMath.h +0 -0
  112. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/PacketMathFP16.h +0 -0
  113. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/TrsmKernel.h +0 -0
  114. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/TypeCasting.h +0 -0
  115. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/Complex.h +0 -0
  116. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MathFunctions.h +0 -0
  117. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProduct.h +0 -0
  118. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductCommon.h +0 -0
  119. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductMMA.h +0 -0
  120. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductMMAbfloat16.h +0 -0
  121. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixVectorProduct.h +0 -0
  122. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/PacketMath.h +0 -0
  123. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/BFloat16.h +0 -0
  124. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/ConjHelper.h +0 -0
  125. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +0 -0
  126. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h +0 -0
  127. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/Half.h +0 -0
  128. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/Settings.h +0 -0
  129. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/TypeCasting.h +0 -0
  130. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/GPU/Complex.h +0 -0
  131. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/GPU/MathFunctions.h +0 -0
  132. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/GPU/PacketMath.h +0 -0
  133. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/GPU/Tuple.h +0 -0
  134. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/GPU/TypeCasting.h +0 -0
  135. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/HIP/hcc/math_constants.h +0 -0
  136. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/MSA/Complex.h +0 -0
  137. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/MSA/MathFunctions.h +0 -0
  138. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/MSA/PacketMath.h +0 -0
  139. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/Complex.h +0 -0
  140. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/GeneralBlockPanelKernel.h +0 -0
  141. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/MathFunctions.h +0 -0
  142. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/PacketMath.h +0 -0
  143. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/TypeCasting.h +0 -0
  144. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/UnaryFunctors.h +0 -0
  145. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SSE/Complex.h +0 -0
  146. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SSE/MathFunctions.h +0 -0
  147. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SSE/PacketMath.h +0 -0
  148. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SSE/TypeCasting.h +0 -0
  149. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SVE/MathFunctions.h +0 -0
  150. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SVE/PacketMath.h +0 -0
  151. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SVE/TypeCasting.h +0 -0
  152. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SYCL/InteropHeaders.h +0 -0
  153. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SYCL/MathFunctions.h +0 -0
  154. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SYCL/PacketMath.h +0 -0
  155. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SYCL/SyclMemoryModel.h +0 -0
  156. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SYCL/TypeCasting.h +0 -0
  157. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/ZVector/Complex.h +0 -0
  158. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/ZVector/MathFunctions.h +0 -0
  159. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/ZVector/PacketMath.h +0 -0
  160. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/AssignmentFunctors.h +0 -0
  161. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/BinaryFunctors.h +0 -0
  162. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/NullaryFunctors.h +0 -0
  163. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/StlFunctors.h +0 -0
  164. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/TernaryFunctors.h +0 -0
  165. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/UnaryFunctors.h +0 -0
  166. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralBlockPanelKernel.h +0 -0
  167. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrix.h +0 -0
  168. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h +0 -0
  169. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h +0 -0
  170. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h +0 -0
  171. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixVector.h +0 -0
  172. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h +0 -0
  173. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/Parallelizer.h +0 -0
  174. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix.h +0 -0
  175. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h +0 -0
  176. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixVector.h +0 -0
  177. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h +0 -0
  178. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointProduct.h +0 -0
  179. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointRank2Update.h +0 -0
  180. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixMatrix.h +0 -0
  181. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h +0 -0
  182. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixVector.h +0 -0
  183. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h +0 -0
  184. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularSolverMatrix.h +0 -0
  185. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h +0 -0
  186. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularSolverVector.h +0 -0
  187. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Assert.h +0 -0
  188. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/BlasUtil.h +0 -0
  189. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/ConfigureVectorization.h +0 -0
  190. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Constants.h +0 -0
  191. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/DisableStupidWarnings.h +0 -0
  192. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/ForwardDeclarations.h +0 -0
  193. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/IndexedViewHelper.h +0 -0
  194. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/IntegralConstant.h +0 -0
  195. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/MKL_support.h +0 -0
  196. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Macros.h +0 -0
  197. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Memory.h +0 -0
  198. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Meta.h +0 -0
  199. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/ReenableStupidWarnings.h +0 -0
  200. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/ReshapedHelper.h +0 -0
  201. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Serializer.h +0 -0
  202. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/StaticAssert.h +0 -0
  203. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/SymbolicIndex.h +0 -0
  204. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/XprHelper.h +0 -0
  205. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/ArrayCwiseBinaryOps.h +0 -0
  206. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/ArrayCwiseUnaryOps.h +0 -0
  207. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/BlockMethods.h +0 -0
  208. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/CommonCwiseBinaryOps.h +0 -0
  209. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/CommonCwiseUnaryOps.h +0 -0
  210. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/IndexedViewMethods.h +0 -0
  211. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/InternalHeaderCheck.h +0 -0
  212. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/MatrixCwiseBinaryOps.h +0 -0
  213. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/MatrixCwiseUnaryOps.h +0 -0
  214. {ml_dtypes-0.3.2 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/ReshapedMethods.h +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ml_dtypes
3
- Version: 0.3.2
3
+ Version: 0.4.0
4
4
  Author-email: ml_dtypes authors <ml_dtypes@google.com>
5
5
  License:
6
6
  Apache License
@@ -12,19 +12,19 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- __version__ = '0.3.2' # Keep in sync with pyproject.toml:version
15
+ __version__ = "0.4.0" # Keep in sync with pyproject.toml:version
16
16
  __all__ = [
17
- '__version__',
18
- 'bfloat16',
19
- 'finfo',
20
- 'float8_e4m3b11fnuz',
21
- 'float8_e4m3fn',
22
- 'float8_e4m3fnuz',
23
- 'float8_e5m2',
24
- 'float8_e5m2fnuz',
25
- 'iinfo',
26
- 'int4',
27
- 'uint4',
17
+ "__version__",
18
+ "bfloat16",
19
+ "finfo",
20
+ "float8_e4m3b11fnuz",
21
+ "float8_e4m3fn",
22
+ "float8_e4m3fnuz",
23
+ "float8_e5m2",
24
+ "float8_e5m2fnuz",
25
+ "iinfo",
26
+ "int4",
27
+ "uint4",
28
28
  ]
29
29
 
30
30
  from typing import Type
@@ -35,13 +35,17 @@ limitations under the License.
35
35
  #include <Python.h>
36
36
 
37
37
  #include "Eigen/Core"
38
- #include "_src/common.h" // NOLINT
38
+ #include "_src/common.h" // NOLINT
39
39
  #include "_src/ufuncs.h" // NOLINT
40
40
 
41
41
  #undef copysign // TODO(ddunleavy): temporary fix for Windows bazel build
42
42
  // Possible this has to do with numpy.h being included before
43
43
  // system headers and in bfloat16.{cc,h}?
44
44
 
45
+ #if NPY_ABI_VERSION < 0x02000000
46
+ #define PyArray_DescrProto PyArray_Descr
47
+ #endif
48
+
45
49
  namespace ml_dtypes {
46
50
 
47
51
  template <typename T>
@@ -59,13 +63,18 @@ struct CustomFloatType {
59
63
 
60
64
  static PyNumberMethods number_methods;
61
65
  static PyArray_ArrFuncs arr_funcs;
62
- static PyArray_Descr npy_descr;
66
+ static PyArray_DescrProto npy_descr_proto;
67
+ static PyArray_Descr* npy_descr;
63
68
  };
64
69
 
65
70
  template <typename T>
66
71
  int CustomFloatType<T>::npy_type = NPY_NOTYPE;
67
72
  template <typename T>
68
73
  PyObject* CustomFloatType<T>::type_ptr = nullptr;
74
+ template <typename T>
75
+ PyArray_DescrProto CustomFloatType<T>::npy_descr_proto;
76
+ template <typename T>
77
+ PyArray_Descr* CustomFloatType<T>::npy_descr = nullptr;
69
78
 
70
79
  // Representation of a Python custom float object.
71
80
  template <typename T>
@@ -397,24 +406,26 @@ template <typename T>
397
406
  PyArray_ArrFuncs CustomFloatType<T>::arr_funcs;
398
407
 
399
408
  template <typename T>
400
- PyArray_Descr CustomFloatType<T>::npy_descr = {
401
- PyObject_HEAD_INIT(nullptr)
402
- /*typeobj=*/nullptr, // Filled in later
403
- /*kind=*/TypeDescriptor<T>::kNpyDescrKind,
404
- /*type=*/TypeDescriptor<T>::kNpyDescrType,
405
- /*byteorder=*/TypeDescriptor<T>::kNpyDescrByteorder,
406
- /*flags=*/NPY_NEEDS_PYAPI | NPY_USE_SETITEM,
407
- /*type_num=*/0,
408
- /*elsize=*/sizeof(T),
409
- /*alignment=*/alignof(T),
410
- /*subarray=*/nullptr,
411
- /*fields=*/nullptr,
412
- /*names=*/nullptr,
413
- /*f=*/&CustomFloatType<T>::arr_funcs,
414
- /*metadata=*/nullptr,
415
- /*c_metadata=*/nullptr,
416
- /*hash=*/-1, // -1 means "not computed yet".
417
- };
409
+ PyArray_DescrProto GetCustomFloatDescrProto() {
410
+ return {
411
+ PyObject_HEAD_INIT(nullptr)
412
+ /*typeobj=*/nullptr, // Filled in later
413
+ /*kind=*/TypeDescriptor<T>::kNpyDescrKind,
414
+ /*type=*/TypeDescriptor<T>::kNpyDescrType,
415
+ /*byteorder=*/TypeDescriptor<T>::kNpyDescrByteorder,
416
+ /*flags=*/NPY_NEEDS_PYAPI | NPY_USE_SETITEM,
417
+ /*type_num=*/0,
418
+ /*elsize=*/sizeof(T),
419
+ /*alignment=*/alignof(T),
420
+ /*subarray=*/nullptr,
421
+ /*fields=*/nullptr,
422
+ /*names=*/nullptr,
423
+ /*f=*/&CustomFloatType<T>::arr_funcs,
424
+ /*metadata=*/nullptr,
425
+ /*c_metadata=*/nullptr,
426
+ /*hash=*/-1, // -1 means "not computed yet".
427
+ };
428
+ }
418
429
 
419
430
  // Implementations of NumPy array methods.
420
431
 
@@ -628,8 +639,8 @@ bool RegisterCustomFloatCast(int numpy_type = TypeDescriptor<OtherT>::Dtype()) {
628
639
  NPyCast<OtherT, T>) < 0) {
629
640
  return false;
630
641
  }
631
- if (PyArray_RegisterCastFunc(&CustomFloatType<T>::npy_descr,
632
- numpy_type, NPyCast<T, OtherT>) < 0) {
642
+ if (PyArray_RegisterCastFunc(CustomFloatType<T>::npy_descr, numpy_type,
643
+ NPyCast<T, OtherT>) < 0) {
633
644
  return false;
634
645
  }
635
646
  return true;
@@ -697,27 +708,27 @@ bool RegisterFloatCasts() {
697
708
  }
698
709
 
699
710
  // Safe casts from T to other types
700
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_FLOAT,
711
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_FLOAT,
701
712
  NPY_NOSCALAR) < 0) {
702
713
  return false;
703
714
  }
704
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_DOUBLE,
715
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_DOUBLE,
705
716
  NPY_NOSCALAR) < 0) {
706
717
  return false;
707
718
  }
708
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_LONGDOUBLE,
719
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_LONGDOUBLE,
709
720
  NPY_NOSCALAR) < 0) {
710
721
  return false;
711
722
  }
712
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_CFLOAT,
723
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_CFLOAT,
713
724
  NPY_NOSCALAR) < 0) {
714
725
  return false;
715
726
  }
716
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_CDOUBLE,
727
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_CDOUBLE,
717
728
  NPY_NOSCALAR) < 0) {
718
729
  return false;
719
730
  }
720
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_CLONGDOUBLE,
731
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_CLONGDOUBLE,
721
732
  NPY_NOSCALAR) < 0) {
722
733
  return false;
723
734
  }
@@ -921,19 +932,26 @@ bool RegisterFloatDtype(PyObject* numpy) {
921
932
  arr_funcs.argmax = NPyCustomFloat_ArgMaxFunc<T>;
922
933
  arr_funcs.argmin = NPyCustomFloat_ArgMinFunc<T>;
923
934
 
924
- #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
925
- Py_TYPE(&CustomFloatType<T>::npy_descr) = &PyArrayDescr_Type;
926
- #else
927
- Py_SET_TYPE(&CustomFloatType<T>::npy_descr, &PyArrayDescr_Type);
928
- #endif
929
- TypeDescriptor<T>::npy_descr.typeobj = type;
935
+ // This is messy, but that's because the NumPy 2.0 API transition is messy.
936
+ // Before 2.0, NumPy assumes we'll keep the descriptor passed in to
937
+ // RegisterDataType alive, because it stores its pointer.
938
+ // After 2.0, the proto and descriptor types diverge, and NumPy allocates
939
+ // and manages the lifetime of the descriptor itself.
940
+ PyArray_DescrProto& descr_proto = CustomFloatType<T>::npy_descr_proto;
941
+ descr_proto = GetCustomFloatDescrProto<T>();
942
+ Py_SET_TYPE(&descr_proto, &PyArrayDescr_Type);
943
+ descr_proto.typeobj = type;
930
944
 
931
- TypeDescriptor<T>::npy_type =
932
- PyArray_RegisterDataType(&CustomFloatType<T>::npy_descr);
933
- if (TypeDescriptor<T>::Dtype() < 0) {
945
+ TypeDescriptor<T>::npy_type = PyArray_RegisterDataType(&descr_proto);
946
+ if (TypeDescriptor<T>::npy_type < 0) {
934
947
  return false;
935
948
  }
936
949
 
950
+ // TODO(phawkins): We intentionally leak the pointer to the descriptor.
951
+ // Implement a better module destructor to handle this.
952
+ CustomFloatType<T>::npy_descr =
953
+ PyArray_DescrFromType(TypeDescriptor<T>::npy_type);
954
+
937
955
  Safe_PyObjectPtr typeDict_obj =
938
956
  make_safe(PyObject_GetAttrString(numpy, "sctypeDict"));
939
957
  if (!typeDict_obj) return false;
@@ -945,10 +963,9 @@ bool RegisterFloatDtype(PyObject* numpy) {
945
963
  }
946
964
 
947
965
  // Support dtype(type_name)
948
- if (PyObject_SetAttrString(TypeDescriptor<T>::type_ptr, "dtype",
949
- reinterpret_cast<PyObject*>(
950
- &CustomFloatType<T>::npy_descr)) <
951
- 0) {
966
+ if (PyObject_SetAttrString(
967
+ TypeDescriptor<T>::type_ptr, "dtype",
968
+ reinterpret_cast<PyObject*>(CustomFloatType<T>::npy_descr)) < 0) {
952
969
  return false;
953
970
  }
954
971
 
@@ -957,4 +974,8 @@ bool RegisterFloatDtype(PyObject* numpy) {
957
974
 
958
975
  } // namespace ml_dtypes
959
976
 
977
+ #if NPY_ABI_VERSION < 0x02000000
978
+ #undef PyArray_DescrProto
979
+ #endif
980
+
960
981
  #endif // ML_DTYPES_CUSTOM_FLOAT_H_
@@ -33,7 +33,7 @@ limitations under the License.
33
33
  #include "_src/custom_float.h"
34
34
  #include "_src/int4_numpy.h"
35
35
  #include "include/float8.h"
36
- #include "include/int4.h"
36
+ #include "include/intn.h"
37
37
 
38
38
  namespace ml_dtypes {
39
39
 
@@ -27,7 +27,11 @@ limitations under the License.
27
27
  #include "Eigen/Core"
28
28
  #include "_src/common.h" // NOLINT
29
29
  #include "_src/ufuncs.h" // NOLINT
30
- #include "include/int4.h"
30
+ #include "include/intn.h"
31
+
32
+ #if NPY_ABI_VERSION < 0x02000000
33
+ #define PyArray_DescrProto PyArray_Descr
34
+ #endif
31
35
 
32
36
  namespace ml_dtypes {
33
37
 
@@ -48,13 +52,18 @@ struct Int4TypeDescriptor {
48
52
 
49
53
  static PyNumberMethods number_methods;
50
54
  static PyArray_ArrFuncs arr_funcs;
51
- static PyArray_Descr npy_descr;
55
+ static PyArray_DescrProto npy_descr_proto;
56
+ static PyArray_Descr* npy_descr;
52
57
  };
53
58
 
54
59
  template <typename T>
55
60
  int Int4TypeDescriptor<T>::npy_type = NPY_NOTYPE;
56
61
  template <typename T>
57
62
  PyObject* Int4TypeDescriptor<T>::type_ptr = nullptr;
63
+ template <typename T>
64
+ PyArray_DescrProto Int4TypeDescriptor<T>::npy_descr_proto;
65
+ template <typename T>
66
+ PyArray_Descr* Int4TypeDescriptor<T>::npy_descr = nullptr;
58
67
 
59
68
  // Representation of a Python custom integer object.
60
69
  template <typename T>
@@ -406,24 +415,26 @@ template <typename T>
406
415
  PyArray_ArrFuncs Int4TypeDescriptor<T>::arr_funcs;
407
416
 
408
417
  template <typename T>
409
- PyArray_Descr Int4TypeDescriptor<T>::npy_descr = {
410
- PyObject_HEAD_INIT(nullptr)
411
- /*typeobj=*/nullptr, // Filled in later
412
- /*kind=*/TypeDescriptor<T>::kNpyDescrKind,
413
- /*type=*/TypeDescriptor<T>::kNpyDescrType,
414
- /*byteorder=*/TypeDescriptor<T>::kNpyDescrByteorder,
415
- /*flags=*/NPY_NEEDS_PYAPI | NPY_USE_SETITEM,
416
- /*type_num=*/0,
417
- /*elsize=*/sizeof(T),
418
- /*alignment=*/alignof(T),
419
- /*subarray=*/nullptr,
420
- /*fields=*/nullptr,
421
- /*names=*/nullptr,
422
- /*f=*/&Int4TypeDescriptor<T>::arr_funcs,
423
- /*metadata=*/nullptr,
424
- /*c_metadata=*/nullptr,
425
- /*hash=*/-1, // -1 means "not computed yet".
426
- };
418
+ PyArray_DescrProto GetInt4DescrProto() {
419
+ return {
420
+ PyObject_HEAD_INIT(nullptr)
421
+ /*typeobj=*/nullptr, // Filled in later
422
+ /*kind=*/TypeDescriptor<T>::kNpyDescrKind,
423
+ /*type=*/TypeDescriptor<T>::kNpyDescrType,
424
+ /*byteorder=*/TypeDescriptor<T>::kNpyDescrByteorder,
425
+ /*flags=*/NPY_NEEDS_PYAPI | NPY_USE_SETITEM,
426
+ /*type_num=*/0,
427
+ /*elsize=*/sizeof(T),
428
+ /*alignment=*/alignof(T),
429
+ /*subarray=*/nullptr,
430
+ /*fields=*/nullptr,
431
+ /*names=*/nullptr,
432
+ /*f=*/&Int4TypeDescriptor<T>::arr_funcs,
433
+ /*metadata=*/nullptr,
434
+ /*c_metadata=*/nullptr,
435
+ /*hash=*/-1, // -1 means "not computed yet".
436
+ };
437
+ }
427
438
 
428
439
  // Implementations of NumPy array methods.
429
440
 
@@ -606,7 +617,7 @@ bool RegisterCustomIntCast(int numpy_type = TypeDescriptor<OtherT>::Dtype()) {
606
617
  IntegerCast<OtherT, T>) < 0) {
607
618
  return false;
608
619
  }
609
- if (PyArray_RegisterCastFunc(&Int4TypeDescriptor<T>::npy_descr, numpy_type,
620
+ if (PyArray_RegisterCastFunc(Int4TypeDescriptor<T>::npy_descr, numpy_type,
610
621
  IntegerCast<T, OtherT>) < 0) {
611
622
  return false;
612
623
  }
@@ -674,66 +685,66 @@ bool RegisterInt4Casts() {
674
685
  }
675
686
 
676
687
  // Safe casts from T to other types
677
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_INT8,
688
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_INT8,
678
689
  NPY_NOSCALAR) < 0) {
679
690
  return false;
680
691
  }
681
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_INT16,
692
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_INT16,
682
693
  NPY_NOSCALAR) < 0) {
683
694
  return false;
684
695
  }
685
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_INT32,
696
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_INT32,
686
697
  NPY_NOSCALAR) < 0) {
687
698
  return false;
688
699
  }
689
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_INT64,
700
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_INT64,
690
701
  NPY_NOSCALAR) < 0) {
691
702
  return false;
692
703
  }
693
704
 
694
705
  if (std::is_same_v<uint4, T>) {
695
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_UINT8,
706
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_UINT8,
696
707
  NPY_NOSCALAR) < 0) {
697
708
  return false;
698
709
  }
699
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_UINT16,
710
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_UINT16,
700
711
  NPY_NOSCALAR) < 0) {
701
712
  return false;
702
713
  }
703
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_UINT32,
714
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_UINT32,
704
715
  NPY_NOSCALAR) < 0) {
705
716
  return false;
706
717
  }
707
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_UINT64,
718
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_UINT64,
708
719
  NPY_NOSCALAR) < 0) {
709
720
  return false;
710
721
  }
711
722
  }
712
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_HALF,
723
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_HALF,
713
724
  NPY_NOSCALAR) < 0) {
714
725
  return false;
715
726
  }
716
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_FLOAT,
727
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_FLOAT,
717
728
  NPY_NOSCALAR) < 0) {
718
729
  return false;
719
730
  }
720
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_DOUBLE,
731
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_DOUBLE,
721
732
  NPY_NOSCALAR) < 0) {
722
733
  return false;
723
734
  }
724
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_LONGDOUBLE,
735
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_LONGDOUBLE,
725
736
  NPY_NOSCALAR) < 0) {
726
737
  return false;
727
738
  }
728
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_CFLOAT,
739
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_CFLOAT,
729
740
  NPY_NOSCALAR) < 0) {
730
741
  return false;
731
742
  }
732
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_CDOUBLE,
743
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_CDOUBLE,
733
744
  NPY_NOSCALAR) < 0) {
734
745
  return false;
735
746
  }
736
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_CLONGDOUBLE,
747
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_CLONGDOUBLE,
737
748
  NPY_NOSCALAR) < 0) {
738
749
  return false;
739
750
  }
@@ -821,18 +832,24 @@ bool RegisterInt4Dtype(PyObject* numpy) {
821
832
  arr_funcs.argmax = NPyInt4_ArgMaxFunc<T>;
822
833
  arr_funcs.argmin = NPyInt4_ArgMinFunc<T>;
823
834
 
824
- #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
825
- Py_TYPE(&Int4TypeDescriptor<T>::npy_descr) = &PyArrayDescr_Type;
826
- #else
827
- Py_SET_TYPE(&Int4TypeDescriptor<T>::npy_descr, &PyArrayDescr_Type);
828
- #endif
829
- TypeDescriptor<T>::npy_descr.typeobj = type;
835
+ // This is messy, but that's because the NumPy 2.0 API transition is messy.
836
+ // Before 2.0, NumPy assumes we'll keep the descriptor passed in to
837
+ // RegisterDataType alive, because it stores its pointer.
838
+ // After 2.0, the proto and descriptor types diverge, and NumPy allocates
839
+ // and manages the lifetime of the descriptor itself.
840
+ PyArray_DescrProto& descr_proto = Int4TypeDescriptor<T>::npy_descr_proto;
841
+ descr_proto = GetInt4DescrProto<T>();
842
+ Py_SET_TYPE(&descr_proto, &PyArrayDescr_Type);
843
+ descr_proto.typeobj = type;
830
844
 
831
- TypeDescriptor<T>::npy_type =
832
- PyArray_RegisterDataType(&Int4TypeDescriptor<T>::npy_descr);
833
- if (TypeDescriptor<T>::Dtype() < 0) {
845
+ TypeDescriptor<T>::npy_type = PyArray_RegisterDataType(&descr_proto);
846
+ if (TypeDescriptor<T>::npy_type < 0) {
834
847
  return false;
835
848
  }
849
+ // TODO(phawkins): We intentionally leak the pointer to the descriptor.
850
+ // Implement a better module destructor to handle this.
851
+ Int4TypeDescriptor<T>::npy_descr =
852
+ PyArray_DescrFromType(TypeDescriptor<T>::npy_type);
836
853
 
837
854
  Safe_PyObjectPtr typeDict_obj =
838
855
  make_safe(PyObject_GetAttrString(numpy, "sctypeDict"));
@@ -847,7 +864,7 @@ bool RegisterInt4Dtype(PyObject* numpy) {
847
864
  // Support dtype(type_name)
848
865
  if (PyObject_SetAttrString(
849
866
  TypeDescriptor<T>::type_ptr, "dtype",
850
- reinterpret_cast<PyObject*>(&Int4TypeDescriptor<T>::npy_descr)) < 0) {
867
+ reinterpret_cast<PyObject*>(Int4TypeDescriptor<T>::npy_descr)) < 0) {
851
868
  return false;
852
869
  }
853
870
 
@@ -856,4 +873,8 @@ bool RegisterInt4Dtype(PyObject* numpy) {
856
873
 
857
874
  } // namespace ml_dtypes
858
875
 
876
+ #if NPY_ABI_VERSION < 0x02000000
877
+ #undef PyArray_DescrProto
878
+ #endif
879
+
859
880
  #endif // ML_DTYPES_INT4_NUMPY_H_
@@ -0,0 +1,8 @@
1
+ #ifndef THIRD_PARTY_PY_ML_DTYPES_INCLUDE_INT4_H_
2
+ #define THIRD_PARTY_PY_ML_DTYPES_INCLUDE_INT4_H_
3
+
4
+ // IWYU pragma: begin_exports
5
+ #include "include/intn.h" // INLINER_FORWARD_TO
6
+ // IWYU pragma: end_exports
7
+
8
+ #endif // THIRD_PARTY_PY_ML_DTYPES_INCLUDE_INT4_H_