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.
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/PKG-INFO +7 -1
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/README.md +6 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/__init__.py +12 -12
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_src/common.h +8 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_src/custom_float.h +71 -87
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_src/dtypes.cc +12 -39
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_src/int4_numpy.h +110 -102
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_src/numpy.h +1 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/include/float8.h +82 -72
- ml_dtypes-0.4.0/ml_dtypes/include/int4.h +8 -0
- ml_dtypes-0.4.0/ml_dtypes/include/intn.h +313 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes.egg-info/PKG-INFO +7 -1
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes.egg-info/SOURCES.txt +1 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes.egg-info/requires.txt +5 -5
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/pyproject.toml +6 -9
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/setup.py +10 -2
- ml_dtypes-0.3.1/ml_dtypes/include/int4.h +0 -262
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/AUTHORS +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/LICENSE +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/LICENSE.eigen +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/MANIFEST.in +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_finfo.py +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_iinfo.py +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_src/numpy.cc +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/_src/ufuncs.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes/py.typed +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes.egg-info/dependency_links.txt +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/ml_dtypes.egg-info/top_level.txt +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/setup.cfg +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/Core +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ArithmeticSequence.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Array.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ArrayBase.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ArrayWrapper.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Assign.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/AssignEvaluator.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Assign_MKL.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/BandMatrix.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Block.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CommaInitializer.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ConditionEstimator.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CoreEvaluators.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CoreIterators.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CwiseBinaryOp.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CwiseNullaryOp.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CwiseTernaryOp.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CwiseUnaryOp.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/CwiseUnaryView.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/DenseBase.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/DenseCoeffsBase.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/DenseStorage.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Diagonal.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/DiagonalMatrix.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/DiagonalProduct.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Dot.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/EigenBase.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ForceAlignedAccess.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Fuzzy.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/GeneralProduct.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/GenericPacketMath.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/GlobalFunctions.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/IO.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/IndexedView.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/InternalHeaderCheck.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Inverse.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Map.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/MapBase.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/MathFunctions.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/MathFunctionsImpl.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Matrix.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/MatrixBase.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/NestByValue.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/NoAlias.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/NumTraits.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/PartialReduxEvaluator.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/PermutationMatrix.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/PlainObjectBase.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Product.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ProductEvaluators.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Random.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Redux.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Ref.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Replicate.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Reshaped.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/ReturnByValue.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Reverse.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Select.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/SelfAdjointView.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/SelfCwiseBinaryOp.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/SkewSymmetricMatrix3.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Solve.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/SolveTriangular.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/SolverBase.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/StableNorm.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/StlIterators.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Stride.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Swap.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Transpose.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Transpositions.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/TriangularMatrix.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/VectorBlock.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/VectorwiseOp.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/Visitor.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX/Complex.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX/MathFunctions.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX/PacketMath.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX/TypeCasting.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/Complex.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/GemmKernel.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/MathFunctions.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/PacketMath.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/PacketMathFP16.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/TrsmKernel.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AVX512/TypeCasting.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/Complex.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MathFunctions.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProduct.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductCommon.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductMMA.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductMMAbfloat16.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixVectorProduct.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/AltiVec/PacketMath.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/BFloat16.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/ConjHelper.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/Half.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/Settings.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/Default/TypeCasting.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/GPU/Complex.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/GPU/MathFunctions.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/GPU/PacketMath.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/GPU/Tuple.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/GPU/TypeCasting.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/HIP/hcc/math_constants.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/MSA/Complex.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/MSA/MathFunctions.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/MSA/PacketMath.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/Complex.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/GeneralBlockPanelKernel.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/MathFunctions.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/PacketMath.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/TypeCasting.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/NEON/UnaryFunctors.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SSE/Complex.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SSE/MathFunctions.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SSE/PacketMath.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SSE/TypeCasting.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SVE/MathFunctions.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SVE/PacketMath.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SVE/TypeCasting.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SYCL/InteropHeaders.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SYCL/MathFunctions.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SYCL/PacketMath.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SYCL/SyclMemoryModel.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/SYCL/TypeCasting.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/ZVector/Complex.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/ZVector/MathFunctions.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/arch/ZVector/PacketMath.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/AssignmentFunctors.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/BinaryFunctors.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/NullaryFunctors.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/StlFunctors.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/TernaryFunctors.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/functors/UnaryFunctors.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralBlockPanelKernel.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrix.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixVector.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/Parallelizer.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixVector.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointProduct.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/SelfadjointRank2Update.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixMatrix.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixVector.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularSolverMatrix.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/products/TriangularSolverVector.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Assert.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/BlasUtil.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/ConfigureVectorization.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Constants.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/DisableStupidWarnings.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/ForwardDeclarations.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/IndexedViewHelper.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/IntegralConstant.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/MKL_support.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Macros.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Memory.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Meta.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/ReenableStupidWarnings.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/ReshapedHelper.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/Serializer.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/StaticAssert.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/SymbolicIndex.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/Core/util/XprHelper.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/ArrayCwiseBinaryOps.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/ArrayCwiseUnaryOps.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/BlockMethods.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/CommonCwiseBinaryOps.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/CommonCwiseUnaryOps.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/IndexedViewMethods.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/InternalHeaderCheck.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/MatrixCwiseBinaryOps.h +0 -0
- {ml_dtypes-0.3.1 → ml_dtypes-0.4.0}/third_party/eigen/Eigen/src/plugins/MatrixCwiseUnaryOps.h +0 -0
- {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
|
+
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__ =
|
|
15
|
+
__version__ = "0.4.0" # Keep in sync with pyproject.toml:version
|
|
16
16
|
__all__ = [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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"
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
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(
|
|
633
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
866
|
-
|
|
867
|
-
//
|
|
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
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
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
|
-
|
|
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(
|
|
986
|
-
|
|
987
|
-
|
|
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/
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 (!
|
|
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
|
-
//
|
|
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
|
-
|
|
283
|
-
|
|
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>();
|