ml-dtypes 0.3.1__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.1 → ml_dtypes-0.4.0}/PKG-INFO +7 -1
  2. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/README.md +6 -0
  3. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/__init__.py +12 -12
  4. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_src/common.h +8 -0
  5. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_src/custom_float.h +71 -87
  6. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_src/dtypes.cc +12 -39
  7. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_src/int4_numpy.h +110 -102
  8. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_src/numpy.h +1 -0
  9. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/include/float8.h +82 -72
  10. ml_dtypes-0.4.0/ml_dtypes/include/int4.h +8 -0
  11. ml_dtypes-0.4.0/ml_dtypes/include/intn.h +313 -0
  12. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes.egg-info/PKG-INFO +7 -1
  13. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes.egg-info/SOURCES.txt +1 -0
  14. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes.egg-info/requires.txt +5 -5
  15. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/pyproject.toml +6 -9
  16. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/setup.py +10 -2
  17. ml_dtypes-0.3.1/ml_dtypes/include/int4.h +0 -262
  18. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/AUTHORS +0 -0
  19. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/LICENSE +0 -0
  20. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/LICENSE.eigen +0 -0
  21. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/MANIFEST.in +0 -0
  22. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_finfo.py +0 -0
  23. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_iinfo.py +0 -0
  24. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_src/numpy.cc +0 -0
  25. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_src/ufuncs.h +0 -0
  26. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/py.typed +0 -0
  27. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes.egg-info/dependency_links.txt +0 -0
  28. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes.egg-info/top_level.txt +0 -0
  29. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/setup.cfg +0 -0
  30. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/Core +0 -0
  31. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ArithmeticSequence.h +0 -0
  32. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Array.h +0 -0
  33. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ArrayBase.h +0 -0
  34. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ArrayWrapper.h +0 -0
  35. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Assign.h +0 -0
  36. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/AssignEvaluator.h +0 -0
  37. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Assign_MKL.h +0 -0
  38. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/BandMatrix.h +0 -0
  39. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Block.h +0 -0
  40. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CommaInitializer.h +0 -0
  41. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ConditionEstimator.h +0 -0
  42. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CoreEvaluators.h +0 -0
  43. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CoreIterators.h +0 -0
  44. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CwiseBinaryOp.h +0 -0
  45. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CwiseNullaryOp.h +0 -0
  46. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CwiseTernaryOp.h +0 -0
  47. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CwiseUnaryOp.h +0 -0
  48. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CwiseUnaryView.h +0 -0
  49. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/DenseBase.h +0 -0
  50. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/DenseCoeffsBase.h +0 -0
  51. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/DenseStorage.h +0 -0
  52. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Diagonal.h +0 -0
  53. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/DiagonalMatrix.h +0 -0
  54. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/DiagonalProduct.h +0 -0
  55. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Dot.h +0 -0
  56. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/EigenBase.h +0 -0
  57. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ForceAlignedAccess.h +0 -0
  58. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Fuzzy.h +0 -0
  59. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/GeneralProduct.h +0 -0
  60. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/GenericPacketMath.h +0 -0
  61. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/GlobalFunctions.h +0 -0
  62. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/IO.h +0 -0
  63. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/IndexedView.h +0 -0
  64. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/InternalHeaderCheck.h +0 -0
  65. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Inverse.h +0 -0
  66. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Map.h +0 -0
  67. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/MapBase.h +0 -0
  68. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/MathFunctions.h +0 -0
  69. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/MathFunctionsImpl.h +0 -0
  70. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Matrix.h +0 -0
  71. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/MatrixBase.h +0 -0
  72. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/NestByValue.h +0 -0
  73. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/NoAlias.h +0 -0
  74. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/NumTraits.h +0 -0
  75. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/PartialReduxEvaluator.h +0 -0
  76. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/PermutationMatrix.h +0 -0
  77. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/PlainObjectBase.h +0 -0
  78. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Product.h +0 -0
  79. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ProductEvaluators.h +0 -0
  80. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Random.h +0 -0
  81. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Redux.h +0 -0
  82. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Ref.h +0 -0
  83. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Replicate.h +0 -0
  84. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Reshaped.h +0 -0
  85. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ReturnByValue.h +0 -0
  86. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Reverse.h +0 -0
  87. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Select.h +0 -0
  88. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/SelfAdjointView.h +0 -0
  89. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/SelfCwiseBinaryOp.h +0 -0
  90. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/SkewSymmetricMatrix3.h +0 -0
  91. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Solve.h +0 -0
  92. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/SolveTriangular.h +0 -0
  93. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/SolverBase.h +0 -0
  94. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/StableNorm.h +0 -0
  95. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/StlIterators.h +0 -0
  96. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Stride.h +0 -0
  97. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Swap.h +0 -0
  98. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Transpose.h +0 -0
  99. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Transpositions.h +0 -0
  100. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/TriangularMatrix.h +0 -0
  101. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/VectorBlock.h +0 -0
  102. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/VectorwiseOp.h +0 -0
  103. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Visitor.h +0 -0
  104. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX/Complex.h +0 -0
  105. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX/MathFunctions.h +0 -0
  106. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX/PacketMath.h +0 -0
  107. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX/TypeCasting.h +0 -0
  108. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/Complex.h +0 -0
  109. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/GemmKernel.h +0 -0
  110. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/MathFunctions.h +0 -0
  111. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/PacketMath.h +0 -0
  112. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/PacketMathFP16.h +0 -0
  113. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/TrsmKernel.h +0 -0
  114. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/TypeCasting.h +0 -0
  115. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/Complex.h +0 -0
  116. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MathFunctions.h +0 -0
  117. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProduct.h +0 -0
  118. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductCommon.h +0 -0
  119. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductMMA.h +0 -0
  120. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductMMAbfloat16.h +0 -0
  121. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixVectorProduct.h +0 -0
  122. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/PacketMath.h +0 -0
  123. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/BFloat16.h +0 -0
  124. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/ConjHelper.h +0 -0
  125. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +0 -0
  126. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h +0 -0
  127. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/Half.h +0 -0
  128. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/Settings.h +0 -0
  129. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/TypeCasting.h +0 -0
  130. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/GPU/Complex.h +0 -0
  131. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/GPU/MathFunctions.h +0 -0
  132. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/GPU/PacketMath.h +0 -0
  133. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/GPU/Tuple.h +0 -0
  134. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/GPU/TypeCasting.h +0 -0
  135. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/HIP/hcc/math_constants.h +0 -0
  136. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/MSA/Complex.h +0 -0
  137. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/MSA/MathFunctions.h +0 -0
  138. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/MSA/PacketMath.h +0 -0
  139. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/Complex.h +0 -0
  140. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/GeneralBlockPanelKernel.h +0 -0
  141. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/MathFunctions.h +0 -0
  142. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/PacketMath.h +0 -0
  143. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/TypeCasting.h +0 -0
  144. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/UnaryFunctors.h +0 -0
  145. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SSE/Complex.h +0 -0
  146. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SSE/MathFunctions.h +0 -0
  147. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SSE/PacketMath.h +0 -0
  148. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SSE/TypeCasting.h +0 -0
  149. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SVE/MathFunctions.h +0 -0
  150. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SVE/PacketMath.h +0 -0
  151. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SVE/TypeCasting.h +0 -0
  152. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SYCL/InteropHeaders.h +0 -0
  153. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SYCL/MathFunctions.h +0 -0
  154. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SYCL/PacketMath.h +0 -0
  155. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SYCL/SyclMemoryModel.h +0 -0
  156. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SYCL/TypeCasting.h +0 -0
  157. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/ZVector/Complex.h +0 -0
  158. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/ZVector/MathFunctions.h +0 -0
  159. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/ZVector/PacketMath.h +0 -0
  160. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/AssignmentFunctors.h +0 -0
  161. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/BinaryFunctors.h +0 -0
  162. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/NullaryFunctors.h +0 -0
  163. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/StlFunctors.h +0 -0
  164. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/TernaryFunctors.h +0 -0
  165. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/UnaryFunctors.h +0 -0
  166. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralBlockPanelKernel.h +0 -0
  167. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrix.h +0 -0
  168. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h +0 -0
  169. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h +0 -0
  170. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h +0 -0
  171. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixVector.h +0 -0
  172. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h +0 -0
  173. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/Parallelizer.h +0 -0
  174. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix.h +0 -0
  175. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h +0 -0
  176. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixVector.h +0 -0
  177. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h +0 -0
  178. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointProduct.h +0 -0
  179. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointRank2Update.h +0 -0
  180. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixMatrix.h +0 -0
  181. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h +0 -0
  182. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixVector.h +0 -0
  183. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h +0 -0
  184. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularSolverMatrix.h +0 -0
  185. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h +0 -0
  186. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularSolverVector.h +0 -0
  187. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Assert.h +0 -0
  188. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/BlasUtil.h +0 -0
  189. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/ConfigureVectorization.h +0 -0
  190. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Constants.h +0 -0
  191. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/DisableStupidWarnings.h +0 -0
  192. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/ForwardDeclarations.h +0 -0
  193. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/IndexedViewHelper.h +0 -0
  194. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/IntegralConstant.h +0 -0
  195. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/MKL_support.h +0 -0
  196. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Macros.h +0 -0
  197. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Memory.h +0 -0
  198. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Meta.h +0 -0
  199. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/ReenableStupidWarnings.h +0 -0
  200. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/ReshapedHelper.h +0 -0
  201. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Serializer.h +0 -0
  202. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/StaticAssert.h +0 -0
  203. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/SymbolicIndex.h +0 -0
  204. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/XprHelper.h +0 -0
  205. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/ArrayCwiseBinaryOps.h +0 -0
  206. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/ArrayCwiseUnaryOps.h +0 -0
  207. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/BlockMethods.h +0 -0
  208. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/CommonCwiseBinaryOps.h +0 -0
  209. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/CommonCwiseUnaryOps.h +0 -0
  210. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/IndexedViewMethods.h +0 -0
  211. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/InternalHeaderCheck.h +0 -0
  212. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/MatrixCwiseBinaryOps.h +0 -0
  213. {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/MatrixCwiseUnaryOps.h +0 -0
  214. {ml_dtypes-0.3.1 → 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.1
3
+ Version: 0.4.0
4
4
  Author-email: ml_dtypes authors <ml_dtypes@google.com>
5
5
  License:
6
6
  Apache License
@@ -268,6 +268,7 @@ array([0, 0, 0, 0], dtype=bfloat16)
268
268
  ```
269
269
  Importing `ml_dtypes` also registers the data types with numpy, so that they may
270
270
  be referred to by their string name:
271
+
271
272
  ```python
272
273
  >>> np.dtype('bfloat16')
273
274
  dtype(bfloat16)
@@ -346,6 +347,7 @@ If you're exploring the use of low-precision dtypes in your code, you should be
346
347
  careful to anticipate when the precision loss might lead to surprising results.
347
348
  One example is the behavior of aggregations like `sum`; consider this `bfloat16`
348
349
  summation in NumPy (run with version 1.24.2):
350
+
349
351
  ```python
350
352
  >>> from ml_dtypes import bfloat16
351
353
  >>> import numpy as np
@@ -357,17 +359,20 @@ summation in NumPy (run with version 1.24.2):
357
359
  The true sum should be close to 5000, but numpy returns exactly 256: this is
358
360
  because `bfloat16` does not have the precision to increment `256` by values less than
359
361
  `1`:
362
+
360
363
  ```python
361
364
  >>> bfloat16(256) + bfloat16(1)
362
365
  256
363
366
  ```
364
367
  After 256, the next representable value in bfloat16 is 258:
368
+
365
369
  ```python
366
370
  >>> np.nextafter(bfloat16(256), bfloat16(np.inf))
367
371
  258
368
372
  ```
369
373
  For better results you can specify that the accumulation should happen in a
370
374
  higher-precision type like `float32`:
375
+
371
376
  ```python
372
377
  >>> vals.sum(dtype='float32').astype(bfloat16)
373
378
  4992
@@ -375,6 +380,7 @@ higher-precision type like `float32`:
375
380
  In contrast to NumPy, projects like [JAX](http://jax.readthedocs.io/) which support
376
381
  low-precision arithmetic more natively will often do these kinds of higher-precision
377
382
  accumulations automatically:
383
+
378
384
  ```python
379
385
  >>> import jax.numpy as jnp
380
386
  >>> jnp.array(vals).sum()
@@ -48,6 +48,7 @@ array([0, 0, 0, 0], dtype=bfloat16)
48
48
  ```
49
49
  Importing `ml_dtypes` also registers the data types with numpy, so that they may
50
50
  be referred to by their string name:
51
+
51
52
  ```python
52
53
  >>> np.dtype('bfloat16')
53
54
  dtype(bfloat16)
@@ -126,6 +127,7 @@ If you're exploring the use of low-precision dtypes in your code, you should be
126
127
  careful to anticipate when the precision loss might lead to surprising results.
127
128
  One example is the behavior of aggregations like `sum`; consider this `bfloat16`
128
129
  summation in NumPy (run with version 1.24.2):
130
+
129
131
  ```python
130
132
  >>> from ml_dtypes import bfloat16
131
133
  >>> import numpy as np
@@ -137,17 +139,20 @@ summation in NumPy (run with version 1.24.2):
137
139
  The true sum should be close to 5000, but numpy returns exactly 256: this is
138
140
  because `bfloat16` does not have the precision to increment `256` by values less than
139
141
  `1`:
142
+
140
143
  ```python
141
144
  >>> bfloat16(256) + bfloat16(1)
142
145
  256
143
146
  ```
144
147
  After 256, the next representable value in bfloat16 is 258:
148
+
145
149
  ```python
146
150
  >>> np.nextafter(bfloat16(256), bfloat16(np.inf))
147
151
  258
148
152
  ```
149
153
  For better results you can specify that the accumulation should happen in a
150
154
  higher-precision type like `float32`:
155
+
151
156
  ```python
152
157
  >>> vals.sum(dtype='float32').astype(bfloat16)
153
158
  4992
@@ -155,6 +160,7 @@ higher-precision type like `float32`:
155
160
  In contrast to NumPy, projects like [JAX](http://jax.readthedocs.io/) which support
156
161
  low-precision arithmetic more natively will often do these kinds of higher-precision
157
162
  accumulations automatically:
163
+
158
164
  ```python
159
165
  >>> import jax.numpy as jnp
160
166
  >>> jnp.array(vals).sum()
@@ -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.1' # 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
@@ -157,6 +157,14 @@ struct TypeDescriptor<std::complex<long double>> {
157
157
  static int Dtype() { return NPY_CLONGDOUBLE; }
158
158
  };
159
159
 
160
+ template <class T>
161
+ struct is_complex : std::false_type {};
162
+ template <class T>
163
+ struct is_complex<std::complex<T>> : std::true_type {};
164
+
165
+ template <typename T>
166
+ inline constexpr bool is_complex_v = is_complex<T>::value;
167
+
160
168
  } // namespace ml_dtypes
161
169
 
162
170
  #endif // ML_DTYPES_COMMON_H_
@@ -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>
@@ -348,7 +357,7 @@ PyObject* PyCustomFloat_RichCompare(PyObject* a, PyObject* b, int op) {
348
357
  PyErr_SetString(PyExc_ValueError, "Invalid op type");
349
358
  return nullptr;
350
359
  }
351
- return PyBool_FromLong(result);
360
+ PyArrayScalar_RETURN_BOOL_FROM_LONG(result);
352
361
  }
353
362
 
354
363
  // Implementation of repr() for PyCustomFloat.
@@ -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
 
@@ -599,12 +610,11 @@ int NPyCustomFloat_ArgMinFunc(void* data, npy_intp n, npy_intp* min_ind,
599
610
 
600
611
  template <typename T>
601
612
  float CastToFloat(T value) {
602
- return static_cast<float>(value);
603
- }
604
-
605
- template <typename T>
606
- float CastToFloat(std::complex<T> value) {
607
- return CastToFloat(value.real());
613
+ if constexpr (is_complex_v<T>) {
614
+ return CastToFloat(value.real());
615
+ } else {
616
+ return static_cast<float>(value);
617
+ }
608
618
  }
609
619
 
610
620
  // Performs a NumPy array cast from type 'From' to 'To'.
@@ -629,8 +639,8 @@ bool RegisterCustomFloatCast(int numpy_type = TypeDescriptor<OtherT>::Dtype()) {
629
639
  NPyCast<OtherT, T>) < 0) {
630
640
  return false;
631
641
  }
632
- if (PyArray_RegisterCastFunc(&CustomFloatType<T>::npy_descr,
633
- numpy_type, NPyCast<T, OtherT>) < 0) {
642
+ if (PyArray_RegisterCastFunc(CustomFloatType<T>::npy_descr, numpy_type,
643
+ NPyCast<T, OtherT>) < 0) {
634
644
  return false;
635
645
  }
636
646
  return true;
@@ -698,27 +708,27 @@ bool RegisterFloatCasts() {
698
708
  }
699
709
 
700
710
  // Safe casts from T to other types
701
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_FLOAT,
711
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_FLOAT,
702
712
  NPY_NOSCALAR) < 0) {
703
713
  return false;
704
714
  }
705
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_DOUBLE,
715
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_DOUBLE,
706
716
  NPY_NOSCALAR) < 0) {
707
717
  return false;
708
718
  }
709
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_LONGDOUBLE,
719
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_LONGDOUBLE,
710
720
  NPY_NOSCALAR) < 0) {
711
721
  return false;
712
722
  }
713
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_CFLOAT,
723
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_CFLOAT,
714
724
  NPY_NOSCALAR) < 0) {
715
725
  return false;
716
726
  }
717
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_CDOUBLE,
727
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_CDOUBLE,
718
728
  NPY_NOSCALAR) < 0) {
719
729
  return false;
720
730
  }
721
- if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_CLONGDOUBLE,
731
+ if (PyArray_RegisterCanCast(TypeDescriptor<T>::npy_descr, NPY_CLONGDOUBLE,
722
732
  NPY_NOSCALAR) < 0) {
723
733
  return false;
724
734
  }
@@ -862,45 +872,9 @@ bool RegisterFloatUFuncs(PyObject* numpy) {
862
872
  return ok;
863
873
  }
864
874
 
865
- // Returns true if the numpy type for T is successfully registered, including if
866
- // it was already registered (e.g. by a different library). If
867
- // `already_registered` is non-null, it's set to true if the type was already
868
- // registered and false otherwise.
869
- template <typename T>
870
- bool RegisterFloatDtype(PyObject* numpy, bool* already_registered = nullptr) {
871
- if (already_registered != nullptr) {
872
- *already_registered = false;
873
- }
874
- // If another module (presumably either TF or JAX) has registered a bfloat16
875
- // type, use it. We don't want two bfloat16 types if we can avoid it since it
876
- // leads to confusion if we have two different types with the same name. This
877
- // assumes that the other module has a sufficiently complete bfloat16
878
- // implementation. The only known NumPy bfloat16 extension at the time of
879
- // writing is this one (distributed in TF and JAX).
880
- // TODO(phawkins): distribute the bfloat16 extension as its own pip package,
881
- // so we can unambiguously refer to a single canonical definition of bfloat16.
882
- int typenum =
883
- PyArray_TypeNumFromName(const_cast<char*>(TypeDescriptor<T>::kTypeName));
884
- if (typenum != NPY_NOTYPE) {
885
- PyArray_Descr* descr = PyArray_DescrFromType(typenum);
886
- // The test for an argmax function here is to verify that the
887
- // bfloat16 implementation is sufficiently new, and, say, not from
888
- // an older version of TF or JAX.
889
- if (descr && descr->f && descr->f->argmax) {
890
- TypeDescriptor<T>::npy_type = typenum;
891
- TypeDescriptor<T>::type_ptr = reinterpret_cast<PyObject*>(descr->typeobj);
892
- if (already_registered != nullptr) {
893
- *already_registered = true;
894
- }
895
- return true;
896
- }
897
- }
898
-
899
- // It's important that we heap-allocate our type. This is because tp_name
900
- // is not a fully-qualified name for a heap-allocated type, and
901
- // PyArray_TypeNumFromName() (above) looks at the tp_name field to find
902
- // types. Existing implementations in JAX and TensorFlow look for "bfloat16",
903
- // not "ml_dtypes.bfloat16" when searching for an implementation.
875
+ template <typename T>
876
+ bool RegisterFloatDtype(PyObject* numpy) {
877
+ // TODO(jakevdp): simplify this; we no longer need heap allocation.
904
878
  Safe_PyObjectPtr name =
905
879
  make_safe(PyUnicode_FromString(TypeDescriptor<T>::kTypeName));
906
880
  Safe_PyObjectPtr qualname =
@@ -958,19 +932,26 @@ bool RegisterFloatDtype(PyObject* numpy, bool* already_registered = nullptr) {
958
932
  arr_funcs.argmax = NPyCustomFloat_ArgMaxFunc<T>;
959
933
  arr_funcs.argmin = NPyCustomFloat_ArgMinFunc<T>;
960
934
 
961
- #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
962
- Py_TYPE(&CustomFloatType<T>::npy_descr) = &PyArrayDescr_Type;
963
- #else
964
- Py_SET_TYPE(&CustomFloatType<T>::npy_descr, &PyArrayDescr_Type);
965
- #endif
966
- 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;
967
944
 
968
- TypeDescriptor<T>::npy_type =
969
- PyArray_RegisterDataType(&CustomFloatType<T>::npy_descr);
970
- if (TypeDescriptor<T>::Dtype() < 0) {
945
+ TypeDescriptor<T>::npy_type = PyArray_RegisterDataType(&descr_proto);
946
+ if (TypeDescriptor<T>::npy_type < 0) {
971
947
  return false;
972
948
  }
973
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
+
974
955
  Safe_PyObjectPtr typeDict_obj =
975
956
  make_safe(PyObject_GetAttrString(numpy, "sctypeDict"));
976
957
  if (!typeDict_obj) return false;
@@ -982,10 +963,9 @@ bool RegisterFloatDtype(PyObject* numpy, bool* already_registered = nullptr) {
982
963
  }
983
964
 
984
965
  // Support dtype(type_name)
985
- if (PyObject_SetAttrString(TypeDescriptor<T>::type_ptr, "dtype",
986
- reinterpret_cast<PyObject*>(
987
- &CustomFloatType<T>::npy_descr)) <
988
- 0) {
966
+ if (PyObject_SetAttrString(
967
+ TypeDescriptor<T>::type_ptr, "dtype",
968
+ reinterpret_cast<PyObject*>(CustomFloatType<T>::npy_descr)) < 0) {
989
969
  return false;
990
970
  }
991
971
 
@@ -994,4 +974,8 @@ bool RegisterFloatDtype(PyObject* numpy, bool* already_registered = nullptr) {
994
974
 
995
975
  } // namespace ml_dtypes
996
976
 
977
+ #if NPY_ABI_VERSION < 0x02000000
978
+ #undef PyArray_DescrProto
979
+ #endif
980
+
997
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
 
@@ -226,61 +226,34 @@ bool Initialize() {
226
226
  if (!RegisterFloatDtype<bfloat16>(numpy.get())) {
227
227
  return false;
228
228
  }
229
- bool float8_e4m3b11fnuz_already_registered;
230
- if (!RegisterFloatDtype<float8_e4m3b11fnuz>(
231
- numpy.get(), &float8_e4m3b11fnuz_already_registered)) {
229
+ if (!RegisterFloatDtype<float8_e4m3b11fnuz>(numpy.get())) {
232
230
  return false;
233
231
  }
234
- bool float8_e4m3fn_already_registered;
235
- if (!ml_dtypes::RegisterFloatDtype<float8_e4m3fn>(
236
- numpy.get(), &float8_e4m3fn_already_registered)) {
232
+ if (!RegisterFloatDtype<float8_e4m3fn>(numpy.get())) {
237
233
  return false;
238
234
  }
239
- bool float8_e4m3fnuz_already_registered;
240
- if (!ml_dtypes::RegisterFloatDtype<float8_e4m3fnuz>(
241
- numpy.get(), &float8_e4m3fnuz_already_registered)) {
235
+ if (!RegisterFloatDtype<float8_e4m3fnuz>(numpy.get())) {
242
236
  return false;
243
237
  }
244
- bool float8_e5m2_already_registered;
245
- if (!ml_dtypes::RegisterFloatDtype<float8_e5m2>(
246
- numpy.get(), &float8_e5m2_already_registered)) {
238
+ if (!RegisterFloatDtype<float8_e5m2>(numpy.get())) {
247
239
  return false;
248
240
  }
249
- bool float8_e5m2fnuz_already_registered;
250
- if (!ml_dtypes::RegisterFloatDtype<float8_e5m2fnuz>(
251
- numpy.get(), &float8_e5m2fnuz_already_registered)) {
241
+ if (!RegisterFloatDtype<float8_e5m2fnuz>(numpy.get())) {
252
242
  return false;
253
243
  }
254
244
 
255
- if (!ml_dtypes::RegisterInt4Dtype<int4>(numpy.get())) {
245
+ if (!RegisterInt4Dtype<int4>(numpy.get())) {
256
246
  return false;
257
247
  }
258
-
259
- if (!ml_dtypes::RegisterInt4Dtype<uint4>(numpy.get())) {
248
+ if (!RegisterInt4Dtype<uint4>(numpy.get())) {
260
249
  return false;
261
250
  }
262
251
 
263
- // Casts between bfloat16 and float8_e4m3b11fnuz. Only perform the cast if
264
- // float8_e4m3b11fnuz hasn't been previously registered, presumably by a
265
- // different library. In this case, we assume the cast has also already been
266
- // registered, and registering it again can cause segfaults due to accessing
267
- // an uninitialized type descriptor in this library.
268
- if (!float8_e4m3b11fnuz_already_registered &&
269
- !RegisterCustomFloatCast<float8_e4m3b11fnuz, bfloat16>()) {
270
- return false;
271
- }
272
- if (!float8_e4m3fnuz_already_registered &&
273
- !float8_e5m2fnuz_already_registered &&
274
- !RegisterTwoWayCustomCast<float8_e4m3fnuz, float8_e5m2fnuz>()) {
275
- return false;
276
- }
277
- if (!float8_e4m3fn_already_registered && !float8_e5m2_already_registered &&
278
- !RegisterCustomFloatCast<float8_e4m3fn, float8_e5m2>()) {
279
- return false;
280
- }
252
+ // Register casts between pairs of custom float dtypes.
281
253
  bool success = true;
282
- // Continue trying to register casts, just in case some types are not
283
- // registered (i.e. float8_e4m3b11fnuz)
254
+ success &= RegisterCustomFloatCast<float8_e4m3b11fnuz, bfloat16>();
255
+ success &= RegisterTwoWayCustomCast<float8_e4m3fnuz, float8_e5m2fnuz>();
256
+ success &= RegisterCustomFloatCast<float8_e4m3fn, float8_e5m2>();
284
257
  success &= RegisterTwoWayCustomCast<float8_e4m3b11fnuz, float8_e4m3fn>();
285
258
  success &= RegisterTwoWayCustomCast<float8_e4m3b11fnuz, float8_e5m2>();
286
259
  success &= RegisterTwoWayCustomCast<bfloat16, float8_e4m3fn>();