-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: Add array repeat
and scan
ops
#1633
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1633 +/- ##
==========================================
+ Coverage 85.51% 85.59% +0.07%
==========================================
Files 136 136
Lines 25264 25463 +199
Branches 22176 22375 +199
==========================================
+ Hits 21605 21794 +189
- Misses 2455 2462 +7
- Partials 1204 1207 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -179,6 +184,10 @@ impl MakeOpDef for ArrayOpDef { | |||
fn description(&self) -> String { | |||
match self { | |||
ArrayOpDef::new_array => "Create a new array from elements", | |||
ArrayOpDef::new_uninitialized_array => { | |||
"Create a new array with uninitialised elements. \ | |||
Reading such an unitialised element is undefined behaviour." |
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.
Do we really want to have undefined behaviour in hugr? Perhaps it should panic instead (though that would require storing a "poison" value I suppose).
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.
I think guaranteeing a panic would be too much overhead. An alternative would be to pass a default value to the op and renaming it to array_repeat
or something like that.
For linear arrays, this default would need to be provided via a function that is called for each element
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.
Yeah that could work. May add some runtime overhead (constructing values that are then replaced), but at least some of that could be eliminated by compiler optimizations.
repeat
and scan
ops
"scan": { | ||
"extension": "prelude", | ||
"name": "scan", | ||
"description": "A combination of map and foldl. Applies a function to each element of the array with an accumulator that is passed trough from left to right. Returns the resulting array and the final state of the accumulator.", |
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.
"description": "A combination of map and foldl. Applies a function to each element of the array with an accumulator that is passed trough from left to right. Returns the resulting array and the final state of the accumulator.", | |
"description": "A combination of map and foldl. Applies a function to each element of the array with an accumulator that is passed through from start to finish. Returns the resulting array and the final state of the accumulator.", |
"scan": { | ||
"extension": "prelude", | ||
"name": "scan", | ||
"description": "A combination of map and foldl. Applies a function to each element of the array with an accumulator that is passed trough from left to right. Returns the resulting array and the final state of the accumulator.", |
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.
"description": "A combination of map and foldl. Applies a function to each element of the array with an accumulator that is passed trough from left to right. Returns the resulting array and the final state of the accumulator.", | |
"description": "A combination of map and foldl. Applies a function to each element of the array with an accumulator that is passed through from start to finish. Returns the resulting array and the final state of the accumulator.", |
of the array with an accumulator that is passed trough from left to \ | ||
right. Returns the resulting array and the final state of the \ |
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.
of the array with an accumulator that is passed trough from left to \ | |
right. Returns the resulting array and the final state of the \ | |
of the array with an accumulator that is passed through from start to \ | |
finish. Returns the resulting array and the final state of the \ |
.into() | ||
} | ||
|
||
/// Add an operation implemented as an [MakeOpDef], which can provide the data |
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.
/// Add an operation implemented as an [MakeOpDef], which can provide the data | |
/// Add an operation implemented as a [MakeOpDef], which can provide the data |
/// required to define an [OpDef], to an extension. | ||
// | ||
// This method is re-defined here since we need to pass the array type def while | ||
// computing the signature, to avoid recursive loops initializing the extension. |
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.
// computing the signature, to avoid recursive loops initializing the extension. | |
// computing the signature, to avoid recursive loops initializing the extension. |
/// The target element type of the output array. | ||
tgt_ty: Type, | ||
/// The accumulator types. | ||
acc_tys: Vec<Type>, |
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.
It's not clear to me why this is a vector of types and not just a type -- isn't the accumulator a single type?
Closes #1627