-
Notifications
You must be signed in to change notification settings - Fork 123
Genericize function arguments #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Genericize function arguments #291
Conversation
bf09b58 to
d2c67ef
Compare
| /// - ``ones(_:type:stream:)`` | ||
| static public func zeros( | ||
| _ shape: [Int], dtype: DType = .float32, stream: StreamOrDevice = .default | ||
| _ shape: some Collection<Int>, dtype: DType, stream: StreamOrDevice = .default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder how this wasn't ambiguous before? Maybe it was and it just picked one (since they have the same defaults)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know either, I've come across with this issue a lot when I genericized my codebases. Maybe due to some type-checker quirks.
I think removing these default arguments won't break the call sites. We might, however, bikeshed on whether to remove these from type: or dtype:.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it will break callers, but we can try it out with mlx-swift-examples and see if anything shows up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tested the current branch with mlx-swift-examples and everything built cleanly.
7c306ae to
1ef6091
Compare
- replaced the use of concrete arrays with Collection and Sequence, when applicable - replaced the use of existentials with generics - removed the default arguments for `dtype:` to resolve the ambiguities arisen after the changes
1ef6091 to
b03d202
Compare
|
One unintended consequence of this PR is it has broken a lot of docc function hashes... |
fixes #286
The blast radius was larger than I expected, I ended up implementing the following changes:
some Collectionandsome Sequence, whenever applicableSome type checking ambiguities arose after the changes, I have to do the following to break ties:
dtype:from functions which have atype: T.Type = <default>overloadI've avoided overridable methods to maintain source compatibility