Skip to content

Adding dtype parameter to creation methods like the zeroes_like and ones_like #4001

Closed

Description

@aaishwarymishra

Hi, I have checked that the current implementation of like methods including zeros_like, ones_like and empty_like does not take dtype as parameter unlike non like methods zeros for example.

array zeros_like(const array &a, StreamOrDevice s = {})

I think adding dtype will make them array api compatible, I seemed like an simple addition, but I ran into issue that many internal methods that use them, use positional arguments which breaks the code and need much refactoring.

Similarly with the users there code can be broken too after this addition, a simple work around could be to add it after stream, which can avoid all that.

I just wanted to get your opinion on this before I made any changes.

Activity

  1. changed the title [-]Adding dtype parameter to creation methods like the zeroes_like and one_like[/-] [+]Adding dtype parameter to creation methods like the zeroes_like and ones_like[/+] on Aug 4, 2026
  2. zcbenz commented on Aug 5, 2026

    @zcbenz
    Member

    Sounds a good addition.

  3. JasonHonKL commented on Aug 6, 2026

    @JasonHonKL
    Contributor

    @zcbenz @aaishwarymishra mind if i give this a try as my first issue in MLX ?

  4. reckylurker commented on Aug 6, 2026

    @reckylurker
    Contributor

    @JasonHonKL I was already working on this :(

  5. JasonHonKL commented on Aug 6, 2026

    @JasonHonKL
    Contributor

    Oh no. Then you take it. Is okay !

  6. reckylurker commented on Aug 6, 2026

    @reckylurker
    Contributor

    @aaishwarymishra there's already a full_like function which accepts dtype so just need to create some overloads with dtype argument for zeros_like and ones_like and forward them to full_like appropriately

  7. aaishwarymishra commented on Aug 6, 2026

    @aaishwarymishra
    ContributorAuthor

    @JasonHonKL Hi, you can still help out :)

    There is still empty_like which does not have the dtype, Also I have noticed that empty and empty_like are implemented in the mlx but are not visible in the docs, it can be another area you can look at :)

  8. JasonHonKL commented on Aug 6, 2026

    @JasonHonKL
    Contributor

    Sure I will do it later today !

  9. zcbenz commented on Aug 7, 2026

    @zcbenz
    Member

    Closed by #4028.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions