Repository navigation
test: cover linalg, random, factory, dtype, parameter types and ArrayAt - #42
Merged
Merged
Conversation
The job summary now shows one table with Lines, Regions and Functions for all of Source/MLX* and for MLX, MLXNN and MLXOptimizers, each against the 80% target. The target is reported only. The text under the table names what is not measured: the Cmlx core and the targets that the test bundle does not link. The step reads each value from the TOTAL row by its column name and fails when a value is missing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MLXFast, MLXFFT, MLXLinalg and MLXRandom are deprecated shims that forward to APIs in Source/MLX. Those APIs are counted in the Source/MLX row, so the text no longer reads as if FFT, linalg and random were unmeasured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add six test files for code in Source/MLX that had low line coverage: - LinalgCoverageTests: each norm overload with hand values, and qr, svd, inv, triInv, cholesky, choleskyInv, pinv, cross, lu, lu_factor, solve, solveTriangular, eig, eigvals, eigh and eigvalsh. The tests rebuild the input from the factors or compare with values worked out by hand. - RandomCoverageTests: each sampler and its free function, with seeded determinism, shape, dtype, range and moment checks. - FactoryCoverageTests: each MLXArray factory and free factory, with exact values and dtypes. - DTypeCoverageTests: DType properties, finfo, Codable, each asMLXArray conversion, toArrays and the MLX promotion table. - ParameterTypesCoverageTests: each init and literal form of IntOrPair, IntOrTriple, IntOrArray and FloatOrArray. - ArrayAtCoverageTests: each .at[...] update compared with a Swift loop, with repeated indices. Three tests find defects. They wrap only the failing assertions in XCTExpectFailure: - Linalg.swift:717: the free triInv does not pass `upper` on. - DType.swift:204: bfloat16 smallestSubnormal is the smallest normal. - DType.swift:137-205: complex64 finfo uses float64 limits, not float32. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 1, 2026
MLX does not allow float64 on the GPU, so the float64 cases stopped the test process. Make the arrays and the add on the CPU stream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Inside an XCTestCase, add(...) refers to the XCTestCase method. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The GPU computes linspace in float32, so some values differ from whole numbers by one or two ulp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 2, 2026
Gajesh2007
approved these changes
Oct 2, 2026
Gajesh2007
left a comment
Member
There was a problem hiding this comment.
Reviewed test-only diff at head 7252fbf and additive fork.yaml resolution. Normal signed main integration preserves all previously landed tests and CI. Runtime Source is unchanged; original dtype/linalg test blobs and all three known-defect XCTExpectFailure markers are preserved while #43/#44 remain unmerged. User authorizes merging with new CI pending.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
This PR adds tests only. It does not change library code.
Coverage on the base (run 36587565184) was low for six files in
Source/MLX:Linalg.swift31.5%,Random.swift53.1%,Factory.swift43.2%,DType.swift50.8%,ParameterTypes.swift14.6%,ArrayAt.swift25.0%. This PR adds six new test files inTests/MLXTests:LinalgCoverageTests(22 tests): eachnormoverload against hand values (vector orders 0, 1, 2, 3, inf, -inf; matrix orders fro, nuc, 1, -1, 2, -2, inf, -inf;axis,axes,IntOrArrayandkeepDimsforms; the error forfro/nucwith one axis). The factorizations rebuild the input: QR (Q*R == A,Qorthonormal,Rupper triangular), SVD (U*diag(S)*Vt == A), Cholesky (L*L^T == A),inv(A*inv == I),triInv,choleskyInv,pinv,lu(L[P]*U == A),lu_factor,solve,solveTriangular,eig,eigvals,eighandeigvalsh(A*v == v*w, andUPLOreads only one triangle), andcross. Both theMLXLinalgfunctions and the free functions are called.RandomCoverageTests(20 tests): each sampler, asMLXRandomfunction and free function:seed,key,split,uniform,normal,multivariateNormal,permutation,randInt,bernoulli,truncatedNormal,gumbel,categorical,laplace. Each test checks seeded determinism, shape, dtype and range, and the mean and variance of 4000 samples with a wide tolerance.FactoryCoverageTests(10 tests): eachMLXArrayfactory and free factory (zeros,ones,eye,identity,full,linspace,arange,repeated,tri) with exact values and dtypes.DTypeCoverageTests(17 tests): theDTypeproperties for all 14 cases,finfo,Codable, eachasMLXArrayconversion,toArrays, and the MLX promotion table (mlx/dtype.cpp,promote_types) through binary operations.ParameterTypesCoverageTests(4 tests): each init and literal form ofIntOrPair,IntOrTriple,IntOrArrayandFloatOrArray.ArrayAtCoverageTests(10 tests): each.at[...]update (add,subtract,multiply,divide,minimum,maximum) against a Swift loop, with repeated indices; index, slice, strided slice, two-index and full-slice forms; the sequence subscript and thestream:label.The linalg factorizations run only on the CPU in MLX, so those tests pass
stream: .cpu.Defects found
Three tests find library defects. Each test keeps the assertion and wraps only the failing assertions in
XCTExpectFailure:Source/MLX/Linalg.swift:717: the free functiontriInv(_:upper:stream:)does not passupperon toMLXLinalg.triInv, so it always reads the lower triangle. Fix: fix(linalg): pass upper on in the free triInv function #43.Source/MLX/DType.swift:137-205:finfogives complex64 the float64 limits. MLX (mlx/utils.cpp,finfo::finfo) gives complex64 the float32 limits. Fix: fix(dtype): use float32 finfo for complex64 and fix bfloat16 subnormal #44.Source/MLX/DType.swift:204: the bfloat16smallestSubnormalis the smallest normal (2^-126). The doc comment defines the smallest subnormal, which is 2^-133. Fix: fix(dtype): use float32 finfo for complex64 and fix bfloat16 subnormal #44.The fix PRs merge before this PR. Before this PR merges, remove the wrappers (see the checklist below).
fork.yaml: the Tests section text now names the new test files.Before this PR merges: remove the wrappers
The fix PRs (#43 and #44) merge first. The wrappers stay on this branch until then, because the fixes are not on its base. After the fixes have merged, merge
maininto this branch (no rebase), do the steps below, wait for Fork Tests, and then merge this PR. XCTest reports an unexpected pass insideXCTExpectFailureas a failure, so this PR must not merge with the wrappers after the fixes are onmain. Line numbers are at headf97466d. In each step, remove theXCTExpectFailure(...) {line and its closing}, keep the assertions inside, and delete the "Defect" comment above it.Tests/MLXTests/LinalgCoverageTests.swift:257-259,testTriangularInverse: remove the wrapperXCTExpectFailure("Linalg.swift:717 free triInv drops the upper argument"), and the Defect comment at lines 254-256. Fixed by fix(linalg): pass upper on in the free triInv function #43.Tests/MLXTests/DTypeCoverageTests.swift:107-109,testFInfoBFloat16: remove the wrapperXCTExpectFailure("DType.swift:204 bfloat16 smallestSubnormal is the smallest normal"), and the Defect comment at lines 103-106. Fixed by fix(dtype): use float32 finfo for complex64 and fix bfloat16 subnormal #44.Tests/MLXTests/DTypeCoverageTests.swift:120-126,testFInfoComplex64: remove the wrapperXCTExpectFailure("DType.swift:137-205 complex64 finfo uses float64 limits"), and the Defect comment at lines 118-119. Fixed by fix(dtype): use float32 finfo for complex64 and fix bfloat16 subnormal #44.Base and merge order. This PR is based on
ci/coverage-scope(#35). It merges after #35. It does not depend on #36-#38 or on the sibling coverage PRs (#41 and others). If a sibling test PR merges first, the only overlap is the text at the end of the Tests section infork.yaml. Keep both lines.Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes (ranswift format format --in-place --configuration .swift-formaton the changed files)fork.yaml;check_forkdiff.pypasses)🤖 Generated with Claude Code