Skip to content

Add Cast-like operator#3558

Merged
askhade merged 10 commits intoonnx:masterfrom
gramalingam:cast-like
Jul 14, 2021
Merged

Add Cast-like operator#3558
askhade merged 10 commits intoonnx:masterfrom
gramalingam:cast-like

Conversation

@gramalingam
Copy link
Copy Markdown
Contributor

Signed-off-by: Ganesan Ramalingam grama@microsoft.com

Description
Introduces an operator CastLike(X,Y) that casts X to the same type as Y.

Motivation and Context
A common use-case in the definition of function-bodies is to produce a constant, like 0.5 or 1, of the same type/precision as an input Y. This enables such functionality (without requiring the use of a type-context and a context-dependent-function). This will also be useful in defining similar functions that are stored in a model (aka model-local functions).

Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
@gramalingam gramalingam requested review from a team as code owners July 6, 2021 23:54
Copy link
Copy Markdown
Member

@jcwchen jcwchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that TestCoverage.md needs to be updated as well

Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Comment thread onnx/defs/tensor/defs.cc
Comment thread onnx/defs/tensor/defs.cc
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
inputs=['input', 'like'],
outputs=['output'],
)
if input_type and output_type:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand why would these 2 be None?

Copy link
Copy Markdown
Contributor Author

@gramalingam gramalingam Jul 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied it from Cast. My guess is that minor adjustments were needed for types like bfloat16 because of the numpy doesn't support this type, so the numpy values have a different type from the intended type (so, the call to expect is different here, and the intended-type is explicitly mentioned).

@askhade askhade added this to the 1.10 milestone Jul 12, 2021
@gramalingam gramalingam added the topic: operator Issues related to ONNX operators label Jul 12, 2021
@askhade askhade merged commit e7c8edc into onnx:master Jul 14, 2021
@gramalingam gramalingam deleted the cast-like branch April 14, 2022 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: operator Issues related to ONNX operators

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants