Skip to content

test: cover MLXArray reads, indexing forms, nested structures, eval/grad, memory and errors - #46

Merged
Gajesh2007 merged 4 commits into
mainfrom
test/array-nested-transforms
Oct 2, 2026
Merged

Gajesh2007 merged 4 commits into
mainfrom
test/array-nested-transforms

Conversation

@davidtai

@davidtai davidtai commented Oct 1, 2026

Copy link
Copy Markdown

Proposed changes

Seven files in Source/MLX had low line coverage in run 36587565184: MLXArray.swift (56.2%), MLXArray+Indexing.swift (79.8%), Nested.swift (78.7%), Transforms+Eval.swift (60.5%), Transforms+Grad.swift (42.3%), Memory.swift (55.4%) and ErrorHandler.swift (61.2%). This PR adds tests only. It does not change library code.

New test files in Tests/MLXTests:

  • ArrayAccessorTests.swift: item() for each integer and float dtype and each Swift type (the itemInt, itemUInt, itemFloat and itemDouble paths), reads that convert first, complex item(), shape2/shape3/shape4, dim, strides, both asType overloads, asImaginary/realPart/imaginaryPart, _updateInternal, copyContext, innerState and description.
  • IndexingFormsTests.swift: each subscript form on a [2, 3, 4] array: the deprecated range, axis:, index, axis: and from:to:stride:axis: forms (get and set), the [any MLXArrayIndex] subscript, .newAxis and .ellipsis reads, strided and negative reads, array index reads, and writes with negative indices, .newAxis and strided slices with array indices. Each result is compared with values from plain Swift loops. Also MLXArrayIndexOperation and MLXSlice descriptions and bounds.
  • NestedStructureTests.swift: NestedItem and NestedDictionary: initializers, the unwrapping: subscript, collection indices, unwrap/asDictionary, description, mapValues with a path, reduce, compactMapValues, the two- and three-item mapValues forms for each combination of value, array, dictionary and .none, flatten with a prefix and each unflatten form.
  • EvalGradOverloadTests.swift: eval, asyncEval and checkedEval with arrays, collections, [Any], dictionaries, 3/4/5-tuples, ignored scalars and NestedDictionary; checkedEval that throws MLXError; each grad overload and valueAndGrad with argumentNumbers, checked against hand-computed derivatives.
  • MemoryLimitTests.swift: Snapshot.delta, description (K and M forms), Codable round trip, live snapshot, and the cacheLimit and memoryLimit getters and setters. Each test restores every limit it changes in a defer.
  • ErrorHandlerScopeTests.swift: MLXError, ErrorBox, sync and async withError and withErrorHandler, and the deprecated global handler (its data destructor runs when the handler is replaced). The global handler is reset in a defer.

fork.yaml: the Tests section text now names the new test files.

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, #41 or the other coverage PRs. If a sibling test PR merges first, the only overlap is one line of text at the end of the Tests section in fork.yaml. Keep both lines.

Checklist

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes (ran swift format format --in-place --configuration .swift-format on the changed files; swift format lint is clean)
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed) (fork.yaml; check_forkdiff.py passes)

🤖 Generated with Claude Code

davidtai and others added 3 commits September 29, 2026 09:06
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>
…grad, memory and errors

Add six test files for code that had low coverage:

- ArrayAccessorTests: item() for each dtype, shape tuples, strides, asType,
  complex parts, description.
- IndexingFormsTests: each subscript form (deprecated axis forms, newAxis,
  ellipsis, strides, negative and array indices, setters), compared with
  values from plain Swift loops.
- NestedStructureTests: NestedItem and NestedDictionary map, reduce,
  flatten, unflatten and description.
- EvalGradOverloadTests: eval, asyncEval and checkedEval overloads and the
  grad and valueAndGrad overloads.
- MemoryLimitTests: snapshots and the cache and memory limits. Each test
  restores the limits it changes.
- ErrorHandlerScopeTests: withError, withErrorHandler (sync and async),
  ErrorBox, MLXError and the global handler.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Gajesh2007
Gajesh2007 changed the base branch from ci/coverage-scope to main October 2, 2026 22:46

@Gajesh2007 Gajesh2007 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed test-only scope and additive fork.yaml resolution at head 50272a3. Signed normal main integration retains every previously landed test and the #35 coverage workflow. Runtime Source is unchanged; original utility tests retain global-state restoration. User explicitly authorizes merging without waiting for refreshed pending CI.

@Gajesh2007
Gajesh2007 merged commit c8266bc into main Oct 2, 2026
7 checks passed
@davidtai
davidtai deleted the test/array-nested-transforms branch October 4, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants