Skip to content

Conversation

@ppaleja
Copy link

@ppaleja ppaleja commented Nov 21, 2025

First time contributor, appreciate any feedback! Work in progress on feature req from #1255.

Proposed changes

  • python/C++ api for mlx.core.searchsorted (caveats: basic logic on cpu using binary search).
  • Tests for searchsorted added to test_ops

In Progress:

[ ] Add functionality for axis parameter for parity with np.searchsorted (documentation has it currently)
[ ] Run benchmarks
[ ] (not optimized) Implement vectorized linear search vs non-vectorized binary search
[ ] implement eval_gpu.

Checklist

Put an x in the boxes that apply.

  • 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
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

Introduces a comprehensive Product Requirements Document for the new mlx.searchsorted feature, outlining API parity with NumPy, multi-dimensional support, axis-based operations, and GPU-accelerated implementation plans. Documents goals, functional/spec requirements, testing strategies, documentation plans, release notes, risks, and implementation phases. References the related issue ml-explore#1255.
Introduces a comprehensive test suite for the searchsorted operation, validating correctness across multiple dimensions, dtypes (int, float, half precision), and sides, including:
- Basic 1D behavior and dtype compatibility
- Handling of duplicates and edge cases (empty, single element, all duplicates)
- Multidimensional inputs with various axes and broadcasting rules
- Special values (inf, -inf, NaN) and out-of-range scenarios
- Output shape and dtype correctness for scalar, vector, and 2D value inputs
- Mixed precision scenarios to ensure robust type handling
- Large input arrays for performance/behavior checks
Introduces a .clangd configuration to enhance editor tooling and code quality.

- Enables strict diagnostic checks (UnusedIncludes, MissingIncludes) and enables Clang-Tidy with tailored rule sets.
- Configures compilation database and background indexing to speed up tooling feedback.
- Enables inlay hints (parameter names, deduced types) and hover improvements for better readability.
- Activates comprehensive completion across all scopes and improves developer experience with AKA hover support.
Drops unused header dependencies:
- removes transforms.h from the operations module
- removes backend/utils.h from primitives
Introduces a local numpy-based reference implementation for searchsorted that supports axis and broadcasting, intended to validate the multi-dimensional behavior against the library. Updates test expectations for scalar input on 2D arrays. Temporarily comments out extensive multi-dimensional test cases pending full parity, but leaves the groundwork for future validation and comparison.
Improves code hygiene by:
- Wrapping a long `set` command in `CMakeLists.txt` for better readability.
- Removing trailing whitespace in `test_ops.py`.
- Standardizing string literal quotes (single to double) in `test_ops.py`.
- Converting whitespace-only lines to truly empty lines.
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.

1 participant