ml-dtypes 0.3.0__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.
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/PKG-INFO +7 -1
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/README.md +6 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes/__init__.py +1 -1
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes/_src/common.h +8 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes/_src/custom_float.h +9 -46
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes/_src/dtypes.cc +11 -38
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes/_src/int4_numpy.h +101 -49
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes/_src/numpy.h +1 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes/include/float8.h +82 -72
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes/include/int4.h +97 -47
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes.egg-info/PKG-INFO +7 -1
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes.egg-info/requires.txt +5 -5
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/pyproject.toml +4 -5
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/setup.py +10 -2
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/AUTHORS +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/LICENSE +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/LICENSE.eigen +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/MANIFEST.in +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes/_finfo.py +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes/_iinfo.py +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes/_src/numpy.cc +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes/_src/ufuncs.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes/py.typed +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes.egg-info/SOURCES.txt +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes.egg-info/dependency_links.txt +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/ml_dtypes.egg-info/top_level.txt +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/setup.cfg +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/Core +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/ArithmeticSequence.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Array.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/ArrayBase.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/ArrayWrapper.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Assign.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/AssignEvaluator.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Assign_MKL.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/BandMatrix.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Block.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/CommaInitializer.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/ConditionEstimator.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/CoreEvaluators.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/CoreIterators.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/CwiseBinaryOp.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/CwiseNullaryOp.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/CwiseTernaryOp.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/CwiseUnaryOp.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/CwiseUnaryView.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/DenseBase.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/DenseCoeffsBase.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/DenseStorage.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Diagonal.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/DiagonalMatrix.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/DiagonalProduct.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Dot.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/EigenBase.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/ForceAlignedAccess.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Fuzzy.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/GeneralProduct.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/GenericPacketMath.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/GlobalFunctions.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/IO.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/IndexedView.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/InternalHeaderCheck.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Inverse.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Map.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/MapBase.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/MathFunctions.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/MathFunctionsImpl.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Matrix.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/MatrixBase.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/NestByValue.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/NoAlias.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/NumTraits.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/PartialReduxEvaluator.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/PermutationMatrix.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/PlainObjectBase.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Product.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/ProductEvaluators.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Random.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Redux.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Ref.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Replicate.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Reshaped.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/ReturnByValue.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Reverse.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Select.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/SelfAdjointView.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/SelfCwiseBinaryOp.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/SkewSymmetricMatrix3.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Solve.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/SolveTriangular.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/SolverBase.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/StableNorm.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/StlIterators.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Stride.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Swap.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Transpose.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Transpositions.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/TriangularMatrix.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/VectorBlock.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/VectorwiseOp.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/Visitor.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX/Complex.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX/MathFunctions.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX/PacketMath.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX/TypeCasting.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX512/Complex.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX512/GemmKernel.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX512/MathFunctions.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX512/PacketMath.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX512/PacketMathFP16.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX512/TrsmKernel.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AVX512/TypeCasting.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AltiVec/Complex.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MathFunctions.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProduct.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductCommon.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductMMA.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductMMAbfloat16.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AltiVec/MatrixVectorProduct.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/AltiVec/PacketMath.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/Default/BFloat16.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/Default/ConjHelper.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/Default/Half.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/Default/Settings.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/Default/TypeCasting.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/GPU/Complex.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/GPU/MathFunctions.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/GPU/PacketMath.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/GPU/Tuple.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/GPU/TypeCasting.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/HIP/hcc/math_constants.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/MSA/Complex.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/MSA/MathFunctions.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/MSA/PacketMath.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/NEON/Complex.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/NEON/GeneralBlockPanelKernel.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/NEON/MathFunctions.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/NEON/PacketMath.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/NEON/TypeCasting.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/NEON/UnaryFunctors.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SSE/Complex.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SSE/MathFunctions.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SSE/PacketMath.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SSE/TypeCasting.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SVE/MathFunctions.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SVE/PacketMath.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SVE/TypeCasting.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SYCL/InteropHeaders.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SYCL/MathFunctions.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SYCL/PacketMath.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SYCL/SyclMemoryModel.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/SYCL/TypeCasting.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/ZVector/Complex.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/ZVector/MathFunctions.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/arch/ZVector/PacketMath.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/functors/AssignmentFunctors.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/functors/BinaryFunctors.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/functors/NullaryFunctors.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/functors/StlFunctors.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/functors/TernaryFunctors.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/functors/UnaryFunctors.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/GeneralBlockPanelKernel.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrix.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixVector.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/Parallelizer.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixVector.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/SelfadjointProduct.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/SelfadjointRank2Update.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixMatrix.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixVector.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/TriangularSolverMatrix.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/products/TriangularSolverVector.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/Assert.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/BlasUtil.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/ConfigureVectorization.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/Constants.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/DisableStupidWarnings.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/ForwardDeclarations.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/IndexedViewHelper.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/IntegralConstant.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/MKL_support.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/Macros.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/Memory.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/Meta.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/ReenableStupidWarnings.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/ReshapedHelper.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/Serializer.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/StaticAssert.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/SymbolicIndex.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/Core/util/XprHelper.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/ArrayCwiseBinaryOps.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/ArrayCwiseUnaryOps.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/BlockMethods.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/CommonCwiseBinaryOps.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/CommonCwiseUnaryOps.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/IndexedViewMethods.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/InternalHeaderCheck.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/MatrixCwiseBinaryOps.h +0 -0
- {ml_dtypes-0.3.0 → ml_dtypes-0.3.2}/third_party/eigen/Eigen/src/plugins/MatrixCwiseUnaryOps.h +0 -0
- {ml_dtypes-0.3.0 → 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.
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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>();
|
|
@@ -16,6 +16,9 @@ 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>
|
|
20
|
+
#include <type_traits>
|
|
21
|
+
|
|
19
22
|
// Must be included first
|
|
20
23
|
// clang-format off
|
|
21
24
|
#include "_src/numpy.h"
|
|
@@ -28,6 +31,8 @@ limitations under the License.
|
|
|
28
31
|
|
|
29
32
|
namespace ml_dtypes {
|
|
30
33
|
|
|
34
|
+
constexpr char kOutOfRange[] = "out of range value cannot be converted to int4";
|
|
35
|
+
|
|
31
36
|
template <typename T>
|
|
32
37
|
struct Int4TypeDescriptor {
|
|
33
38
|
static int Dtype() { return npy_type; }
|
|
@@ -51,7 +56,7 @@ int Int4TypeDescriptor<T>::npy_type = NPY_NOTYPE;
|
|
|
51
56
|
template <typename T>
|
|
52
57
|
PyObject* Int4TypeDescriptor<T>::type_ptr = nullptr;
|
|
53
58
|
|
|
54
|
-
// Representation of a Python custom
|
|
59
|
+
// Representation of a Python custom integer object.
|
|
55
60
|
template <typename T>
|
|
56
61
|
struct PyInt4 {
|
|
57
62
|
PyObject_HEAD; // Python object header
|
|
@@ -92,7 +97,7 @@ Safe_PyObjectPtr PyInt4_FromValue(T x) {
|
|
|
92
97
|
return ref;
|
|
93
98
|
}
|
|
94
99
|
|
|
95
|
-
// Converts a Python object to a reduced
|
|
100
|
+
// Converts a Python object to a reduced integer value. Returns true on success,
|
|
96
101
|
// returns false and reports a Python error on failure.
|
|
97
102
|
template <typename T>
|
|
98
103
|
bool CastToInt4(PyObject* arg, T* output) {
|
|
@@ -114,8 +119,7 @@ bool CastToInt4(PyObject* arg, T* output) {
|
|
|
114
119
|
}
|
|
115
120
|
if (d < static_cast<double>(T::lowest()) ||
|
|
116
121
|
d > static_cast<double>(T::highest())) {
|
|
117
|
-
PyErr_SetString(PyExc_OverflowError,
|
|
118
|
-
"out of range value cannot be converted to int4");
|
|
122
|
+
PyErr_SetString(PyExc_OverflowError, kOutOfRange);
|
|
119
123
|
}
|
|
120
124
|
*output = T(d);
|
|
121
125
|
return true;
|
|
@@ -131,9 +135,39 @@ bool CastToInt4(PyObject* arg, T* output) {
|
|
|
131
135
|
if (PyArray_IsScalar(arg, Integer)) {
|
|
132
136
|
int64_t v;
|
|
133
137
|
PyArray_CastScalarToCtype(arg, &v, PyArray_DescrFromType(NPY_INT64));
|
|
138
|
+
|
|
139
|
+
if (!(std::numeric_limits<T>::min() <= v &&
|
|
140
|
+
v <= std::numeric_limits<T>::max())) {
|
|
141
|
+
PyErr_SetString(PyExc_OverflowError, kOutOfRange);
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
134
144
|
*output = T(v);
|
|
135
145
|
return true;
|
|
136
146
|
}
|
|
147
|
+
auto floating_conversion = [&](auto type) -> bool {
|
|
148
|
+
decltype(type) f;
|
|
149
|
+
PyArray_ScalarAsCtype(arg, &f);
|
|
150
|
+
if (!(std::numeric_limits<T>::min() <= f &&
|
|
151
|
+
f <= std::numeric_limits<T>::max())) {
|
|
152
|
+
PyErr_SetString(PyExc_OverflowError, kOutOfRange);
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
*output = T(static_cast<::int8_t>(f));
|
|
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{});
|
|
163
|
+
}
|
|
164
|
+
if (PyArray_IsScalar(arg, Double)) {
|
|
165
|
+
return floating_conversion(double{});
|
|
166
|
+
}
|
|
167
|
+
if (PyArray_IsScalar(arg, LongDouble)) {
|
|
168
|
+
using ld = long double;
|
|
169
|
+
return floating_conversion(ld{});
|
|
170
|
+
}
|
|
137
171
|
return false;
|
|
138
172
|
}
|
|
139
173
|
|
|
@@ -185,14 +219,13 @@ PyObject* PyInt4_tp_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
|
|
|
185
219
|
template <typename T>
|
|
186
220
|
PyObject* PyInt4_nb_float(PyObject* self) {
|
|
187
221
|
T x = PyInt4_Value_Unchecked<T>(self);
|
|
188
|
-
return PyFloat_FromDouble(static_cast<double>(
|
|
222
|
+
return PyFloat_FromDouble(static_cast<double>(x));
|
|
189
223
|
}
|
|
190
224
|
|
|
191
225
|
template <typename T>
|
|
192
226
|
PyObject* PyInt4_nb_int(PyObject* self) {
|
|
193
227
|
T x = PyInt4_Value_Unchecked<T>(self);
|
|
194
|
-
|
|
195
|
-
return PyLong_FromLong(y);
|
|
228
|
+
return PyLong_FromLong(static_cast<long>(x)); // NOLINT
|
|
196
229
|
}
|
|
197
230
|
|
|
198
231
|
template <typename T>
|
|
@@ -365,7 +398,7 @@ PyObject* PyInt4_RichCompare(PyObject* a, PyObject* b, int op) {
|
|
|
365
398
|
PyErr_SetString(PyExc_ValueError, "Invalid op type");
|
|
366
399
|
return nullptr;
|
|
367
400
|
}
|
|
368
|
-
|
|
401
|
+
PyArrayScalar_RETURN_BOOL_FROM_LONG(result);
|
|
369
402
|
}
|
|
370
403
|
|
|
371
404
|
// Numpy support
|
|
@@ -507,12 +540,11 @@ int NPyInt4_CompareFunc(const void* v1, const void* v2, void* arr) {
|
|
|
507
540
|
template <typename T>
|
|
508
541
|
int NPyInt4_ArgMaxFunc(void* data, npy_intp n, npy_intp* max_ind, void* arr) {
|
|
509
542
|
const T* bdata = reinterpret_cast<const T*>(data);
|
|
510
|
-
// Start with a max_val of
|
|
511
|
-
// bdata[0].
|
|
512
|
-
int max_val = std::numeric_limits<int>::
|
|
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();
|
|
513
546
|
for (npy_intp i = 0; i < n; ++i) {
|
|
514
|
-
|
|
515
|
-
if (!(static_cast<int>(bdata[i]) <= max_val)) {
|
|
547
|
+
if (static_cast<int>(bdata[i]) > max_val) {
|
|
516
548
|
max_val = static_cast<int>(bdata[i]);
|
|
517
549
|
*max_ind = i;
|
|
518
550
|
}
|
|
@@ -523,12 +555,11 @@ int NPyInt4_ArgMaxFunc(void* data, npy_intp n, npy_intp* max_ind, void* arr) {
|
|
|
523
555
|
template <typename T>
|
|
524
556
|
int NPyInt4_ArgMinFunc(void* data, npy_intp n, npy_intp* min_ind, void* arr) {
|
|
525
557
|
const T* bdata = reinterpret_cast<const T*>(data);
|
|
526
|
-
int min_val = std::numeric_limits<int>::
|
|
527
|
-
// Start with a min_val of
|
|
528
|
-
// 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].
|
|
529
561
|
for (npy_intp i = 0; i < n; ++i) {
|
|
530
|
-
|
|
531
|
-
if (!(static_cast<int>(bdata[i]) >= min_val)) {
|
|
562
|
+
if (static_cast<int>(bdata[i]) < min_val) {
|
|
532
563
|
min_val = static_cast<int>(bdata[i]);
|
|
533
564
|
*min_ind = i;
|
|
534
565
|
}
|
|
@@ -536,30 +567,21 @@ int NPyInt4_ArgMinFunc(void* data, npy_intp n, npy_intp* min_ind, void* arr) {
|
|
|
536
567
|
return 0;
|
|
537
568
|
}
|
|
538
569
|
|
|
539
|
-
template <typename T
|
|
540
|
-
std::is_same<T, Eigen::half>::value),
|
|
541
|
-
bool> = true>
|
|
570
|
+
template <typename T>
|
|
542
571
|
int CastToInt(T value) {
|
|
543
|
-
if
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
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);
|
|
547
584
|
}
|
|
548
|
-
return static_cast<int>(value);
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
template <typename T, std::enable_if_t<std::is_integral<T>::value, bool> = true>
|
|
552
|
-
int CastToInt(T value) {
|
|
553
|
-
return static_cast<int>(value);
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
int CastToInt(int4 value) { return static_cast<int>(value); }
|
|
557
|
-
|
|
558
|
-
int CastToInt(uint4 value) { return static_cast<int>(value); }
|
|
559
|
-
|
|
560
|
-
template <typename T>
|
|
561
|
-
int CastToInt(std::complex<T> value) {
|
|
562
|
-
return CastToInt(value.real());
|
|
563
585
|
}
|
|
564
586
|
|
|
565
587
|
// Performs a NumPy array cast from type 'From' to 'To'.
|
|
@@ -652,7 +674,45 @@ bool RegisterInt4Casts() {
|
|
|
652
674
|
}
|
|
653
675
|
|
|
654
676
|
// Safe casts from T to other types
|
|
655
|
-
|
|
677
|
+
if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_INT8,
|
|
678
|
+
NPY_NOSCALAR) < 0) {
|
|
679
|
+
return false;
|
|
680
|
+
}
|
|
681
|
+
if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_INT16,
|
|
682
|
+
NPY_NOSCALAR) < 0) {
|
|
683
|
+
return false;
|
|
684
|
+
}
|
|
685
|
+
if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_INT32,
|
|
686
|
+
NPY_NOSCALAR) < 0) {
|
|
687
|
+
return false;
|
|
688
|
+
}
|
|
689
|
+
if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_INT64,
|
|
690
|
+
NPY_NOSCALAR) < 0) {
|
|
691
|
+
return false;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
if (std::is_same_v<uint4, T>) {
|
|
695
|
+
if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_UINT8,
|
|
696
|
+
NPY_NOSCALAR) < 0) {
|
|
697
|
+
return false;
|
|
698
|
+
}
|
|
699
|
+
if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_UINT16,
|
|
700
|
+
NPY_NOSCALAR) < 0) {
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
703
|
+
if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_UINT32,
|
|
704
|
+
NPY_NOSCALAR) < 0) {
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_UINT64,
|
|
708
|
+
NPY_NOSCALAR) < 0) {
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_HALF,
|
|
713
|
+
NPY_NOSCALAR) < 0) {
|
|
714
|
+
return false;
|
|
715
|
+
}
|
|
656
716
|
if (PyArray_RegisterCanCast(&TypeDescriptor<T>::npy_descr, NPY_FLOAT,
|
|
657
717
|
NPY_NOSCALAR) < 0) {
|
|
658
718
|
return false;
|
|
@@ -683,14 +743,6 @@ bool RegisterInt4Casts() {
|
|
|
683
743
|
TypeDescriptor<T>::Dtype(), NPY_NOSCALAR) < 0) {
|
|
684
744
|
return false;
|
|
685
745
|
}
|
|
686
|
-
if (PyArray_RegisterCanCast(PyArray_DescrFromType(NPY_UBYTE),
|
|
687
|
-
TypeDescriptor<T>::Dtype(), NPY_NOSCALAR) < 0) {
|
|
688
|
-
return false;
|
|
689
|
-
}
|
|
690
|
-
if (PyArray_RegisterCanCast(PyArray_DescrFromType(NPY_BYTE),
|
|
691
|
-
TypeDescriptor<T>::Dtype(), NPY_NOSCALAR) < 0) {
|
|
692
|
-
return false;
|
|
693
|
-
}
|
|
694
746
|
|
|
695
747
|
return true;
|
|
696
748
|
}
|