ml-dtypes 0.3.1__tar.gz → 0.3.2__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 (212) hide show
  1. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/PKG-INFO +7 -1
  2. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/README.md +6 -0
  3. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes/__init__.py +1 -1
  4. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes/_src/common.h +8 -0
  5. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes/_src/custom_float.h +9 -46
  6. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes/_src/dtypes.cc +11 -38
  7. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes/_src/int4_numpy.h +44 -57
  8. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes/_src/numpy.h +1 -0
  9. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes/include/float8.h +82 -72
  10. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes/include/int4.h +97 -47
  11. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes.egg-info/PKG-INFO +7 -1
  12. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes.egg-info/requires.txt +5 -5
  13. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/pyproject.toml +4 -5
  14. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/setup.py +10 -2
  15. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/AUTHORS +0 -0
  16. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/LICENSE +0 -0
  17. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/LICENSE.eigen +0 -0
  18. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/MANIFEST.in +0 -0
  19. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes/_finfo.py +0 -0
  20. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes/_iinfo.py +0 -0
  21. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes/_src/numpy.cc +0 -0
  22. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes/_src/ufuncs.h +0 -0
  23. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes/py.typed +0 -0
  24. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes.egg-info/SOURCES.txt +0 -0
  25. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes.egg-info/dependency_links.txt +0 -0
  26. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/ml_dtypes.egg-info/top_level.txt +0 -0
  27. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/setup.cfg +0 -0
  28. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/Core +0 -0
  29. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/ArithmeticSequence.h +0 -0
  30. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Array.h +0 -0
  31. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/ArrayBase.h +0 -0
  32. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/ArrayWrapper.h +0 -0
  33. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Assign.h +0 -0
  34. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/AssignEvaluator.h +0 -0
  35. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Assign_MKL.h +0 -0
  36. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/BandMatrix.h +0 -0
  37. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Block.h +0 -0
  38. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/CommaInitializer.h +0 -0
  39. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/ConditionEstimator.h +0 -0
  40. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/CoreEvaluators.h +0 -0
  41. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/CoreIterators.h +0 -0
  42. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/CwiseBinaryOp.h +0 -0
  43. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/CwiseNullaryOp.h +0 -0
  44. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/CwiseTernaryOp.h +0 -0
  45. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/CwiseUnaryOp.h +0 -0
  46. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/CwiseUnaryView.h +0 -0
  47. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/DenseBase.h +0 -0
  48. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/DenseCoeffsBase.h +0 -0
  49. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/DenseStorage.h +0 -0
  50. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Diagonal.h +0 -0
  51. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/DiagonalMatrix.h +0 -0
  52. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/DiagonalProduct.h +0 -0
  53. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Dot.h +0 -0
  54. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/EigenBase.h +0 -0
  55. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/ForceAlignedAccess.h +0 -0
  56. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Fuzzy.h +0 -0
  57. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/GeneralProduct.h +0 -0
  58. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/GenericPacketMath.h +0 -0
  59. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/GlobalFunctions.h +0 -0
  60. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/IO.h +0 -0
  61. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/IndexedView.h +0 -0
  62. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/InternalHeaderCheck.h +0 -0
  63. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Inverse.h +0 -0
  64. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Map.h +0 -0
  65. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/MapBase.h +0 -0
  66. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/MathFunctions.h +0 -0
  67. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/MathFunctionsImpl.h +0 -0
  68. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Matrix.h +0 -0
  69. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/MatrixBase.h +0 -0
  70. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/NestByValue.h +0 -0
  71. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/NoAlias.h +0 -0
  72. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/NumTraits.h +0 -0
  73. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/PartialReduxEvaluator.h +0 -0
  74. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/PermutationMatrix.h +0 -0
  75. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/PlainObjectBase.h +0 -0
  76. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Product.h +0 -0
  77. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/ProductEvaluators.h +0 -0
  78. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Random.h +0 -0
  79. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Redux.h +0 -0
  80. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Ref.h +0 -0
  81. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Replicate.h +0 -0
  82. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Reshaped.h +0 -0
  83. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/ReturnByValue.h +0 -0
  84. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Reverse.h +0 -0
  85. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Select.h +0 -0
  86. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/SelfAdjointView.h +0 -0
  87. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/SelfCwiseBinaryOp.h +0 -0
  88. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/SkewSymmetricMatrix3.h +0 -0
  89. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Solve.h +0 -0
  90. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/SolveTriangular.h +0 -0
  91. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/SolverBase.h +0 -0
  92. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/StableNorm.h +0 -0
  93. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/StlIterators.h +0 -0
  94. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Stride.h +0 -0
  95. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Swap.h +0 -0
  96. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Transpose.h +0 -0
  97. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Transpositions.h +0 -0
  98. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/TriangularMatrix.h +0 -0
  99. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/VectorBlock.h +0 -0
  100. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/VectorwiseOp.h +0 -0
  101. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Visitor.h +0 -0
  102. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX/Complex.h +0 -0
  103. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX/MathFunctions.h +0 -0
  104. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX/PacketMath.h +0 -0
  105. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX/TypeCasting.h +0 -0
  106. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX512/Complex.h +0 -0
  107. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX512/GemmKernel.h +0 -0
  108. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX512/MathFunctions.h +0 -0
  109. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX512/PacketMath.h +0 -0
  110. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX512/PacketMathFP16.h +0 -0
  111. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX512/TrsmKernel.h +0 -0
  112. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX512/TypeCasting.h +0 -0
  113. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AltiVec/Complex.h +0 -0
  114. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MathFunctions.h +0 -0
  115. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProduct.h +0 -0
  116. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductCommon.h +0 -0
  117. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductMMA.h +0 -0
  118. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductMMAbfloat16.h +0 -0
  119. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixVectorProduct.h +0 -0
  120. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AltiVec/PacketMath.h +0 -0
  121. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/Default/BFloat16.h +0 -0
  122. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/Default/ConjHelper.h +0 -0
  123. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +0 -0
  124. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h +0 -0
  125. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/Default/Half.h +0 -0
  126. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/Default/Settings.h +0 -0
  127. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/Default/TypeCasting.h +0 -0
  128. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/GPU/Complex.h +0 -0
  129. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/GPU/MathFunctions.h +0 -0
  130. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/GPU/PacketMath.h +0 -0
  131. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/GPU/Tuple.h +0 -0
  132. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/GPU/TypeCasting.h +0 -0
  133. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/HIP/hcc/math_constants.h +0 -0
  134. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/MSA/Complex.h +0 -0
  135. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/MSA/MathFunctions.h +0 -0
  136. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/MSA/PacketMath.h +0 -0
  137. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/NEON/Complex.h +0 -0
  138. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/NEON/GeneralBlockPanelKernel.h +0 -0
  139. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/NEON/MathFunctions.h +0 -0
  140. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/NEON/PacketMath.h +0 -0
  141. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/NEON/TypeCasting.h +0 -0
  142. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/NEON/UnaryFunctors.h +0 -0
  143. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SSE/Complex.h +0 -0
  144. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SSE/MathFunctions.h +0 -0
  145. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SSE/PacketMath.h +0 -0
  146. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SSE/TypeCasting.h +0 -0
  147. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SVE/MathFunctions.h +0 -0
  148. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SVE/PacketMath.h +0 -0
  149. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SVE/TypeCasting.h +0 -0
  150. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SYCL/InteropHeaders.h +0 -0
  151. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SYCL/MathFunctions.h +0 -0
  152. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SYCL/PacketMath.h +0 -0
  153. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SYCL/SyclMemoryModel.h +0 -0
  154. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SYCL/TypeCasting.h +0 -0
  155. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/ZVector/Complex.h +0 -0
  156. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/ZVector/MathFunctions.h +0 -0
  157. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/ZVector/PacketMath.h +0 -0
  158. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/functors/AssignmentFunctors.h +0 -0
  159. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/functors/BinaryFunctors.h +0 -0
  160. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/functors/NullaryFunctors.h +0 -0
  161. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/functors/StlFunctors.h +0 -0
  162. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/functors/TernaryFunctors.h +0 -0
  163. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/functors/UnaryFunctors.h +0 -0
  164. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/GeneralBlockPanelKernel.h +0 -0
  165. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrix.h +0 -0
  166. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h +0 -0
  167. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h +0 -0
  168. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h +0 -0
  169. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixVector.h +0 -0
  170. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h +0 -0
  171. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/Parallelizer.h +0 -0
  172. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix.h +0 -0
  173. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h +0 -0
  174. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixVector.h +0 -0
  175. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h +0 -0
  176. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/SelfadjointProduct.h +0 -0
  177. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/SelfadjointRank2Update.h +0 -0
  178. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixMatrix.h +0 -0
  179. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h +0 -0
  180. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixVector.h +0 -0
  181. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h +0 -0
  182. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/TriangularSolverMatrix.h +0 -0
  183. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h +0 -0
  184. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/TriangularSolverVector.h +0 -0
  185. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/Assert.h +0 -0
  186. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/BlasUtil.h +0 -0
  187. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/ConfigureVectorization.h +0 -0
  188. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/Constants.h +0 -0
  189. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/DisableStupidWarnings.h +0 -0
  190. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/ForwardDeclarations.h +0 -0
  191. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/IndexedViewHelper.h +0 -0
  192. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/IntegralConstant.h +0 -0
  193. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/MKL_support.h +0 -0
  194. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/Macros.h +0 -0
  195. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/Memory.h +0 -0
  196. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/Meta.h +0 -0
  197. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/ReenableStupidWarnings.h +0 -0
  198. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/ReshapedHelper.h +0 -0
  199. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/Serializer.h +0 -0
  200. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/StaticAssert.h +0 -0
  201. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/SymbolicIndex.h +0 -0
  202. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/XprHelper.h +0 -0
  203. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/ArrayCwiseBinaryOps.h +0 -0
  204. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/ArrayCwiseUnaryOps.h +0 -0
  205. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/BlockMethods.h +0 -0
  206. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/CommonCwiseBinaryOps.h +0 -0
  207. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/CommonCwiseUnaryOps.h +0 -0
  208. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/IndexedViewMethods.h +0 -0
  209. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/InternalHeaderCheck.h +0 -0
  210. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/MatrixCwiseBinaryOps.h +0 -0
  211. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/MatrixCwiseUnaryOps.h +0 -0
  212. {ml_dtypes-0.3.1 → ml_dtypes-0.3.2}/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.3.2
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,7 +12,7 @@
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.3.2' # Keep in sync with pyproject.toml:version
16
16
  __all__ = [
17
17
  '__version__',
18
18
  'bfloat16',
@@ -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_
@@ -348,7 +348,7 @@ PyObject* PyCustomFloat_RichCompare(PyObject* a, PyObject* b, int op) {
348
348
  PyErr_SetString(PyExc_ValueError, "Invalid op type");
349
349
  return nullptr;
350
350
  }
351
- return PyBool_FromLong(result);
351
+ PyArrayScalar_RETURN_BOOL_FROM_LONG(result);
352
352
  }
353
353
 
354
354
  // Implementation of repr() for PyCustomFloat.
@@ -599,12 +599,11 @@ int NPyCustomFloat_ArgMinFunc(void* data, npy_intp n, npy_intp* min_ind,
599
599
 
600
600
  template <typename T>
601
601
  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());
602
+ if constexpr (is_complex_v<T>) {
603
+ return CastToFloat(value.real());
604
+ } else {
605
+ return static_cast<float>(value);
606
+ }
608
607
  }
609
608
 
610
609
  // Performs a NumPy array cast from type 'From' to 'To'.
@@ -862,45 +861,9 @@ bool RegisterFloatUFuncs(PyObject* numpy) {
862
861
  return ok;
863
862
  }
864
863
 
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.
864
+ template <typename T>
865
+ bool RegisterFloatDtype(PyObject* numpy) {
866
+ // TODO(jakevdp): simplify this; we no longer need heap allocation.
904
867
  Safe_PyObjectPtr name =
905
868
  make_safe(PyUnicode_FromString(TypeDescriptor<T>::kTypeName));
906
869
  Safe_PyObjectPtr qualname =
@@ -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>();
@@ -16,6 +16,7 @@ limitations under the License.
16
16
  #ifndef ML_DTYPES_INT4_NUMPY_H_
17
17
  #define ML_DTYPES_INT4_NUMPY_H_
18
18
 
19
+ #include <limits>
19
20
  #include <type_traits>
20
21
 
21
22
  // Must be included first
@@ -55,7 +56,7 @@ int Int4TypeDescriptor<T>::npy_type = NPY_NOTYPE;
55
56
  template <typename T>
56
57
  PyObject* Int4TypeDescriptor<T>::type_ptr = nullptr;
57
58
 
58
- // Representation of a Python custom float object.
59
+ // Representation of a Python custom integer object.
59
60
  template <typename T>
60
61
  struct PyInt4 {
61
62
  PyObject_HEAD; // Python object header
@@ -96,7 +97,7 @@ Safe_PyObjectPtr PyInt4_FromValue(T x) {
96
97
  return ref;
97
98
  }
98
99
 
99
- // Converts a Python object to a reduced float value. Returns true on success,
100
+ // Converts a Python object to a reduced integer value. Returns true on success,
100
101
  // returns false and reports a Python error on failure.
101
102
  template <typename T>
102
103
  bool CastToInt4(PyObject* arg, T* output) {
@@ -143,8 +144,8 @@ bool CastToInt4(PyObject* arg, T* output) {
143
144
  *output = T(v);
144
145
  return true;
145
146
  }
146
- if (PyArray_IsScalar(arg, Float)) {
147
- float f;
147
+ auto floating_conversion = [&](auto type) -> bool {
148
+ decltype(type) f;
148
149
  PyArray_ScalarAsCtype(arg, &f);
149
150
  if (!(std::numeric_limits<T>::min() <= f &&
150
151
  f <= std::numeric_limits<T>::max())) {
@@ -153,17 +154,19 @@ bool CastToInt4(PyObject* arg, T* output) {
153
154
  }
154
155
  *output = T(static_cast<::int8_t>(f));
155
156
  return true;
157
+ };
158
+ if (PyArray_IsScalar(arg, Half)) {
159
+ return floating_conversion(Eigen::half{});
160
+ }
161
+ if (PyArray_IsScalar(arg, Float)) {
162
+ return floating_conversion(float{});
156
163
  }
157
164
  if (PyArray_IsScalar(arg, Double)) {
158
- double d;
159
- PyArray_ScalarAsCtype(arg, &d);
160
- if (!(std::numeric_limits<T>::min() <= d &&
161
- d <= std::numeric_limits<T>::max())) {
162
- PyErr_SetString(PyExc_OverflowError, kOutOfRange);
163
- return false;
164
- }
165
- *output = T(static_cast<::int8_t>(d));
166
- return true;
165
+ return floating_conversion(double{});
166
+ }
167
+ if (PyArray_IsScalar(arg, LongDouble)) {
168
+ using ld = long double;
169
+ return floating_conversion(ld{});
167
170
  }
168
171
  return false;
169
172
  }
@@ -216,14 +219,13 @@ PyObject* PyInt4_tp_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
216
219
  template <typename T>
217
220
  PyObject* PyInt4_nb_float(PyObject* self) {
218
221
  T x = PyInt4_Value_Unchecked<T>(self);
219
- return PyFloat_FromDouble(static_cast<double>(static_cast<float>(x)));
222
+ return PyFloat_FromDouble(static_cast<double>(x));
220
223
  }
221
224
 
222
225
  template <typename T>
223
226
  PyObject* PyInt4_nb_int(PyObject* self) {
224
227
  T x = PyInt4_Value_Unchecked<T>(self);
225
- long y = static_cast<long>(static_cast<float>(x)); // NOLINT
226
- return PyLong_FromLong(y);
228
+ return PyLong_FromLong(static_cast<long>(x)); // NOLINT
227
229
  }
228
230
 
229
231
  template <typename T>
@@ -396,7 +398,7 @@ PyObject* PyInt4_RichCompare(PyObject* a, PyObject* b, int op) {
396
398
  PyErr_SetString(PyExc_ValueError, "Invalid op type");
397
399
  return nullptr;
398
400
  }
399
- return PyBool_FromLong(result);
401
+ PyArrayScalar_RETURN_BOOL_FROM_LONG(result);
400
402
  }
401
403
 
402
404
  // Numpy support
@@ -538,12 +540,11 @@ int NPyInt4_CompareFunc(const void* v1, const void* v2, void* arr) {
538
540
  template <typename T>
539
541
  int NPyInt4_ArgMaxFunc(void* data, npy_intp n, npy_intp* max_ind, void* arr) {
540
542
  const T* bdata = reinterpret_cast<const T*>(data);
541
- // Start with a max_val of NaN, this results in the first iteration preferring
542
- // bdata[0].
543
- int max_val = std::numeric_limits<int>::max();
543
+ // Start with a max_val of INT_MIN, this results in the first iteration
544
+ // preferring bdata[0].
545
+ int max_val = std::numeric_limits<int>::lowest();
544
546
  for (npy_intp i = 0; i < n; ++i) {
545
- // This condition is chosen so that NaNs are always considered "max".
546
- if (!(static_cast<int>(bdata[i]) <= max_val)) {
547
+ if (static_cast<int>(bdata[i]) > max_val) {
547
548
  max_val = static_cast<int>(bdata[i]);
548
549
  *max_ind = i;
549
550
  }
@@ -554,12 +555,11 @@ int NPyInt4_ArgMaxFunc(void* data, npy_intp n, npy_intp* max_ind, void* arr) {
554
555
  template <typename T>
555
556
  int NPyInt4_ArgMinFunc(void* data, npy_intp n, npy_intp* min_ind, void* arr) {
556
557
  const T* bdata = reinterpret_cast<const T*>(data);
557
- int min_val = std::numeric_limits<int>::lowest();
558
- // Start with a min_val of NaN, this results in the first iteration preferring
559
- // bdata[0].
558
+ int min_val = std::numeric_limits<int>::max();
559
+ // Start with a min_val of INT_MAX, this results in the first iteration
560
+ // preferring bdata[0].
560
561
  for (npy_intp i = 0; i < n; ++i) {
561
- // This condition is chosen so that NaNs are always considered "min".
562
- if (!(static_cast<int>(bdata[i]) >= min_val)) {
562
+ if (static_cast<int>(bdata[i]) < min_val) {
563
563
  min_val = static_cast<int>(bdata[i]);
564
564
  *min_ind = i;
565
565
  }
@@ -567,30 +567,21 @@ int NPyInt4_ArgMinFunc(void* data, npy_intp n, npy_intp* min_ind, void* arr) {
567
567
  return 0;
568
568
  }
569
569
 
570
- template <typename T, std::enable_if_t<(std::is_floating_point<T>::value ||
571
- std::is_same<T, Eigen::half>::value),
572
- bool> = true>
570
+ template <typename T>
573
571
  int CastToInt(T value) {
574
- if (std::isnan(value) || std::isinf(value) ||
575
- value < std::numeric_limits<int>::lowest() ||
576
- value > std::numeric_limits<int>::max()) {
577
- return 0;
572
+ if constexpr (is_complex_v<T>) {
573
+ return CastToInt(value.real());
574
+ } else {
575
+ static_assert(std::numeric_limits<T>::is_specialized);
576
+ if constexpr (!std::numeric_limits<T>::is_integer) {
577
+ if (std::isnan(value) || std::isinf(value) ||
578
+ value < std::numeric_limits<int>::lowest() ||
579
+ value > std::numeric_limits<int>::max()) {
580
+ return 0;
581
+ }
582
+ }
583
+ return static_cast<int>(value);
578
584
  }
579
- return static_cast<int>(value);
580
- }
581
-
582
- template <typename T, std::enable_if_t<std::is_integral<T>::value, bool> = true>
583
- int CastToInt(T value) {
584
- return static_cast<int>(value);
585
- }
586
-
587
- int CastToInt(int4 value) { return static_cast<int>(value); }
588
-
589
- int CastToInt(uint4 value) { return static_cast<int>(value); }
590
-
591
- template <typename T>
592
- int CastToInt(std::complex<T> value) {
593
- return CastToInt(value.real());
594
585
  }
595
586
 
596
587
  // Performs a NumPy array cast from type 'From' to 'To'.
@@ -718,6 +709,10 @@ bool RegisterInt4Casts() {
718
709
  return false;
719
710
  }
720
711
  }
712
+ if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_HALF,
713
+ NPY_NOSCALAR) < 0) {
714
+ return false;
715
+ }
721
716
  if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_FLOAT,
722
717
  NPY_NOSCALAR) < 0) {
723
718
  return false;
@@ -748,14 +743,6 @@ bool RegisterInt4Casts() {
748
743
  TypeDescriptor<T>::Dtype(), NPY_NOSCALAR) < 0) {
749
744
  return false;
750
745
  }
751
- if (PyArray_RegisterCanCast(PyArray_DescrFromType(NPY_UBYTE),
752
- TypeDescriptor<T>::Dtype(), NPY_NOSCALAR) < 0) {
753
- return false;
754
- }
755
- if (PyArray_RegisterCanCast(PyArray_DescrFromType(NPY_BYTE),
756
- TypeDescriptor<T>::Dtype(), NPY_NOSCALAR) < 0) {
757
- return false;
758
- }
759
746
 
760
747
  return true;
761
748
  }
@@ -35,6 +35,7 @@ limitations under the License.
35
35
  #include <Python.h>
36
36
 
37
37
  #include "numpy/arrayobject.h"
38
+ #include "numpy/arrayscalars.h"
38
39
  #include "numpy/ufuncobject.h"
39
40
 
40
41
  namespace ml_dtypes {