-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Add prim::EnumName and prim::EnumValue ops #41965
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1595,6 +1595,21 @@ Node* Graph::createTupleSlice(Value* tup, int64_t beg, int64_t end) { | |
| return n; | ||
| } | ||
|
|
||
| Node* Graph::createEnumName(Value* e) { | ||
|
||
| e->type()->expect<EnumType>(); | ||
| assert(e->type()->cast<EnumType>()); | ||
|
||
| auto n = create(prim::EnumName, {e}); | ||
| n->output()->setType(StringType::get()); | ||
| return n; | ||
| } | ||
|
|
||
| Node* Graph::createEnumValue(Value* e) { | ||
| auto enum_type = e->type()->expect<EnumType>(); | ||
| auto n = create(prim::EnumValue, {e}); | ||
| n->output()->setType(enum_type->getValueType()); | ||
| return n; | ||
| } | ||
|
|
||
| Node* Graph::createList(const TypePtr& elem_type, at::ArrayRef<Value*> values) { | ||
| auto n = create(prim::ListConstruct, values); | ||
| for (const auto& v : values) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -311,6 +311,34 @@ RegisterOperators reg( | |
| pack(stack, t.sizes().vec()); | ||
| }, | ||
| aliasAnalysisFromSchema()), | ||
| Operator( | ||
| "prim::EnumName(AnyEnumType enum) -> str", | ||
| [](Stack* stack) { | ||
| IValue e = pop(stack); | ||
| push(stack, e.toEnumHolder()->name()); | ||
| }, | ||
| aliasAnalysisFromSchema()), | ||
| Operator( | ||
| "prim::EnumValue.int(AnyEnumType enum) -> int", | ||
|
||
| [](Stack* stack) { | ||
| IValue e = pop(stack); | ||
| push(stack, e.toEnumHolder()->value()); | ||
| }, | ||
| aliasAnalysisFromSchema()), | ||
| Operator( | ||
| "prim::EnumValue.float(AnyEnumType enum) -> float", | ||
| [](Stack* stack) { | ||
| IValue e = pop(stack); | ||
| push(stack, e.toEnumHolder()->value()); | ||
| }, | ||
| aliasAnalysisFromSchema()), | ||
| Operator( | ||
| "prim::EnumValue.str(AnyEnumType enum) -> str", | ||
| [](Stack* stack) { | ||
| IValue e = pop(stack); | ||
| push(stack, e.toEnumHolder()->value()); | ||
| }, | ||
| aliasAnalysisFromSchema()), | ||
| Operator( | ||
| // note the compiler knows to type TupleIndex more accurately than it | ||
| // is listed here. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not including bool as a type here, but we are registering a kernel for it