-
Notifications
You must be signed in to change notification settings - Fork 308
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
Implement arithmetic ops on more combinations of types #744
Open
jturner314
wants to merge
2
commits into
rust-ndarray:master
Choose a base branch
from
jturner314:more-ops
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -607,18 +607,18 @@ pub type Ixs = isize; | |
/// | ||
/// ### Binary Operators with Two Arrays | ||
/// | ||
/// Let `A` be an array or view of any kind. Let `B` be an array | ||
/// Let `A` be an array or view of any kind. Let `O` be an array | ||
/// with owned storage (either `Array` or `ArcArray`). | ||
/// Let `C` be an array with mutable data (either `Array`, `ArcArray` | ||
/// or `ArrayViewMut`). | ||
/// Let `M` be an array with mutable data (either `Array`, `ArcArray` | ||
/// or `ArrayViewMut`). Let `V` be an `ArrayView`. | ||
/// The following combinations of operands | ||
/// are supported for an arbitrary binary operator denoted by `@` (it can be | ||
/// `+`, `-`, `*`, `/` and so on). | ||
/// | ||
/// - `&A @ &A` which produces a new `Array` | ||
/// - `B @ A` which consumes `B`, updates it with the result, and returns it | ||
/// - `B @ &A` which consumes `B`, updates it with the result, and returns it | ||
/// - `C @= &A` which performs an arithmetic operation in place | ||
/// - `&A @ &A`, `&A @ V`, `V @ &A`, or `V @ V` which produce a new `Array` | ||
/// - `O @ A` which consumes `O`, updates it with the result, and returns it | ||
/// - `O @ &A` which consumes `O`, updates it with the result, and returns it | ||
/// - `M @= &A` or `M @= A` which performs an arithmetic operation in place on `M` | ||
/// | ||
/// Note that the element type needs to implement the operator trait and the | ||
/// `Clone` trait. | ||
|
@@ -646,18 +646,19 @@ pub type Ixs = isize; | |
/// are supported (scalar can be on either the left or right side, but | ||
/// `ScalarOperand` docs has the detailed condtions). | ||
/// | ||
/// - `&A @ K` or `K @ &A` which produces a new `Array` | ||
/// - `B @ K` or `K @ B` which consumes `B`, updates it with the result and returns it | ||
/// - `C @= K` which performs an arithmetic operation in place | ||
/// - `&A @ K`, `V @ K`, `K @ &A`, or `K @ V` which produces a new `Array` | ||
/// - `O @ K` or `K @ O` which consumes `O`, updates it with the result and returns it | ||
/// - `M @= K` which performs an arithmetic operation in place | ||
/// | ||
/// ### Unary Operators | ||
/// | ||
/// Let `A` be an array or view of any kind. Let `B` be an array with owned | ||
/// storage (either `Array` or `ArcArray`). The following operands are supported | ||
/// for an arbitrary unary operator denoted by `@` (it can be `-` or `!`). | ||
/// Let `A` be an array or view of any kind. Let `O` be an array with owned | ||
/// storage (either `Array` or `ArcArray`). Let `V` be an `ArrayView`. The | ||
/// following operands are supported for an arbitrary unary operator denoted by | ||
/// `@` (it can be `-` or `!`). | ||
/// | ||
/// - `@&A` which produces a new `Array` | ||
/// - `@B` which consumes `B`, updates it with the result, and returns it | ||
/// - `@&A` or `@V` which produces a new `Array` | ||
/// - `@O` which consumes `O`, updates it with the result, and returns it | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for updating this, even if it's a draft PR or whatever, it makes it easy to discuss changes 🙂 |
||
/// | ||
/// ## Broadcasting | ||
/// | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not important, but just something I saw. Allegedly this doc is not visible in rustdoc, but that comment may be outdated now(!). then we want that
#[doc=$doc]
back to make a complete sentence.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 would especially discourage these impl blocks. We have to spend a lot of impl blocks on the arithmetic ops with scalars on the left hand side. Part of me want to just remove everything with left hand side scalars, because it can never(?) be properly general because of how we need to express it as an
impl .. for $scalar
(for a specific single 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.
I've removed this impl block in the most recent commit because it's not necessary.
I understand the objection, and AFAIK it will never be possible to write these impls for generic scalars even after re_rebalance_coherence. However, IMO supporting left-hand-side scalars is important, even if it's just
f32
/f64
. I use these impls all the time in my code. They are especially important for non-commutative ops, where it's not straightforward to just move the scalar to the other side.