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

The input of triangular should be at least 2D tensor #494

Closed
BruceDai opened this issue Dec 19, 2023 · 2 comments · Fixed by #550
Closed

The input of triangular should be at least 2D tensor #494

BruceDai opened this issue Dec 19, 2023 · 2 comments · Fixed by #550

Comments

@BruceDai
Copy link
Contributor

This is raised by @fdwr on reviewing implementation for triangular op on webmachinelearning/webnn-baseline#64. (Thanks Dwayne!)

it should say the input is at least 2D. You can see other ML libraries just treat each 2D subsection as a separate batch:

https://numpy.org/doc/stable/reference/generated/numpy.triu.html
https://pytorch.org/docs/stable/generated/torch.tril.html
https://onnx.ai/onnx/operators/onnx__Trilu.html

So shape [4,3,5,7] would apply the triangular masking to the last two dimensions.

@fdwr
Copy link
Collaborator

fdwr commented Dec 19, 2023

...

  Arguments:
- input: an [MLOperand](https://www.w3.org/TR/webnn/#mloperand). The input 2-D tensor.
+ input: an [MLOperand](https://www.w3.org/TR/webnn/#mloperand). The input tensor which is at least 2D.

   options: an optional [MLTriangularOptions](https://www.w3.org/TR/webnn/#dictdef-mltriangularoptions). The optional parameters of the operation.

- Returns: an [MLOperand](https://www.w3.org/TR/webnn/#mloperand). The output 2-D tensor representing a triangular matrix.
+ Returns: an [MLOperand](https://www.w3.org/TR/webnn/#mloperand). The output tensor representing a triangular matrix which is the same shape as the input.

...

+ // lower triangular matrix with two batches:
+ //   [[[7, 0, 0],
+ //     [9, 4, 0],
+ //     [2, 6, 3]],
+ //    [[1, 0, 0],
+ //     [4, 5, 0],
+ //     [7, 8, 9]]]
+ const lower = builder.triangular(input, { upper: false });

@BruceDai
Copy link
Contributor Author

Thanks @fdwr !
I think you can create a PR for this!

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

Successfully merging a pull request may close this issue.

3 participants