Skip to content

Conversation

barronalex
Copy link
Contributor

Update mlx-c to 0.1.2 and mlx to 0.23.1

I added a few of the new methods:

MLXLinalg.lu
MLXLinalg.lu_factor
MLXLinalg.solve
MLXLinalg.solve_triangular
flatten
unflatten
kron

@barronalex barronalex requested a review from davidkoski March 20, 2025 18:47
@davidkoski
Copy link
Collaborator

See also #206 -- I wasn't done with it but I set up a PR with what I have. This may go together

Co-authored-by: DavidKoski <46639364+davidkoski@users.noreply.github.com>
public convenience init<T: HasDType>(_ value: T) {
let floatMax = Double(Float.greatestFiniteMagnitude)
let doubleValue = value as? Double
if doubleValue != nil && doubleValue! < floatMax && doubleValue! > -floatMax {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea here is to convert a scalar to float64 only if it lies outside the range representable for float32. We could also just always cast to float32 and let the user do MLXArray(0.1, dtype: .float64) if they want a float64.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This might be better as init(_ value: Double) -- otherwise this logic is use for bools, ints, etc. It should still work, but I think specializing it to Double expresses the intent better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good I'll change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I remembered why I put it here:
When you initialize a MLXArray from a range e.g. in

let a = MLXRandom.uniform(0.0 ..< 1.0, [4, 10, 12, 4])

You're redirected to this initialization rather than init(_ value: Double).
Do you know if there's a better way to overload in that case as well?

Copy link
Collaborator

@davidkoski davidkoski left a comment

Choose a reason for hiding this comment

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

Changes look good, thank you!

@barronalex barronalex merged commit 8f7ce77 into main Mar 24, 2025
@barronalex barronalex deleted the update-mlx-c-0.1.2 branch March 24, 2025 19:46
@davidkoski davidkoski mentioned this pull request Mar 24, 2025
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