deprecate factory methods that have an implicit Float/.float32 type#391
deprecate factory methods that have an implicit Float/.float32 type#391davidkoski wants to merge 2 commits intomainfrom
Conversation
- fix #390 specifically this logically deprecates functions like this: static public func ones( _ shape: some Collection<Int>, type: (some HasDType).Type = Float.self, stream: StreamOrDevice = .default ) -> MLXArray { MLX.ones(shape, type: type, stream: stream) } calling with no type will get a deprecation warning
|
@DePasqualeOrg -- nice, your doc checker already caught one! |
| /// - ``ones(_:type:stream:)`` | ||
| static public func zeros( | ||
| _ shape: some Collection<Int>, type: (some HasDType).Type = Float.self, | ||
| _ shape: some Collection<Int>, type: (some HasDType).Type, |
There was a problem hiding this comment.
Here is the pattern: remove the default value. Now type: is required, which is a breaking change.
| static public func zeros( | ||
| _ shape: some Collection<Int>, | ||
| stream: StreamOrDevice = .default | ||
| ) -> MLXArray { |
There was a problem hiding this comment.
Add a no type: variant that is deprecated. Code that would have used the zeros() with no type now resolves to this and gets a deprecation warning.
| _ stop: T, stream: StreamOrDevice = .default | ||
| ) -> MLXArray { | ||
| MLX.arange(stop, stream: stream) | ||
| } |
There was a problem hiding this comment.
Adding variants that will infer the integer dtype, e.g. Int16
| /// ### See Also | ||
| /// - <doc:initialization> | ||
| /// - ``arange(_:dtype:stream:)-(Double,_,_)`` | ||
| static public func arange<T: HasDType & BinaryFloatingPoint>( |
There was a problem hiding this comment.
Note that Double already has an implementation and produces .float32
| stream: StreamOrDevice = .default | ||
| ) -> MLXArray { | ||
| zeros(shape, type: Float.self, stream: stream) | ||
| } |
There was a problem hiding this comment.
Free function variants.
| let a = MLXArray.ones([2, 6, 6, 6]) | ||
| let b = MLXArray.zeros([3, 4, 4, 4]) | ||
| let a = MLXArray.ones([2, 6, 6, 6], type: Float.self) | ||
| let b = MLXArray.zeros([3, 4, 4, 4], type: Float.self) |
There was a problem hiding this comment.
Update to use the non deprecated forms
| XCTAssertEqual(c.shape, [0]) | ||
| } | ||
|
|
||
| func testArangeDTypeInference() { |
There was a problem hiding this comment.
Verify the type inference works as expected
wait just a sec... not sure we want this
specifically this logically deprecates functions like this:
calling with no type will get a deprecation warning
Proposed changes
Please include a description of the problem or feature this PR is addressing. If there is a corresponding issue, include the issue #.
Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes