-
Notifications
You must be signed in to change notification settings - Fork 1
Define tensor_product
#2
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 2 commits
3ef9e85
4a040e0
2844e5e
3dd63d7
f81bfc8
300ee70
bb8fd82
5782c91
cbbab4c
a407dab
c4c1787
35b2694
dec5a37
4b1881a
50d1a19
0a16571
a9f9bc6
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 | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,14 @@ | ||||||
# This files defines an interface for the tensor product of two axes | ||||||
# https://en.wikipedia.org/wiki/Tensor_product | ||||||
|
||||||
# ================================== misc ================================================ | ||||||
is_offset_axis(a::AbstractUnitRange) = isone(first(a)) | ||||||
|
||||||
function require_one_based_axis(a::AbstractUnitRange) | ||||||
return !is_offset_axis(a) && throw(ArgumentError("Range must be one-based")) | ||||||
end | ||||||
|
||||||
# ============================== tensor product ========================================== | ||||||
⊗() = tensor_product() | ||||||
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. This could also be an alias:
Suggested change
Then you could define methods for either, instead of both 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. This is not compatible with |
||||||
⊗(a) = tensor_product(a) | ||||||
|
||||||
|
@@ -16,9 +24,8 @@ tensor_product(a1, a2, as...) = tensor_product(tensor_product(a1, a2), as...) | |||||
|
||||||
# default | ||||||
function tensor_product(a1::AbstractUnitRange, a2::AbstractUnitRange) | ||||||
!(isone(first(a1)) && isone(first(a2))) && | ||||||
throw(ArgumentError("Ranges must be one-based")) | ||||||
return Base.OneTo(prod(length.((a1, a2)))) | ||||||
require_one_based_axis(a1) || require_one_based_axis(a2) | ||||||
return Base.OneTo(length(a1) * length(a2)) | ||||||
end | ||||||
|
||||||
tensor_product(::OneToOne, ::OneToOne) = OneToOne() |
Uh oh!
There was an error while loading. Please reload this page.