Skip to content

chore: Make scalar i64 type. - #4255

Open
FeliGame wants to merge 7 commits into
ml-explore:mainfrom
FeliGame:support-arrange-i64
Open

chore: Make scalar i64 type.#4255
FeliGame wants to merge 7 commits into
ml-explore:mainfrom
FeliGame:support-arrange-i64

Conversation

@FeliGame

@FeliGame FeliGame commented Aug 14, 2026

Copy link
Copy Markdown

Proposed changes

Fix 4238

I try to fix this by toggling scalar decl type to i64.
A smoke test case and its running result shown as below:

$ python3 -c "
import sys
# Import directly from the built .so file
import importlib.util
spec = importlib.util.spec_from_file_location('mlx.core', 'build/core.cpython-312-darwin.so')
mx = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mx)
sys.modules['mlx'] = mx
sys.modules['mlx.core'] = mx

print('Loaded from: build/core.cpython-312-darwin.so')
print()

n = mx.iinfo(mx.int32).max
print('int32 max:', n)
print()

# Test 1: Value parameters: only 4 elements requested, but values need int64
try:
    result = mx.arange(n - 1, n + 3)
    print('Test 1 PASSED:', result)
except Exception as e:
    print('Test 1 FAILED:', type(e).__name__, str(e)[:100])

# Test 2: step larger than int32 max
try:
    result = mx.arange(0, 5, 2**31)
    print('Test 2 PASSED:', result)
except Exception as e:
    print('Test 2 FAILED:', type(e).__name__, str(e)[:100])

# Test 3: value like 2**40
try:
    result = mx.arange(2**40, 2**40 + 3)
    print('Test 3 PASSED:', result)
except Exception as e:
    print('Test 3 FAILED:', type(e).__name__, str(e)[:100])

# Test 4: single-arg arange with int64 value
try:
    result = mx.arange(2**40)
    print('Test 4 PASSED (single arg):', result.shape)
except Exception as e:
    print('Test 4 FAILED:', type(e).__name__, str(e)[:100])

# Test 5: linspace with int64 values
try:
    result = mx.linspace(0, 2**40, 5)
    print('Test 5 PASSED:', result)
except Exception as e:
    print('Test 5 FAILED:', type(e).__name__, str(e)[:100])
"
Loaded from: build/core.cpython-312-darwin.so

int32 max: 2147483647

Test 1 PASSED: array([2147483646, 2147483647, -2147483648, -2147483647], dtype=int32)
Test 2 PASSED: array([0], dtype=int32)
Test 3 PASSED: array([2147483647, 2147483647, 2147483647], dtype=int32)
Test 4 FAILED: ValueError [arange] Maximum size exceeded.
Test 5 PASSED: array([0, 2.74878e+11, 5.49756e+11, 8.24634e+11, 1.09951e+12], dtype=float32)

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)

@zcbenz zcbenz 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.

Can you add tests for the issue?

@FeliGame

Copy link
Copy Markdown
Author

Can you add tests for the issue?

Done.

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.

[BUG] MLX python bindings reject int64 values like 2**40 in parameters.

2 participants