Skip to content
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

Reshape: what if |newShape| is a scalar number #452

Closed
zolkis opened this issue Aug 21, 2023 · 6 comments
Closed

Reshape: what if |newShape| is a scalar number #452

zolkis opened this issue Aug 21, 2023 · 6 comments

Comments

@zolkis
Copy link
Collaborator

zolkis commented Aug 21, 2023

Originally posted by @BruceDai in #446 (comment)

Currently the spec only defines newShape as a sequence of {{nullable}} {{unsigned long}} -- how about creating a separate PR where |newShape| can also be a scalar [=number=], then Spec editors and more reviewers can easily review it and give feedbacks.

@inexorabletash
Copy link
Member

Just to make sure I'm following along, this proposes:

    partial interface MLGraphBuilder {
-     MLOperand reshape(MLOperand input, sequence<unsigned long> newShape);
+     MLOperand reshape(MLOperand input, (unsigned long or sequence<unsigned long>) newShape);
    };

And the behavior of builder.reshape(op, 123); is equivalent to builder.reshape(op, [123]); ?

@huningxin
Copy link
Contributor

And the behavior of builder.reshape(op, 123); is equivalent to builder.reshape(op, [123]); ?

It seems confusing. I am not aware any examples to use scalar number to represent shape. @BruceDai , could you please clarify your proposal?

@wacky6
Copy link

wacky6 commented Mar 23, 2024

I'm not aware of models that make use of scalar shape.

What is the semantic difference between shape = 123 vs shape = (123) ?

Torch and Numpy seems to treat reshape(scalar) as if it's reshape([scalar]). The scalar invocation looks like a syntax sugar?

>>> np.random.rand(1,3,4,4).reshape(48).shape
(48,)   // <- The returned shape is a sequence of integers

>>> torch.rand((1,3,4,4)).reshape(48).shape
torch.Size([48])      // <- The returned shape is a sequence of integers

@zolkis
Copy link
Collaborator Author

zolkis commented Mar 25, 2024

@BruceDai PTAL: I wonder whether after #476 is this still an issue.

@BruceDai
Copy link
Contributor

@BruceDai , could you please clarify your proposal?

Actually this proposal was from @zolkis's #446.

@BruceDai PTAL: I wonder whether after #476 is this still an issue.

In #476, it removed the step for |newShape| being a scalar,

- If |newShape| is a scalar [=number=], set |outputShape| to the [=/list=] « 1 ».

so current the declarations of |newShape| match below algorithm steps.

@zolkis
Copy link
Collaborator Author

zolkis commented Mar 26, 2024

Thanks @BruceDai , then this can be closed.

@zolkis zolkis closed this as completed Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants