Repository navigation
test: cover the ops free functions, operators and methods - #41
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 OpsCoverageTests (Source/MLX/Ops.swift) and MLXArrayOpsCoverageTests (Source/MLX/Ops+Array.swift and Source/MLX/MLXArray+Ops.swift). Each test calls the free function, the operator overloads with a scalar on each side and the method forms on small arrays. It compares shape, dtype and values with values computed by hand or by plain Swift loops. Four tests find defects in the Swift wrappers. Their failing assertions are wrapped in XCTExpectFailure: - convolve .same with an even kernel of size 4 or more pads the right side with padLeft / 2 - 1, not padLeft - 1 (Ops.swift:1006). - median(_:keepDims:) passes no axes, so MLX raises an error (Ops.swift:2032). - roll(_:shift:axes:) passes one shift value for more than one axis, so MLX raises an error (Ops.swift:2595). - nanToNum defaults posInf and negInf to 0, not to the largest finite value that its doc comment gives (Ops.swift:2102). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 1, 2026
XCTestCase has an add(_:) method, which hides the free function. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
4 tasks done
The sum of squared deviations of the 8 values in testStd and testVariance is 5.5, not 3.5. The GPU pow gives 8.999998 for 3 ** 2, so the pow checks now use a relative tolerance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 1, 2026
Gajesh2007
approved these changes
Oct 2, 2026
Gajesh2007
left a comment
Member
There was a problem hiding this comment.
Reviewed test-only scope at head f95c382. Signed main integration preserves all fork.yaml topic entries, all four known-defect XCTExpectFailure markers, and the full original test blobs. No runtime Source changes or inherited CI regressions. New composed CI is pending; user explicitly authorizes proceeding without waiting.
jonathan308
added a commit
that referenced
this pull request
Oct 26, 2026
The PR branch moved on GitHub after this refresh started: 3832c0d pins Source/Cmlx/mlx to d11238f1 (Layr-Labs/mlx#41), the core that keeps precompiled MLX builds on 32 x 32 steel tiles. Merging it makes this branch a fast-forward of the published head. The merge is clean, and the gitlink moves 2e16455f -> d11238f1. The forward merge of #56 and the restitch to the merged #41 core (which contains d11238f1) follow. Tests: run on the restitch commit that follows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308
added a commit
that referenced
this pull request
Oct 26, 2026
…anch (#61) Brings #56's forward merge of the restitched #54 and #56's own restitch commit 3e1fc78 forward, so that this branch contains its base again. Conflicts, resolved to this branch's side. The restitch commit that follows sets this layer's pins and regenerates from them: - Source/Cmlx/mlx (gitlink): kept d11238f1, this branch's #41 pin. #56 has its own core, 2b5253ad. - fork.yaml, "Submodule pins" paragraph: kept this branch's paragraph. Taken from #56 without conflict: - Source/Cmlx/mlx-c moves 8a50797b -> 73720efb, the merge of mlx-c main into mlx-c#15. This layer pins the same C layer. - The regenerated include-framework headers. Tests: run on the restitch commit that follows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308
added a commit
that referenced
this pull request
Oct 26, 2026
Restitches the nested pins after the merge of main 6959486: - Source/Cmlx/mlx: d11238f1 -> ce21a37d. That is the merge of the refreshed mlx#35 into Layr-Labs/mlx#41, a fast-forward of the published d11238f1, plus the fix of the head-dim split NAX attention's run-time template. Without that fix, the JIT build that mlx-swift uses throws "Unable to build metal library from source" for head-dim 256 and 512 causal or masked prefill on NAX GPUs. - Source/Cmlx/mlx-c: 73720efb (taken from #56), the merge of mlx-c main into mlx-c#15. Regenerated as tools/update-mlx.sh does from those pins: - The mirrored Source/Cmlx/include headers, the embedded JIT and CPU sources and the Xcode project match the regeneration. - The include-framework copies of the core's metal/device.h and utils.h gain #41's steel-tile declarations: thread_qmm_steel_tile, qmm_steel_tile and its minimum-groups setting. - Metal.hpp differs only in its "Autogenerated" line and is kept as it is. fork.yaml's pin paragraph names the merged core and C. Tests (Ultra A, Xcode 27.1, at these pins): - tools/update-mlx.sh regeneration from the two pins matches the tree (Metal.hpp aside, as above). - check-generated-metal-sources.py: pass. - swift build --build-tests: complete. - Fork Tests, all 3 shards of the CI plan, with an AOT mlx.metallib from this core: - XCTest: 853 listed, 849 passed (including HadamardLayerTests and Float16ConstantCastTests), and the 2 permitted skips. - The fresh-process allocation-cap test and both multi-process ring suites passed. - Swift Testing: 749 of 749 passed. - test-shards.py verify: every test ran exactly once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 26, 2026
jonathan308
added a commit
that referenced
this pull request
Oct 27, 2026
Source/Cmlx/mlx -> ea318ee0 (core #41 with main 6bc9de5b merged; its head-dim split JIT fix now reads as main's); mlx-c stays 73720efb. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
davidtai
added a commit
that referenced
this pull request
Oct 27, 2026
Source/Cmlx/mlx moves from ea318ee0 to e637499f, the head of Layr-Labs/mlx#41: the fast fence is updated before the event fence, fenced inputs stay in device memory and take their waits first, a sealed frame over INT_MAX is refused, and the JACCL mesh shares its failure flag across wires and does all_gather offsets in 64 bits. The range changes .cpp files that the package already compiles and headers that it does not mirror (distributed/sealed.h, sealed_stream.h, jaccl/lib). No Metal kernel, JIT source, CPU preamble input or CUDA device file changes, so mlx-generated does not change. The Metal.hpp commit stamp is written only by a cmake run and is left as it is. Source/Cmlx/mlx-c moves from 73720efb to 2ac897e3, the head of Layr-Labs/mlx-c#15. Only comments in mlx/c/distributed_group.h change; both mirrored copies are refreshed as tools/update-mlx.sh and tools/update-mlx-xcodeproj.sh copy them. The other 28 headers are unchanged byte for byte. fork.yaml: the Submodule pins prose names the new pins and fixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Line coverage on the base (run 36587565184) was low for the three op files:
Source/MLX/Ops.swiftSource/MLX/Ops+Array.swiftSource/MLX/MLXArray+Ops.swiftThis PR adds tests only. It does not change library code.
New files:
Tests/MLXTests/OpsCoverageTests.swift(50 tests): the free functions inOps.swift. This includes arithmetic,divmod,addMM,clip,nanToNum, the trigonometric and hyperbolic functions,erfInverse, theis*checks, comparison and logical functions,where/which, the shape functions (atLeast*D,padded,tiled,roll,tril/triu,flatten/unflatten,meshGrid), sort, partition andtop,takeAlong/putAlong,median,std,trace,inner/outer/kron, the threetensordotforms,einsum,blockMaskedMM,gatherMM,segmentedMM, the window functions,softmax, the convolutions (1D, 2D, 3D, general, transposed) andconvolve. The deprecated wrappers (addmm,softMax,gatherMatmul,quantizedMatmul,gatherQuantizedMatmul) are called too.Tests/MLXTests/MLXArrayOpsCoverageTests.swift(26 tests): each operator inMLXArray+Ops.swiftwith every overload (array and array, array and scalar, scalar and array, and the compound assignments), and each free function inOps+Array.swifttogether with itsMLXArraymethod.Each test uses a small array. It checks shape, dtype and values against values computed by hand or by a plain Swift loop (for example, the convolutions,
kron,gatherMMandsegmentedMM). Tolerances are used only where the math is not exact.Defects found
Four tests find defects in the Swift wrappers. The failing assertions are wrapped in
XCTExpectFailure, with a comment that names the defect. Each has its own fix PR, based onmain:Source/MLX/Ops.swift:1006,convolve(_:_:mode:)with.sameand an even kernel: the right pad ismax(0, padLeft / 2 - 1). Python MLX (python/src/ops.cpp) usesmax(0, pad_l - 1). For a kernel of size 4 the output has one element less thanmax(len(a), len(v)). Test:testConvolveSameEvenKernel. Fix: fix(ops): give convolve .same the right length for an even kernel #48.Source/MLX/Ops.swift:2032,median(_:keepDims:): it passes an empty axes list tomlx_median. MLX then raises[flatten] start_axis must be less than or equal to end_axisfor every array with 1 or more dimensions. The doc comment and Pythonmx.median(a)reduce over all axes. Test:testMedianAllAxes. Fix: fix(ops): reduce over all axes in median(_:keepDims:) #49.Source/MLX/Ops.swift:2595,roll(_:shift:axes:): it passes one shift value for all the axes. MLX raises[roll] At least one shift value per axis is requiredwhen there are two or more axes. Pythonmx.roll(a, 1, axis=(0, 1))applies the shift to each axis. Test:testRollMultipleAxes. Fix: fix(ops): pass one shift for each axis in roll(_:shift:axes:) #50.Source/MLX/Ops.swift:2102,nanToNum:posInfandnegInfdefault to0. The doc comment says that when they are not given, the largest finite value is used, as in Python MLX (posinf=None). Test:testNanToNumDefaults. Fix: fix(ops): default nanToNum infinities to the largest finite value #51.The error tests use
withError, so an MLX error becomes a test failure, not a crash. The fix PRs merge before this PR. Before this PR merges, remove the wrappers (see the checklist below).Coverage after this PR (run 36810978852)
Source/MLX/Ops.swiftSource/MLX/Ops+Array.swiftSource/MLX/MLXArray+Ops.swiftThe three files lose 838 missed lines in total.
fork.yaml: the Tests section text now names the new test files.Before this PR merges: remove the wrappers
The fix PRs (#48, #49, #50 and #51) 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 head218abdc. In each step, remove theXCTExpectFailure(...) {line and its closing}, keep the assertions inside, and delete the "Defect" comment above it.Tests/MLXTests/OpsCoverageTests.swift:178-183,testNanToNumDefaults: remove the wrapper ("nanToNum defaults posInf and negInf to 0 ..."), and change the comment at lines 169-172, which describes the defect. Fixed by fix(ops): default nanToNum infinities to the largest finite value #51.Tests/MLXTests/OpsCoverageTests.swift:398-410,testRollMultipleAxes: remove the wrapper ("roll(_:shift:axes:) passes one shift value ..."); keep thedo { try withError ... } catch { XCTFail ... }inside it. Change the comment at lines 393-396. Fixed by fix(ops): pass one shift for each axis in roll(_:shift:axes:) #50.Tests/MLXTests/OpsCoverageTests.swift:579-596,testMedianAllAxes: remove the wrapper ("median(_:keepDims:) passes no axes to mlx_median ..."); keep thedo/catchinside it. Change the comment at lines 574-577. Fixed by fix(ops): reduce over all axes in median(_:keepDims:) #49.Tests/MLXTests/OpsCoverageTests.swift:966-973,testConvolveSameEvenKernel: remove the wrapper ("convolve .same pads the right side ..."). Change the comment at lines 954-958. Fixed by fix(ops): give convolve .same the right length for an even kernel #48.Base and merge order. This PR is based on
ci/coverage-scope(#35). It merges after #35. It does not depend on #36, #37, #38 or the sibling coverage PRs. 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; no diff)fork.yaml;check_forkdiff.pypasses)🤖 Generated with Claude Code