Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbd69e8f

Browse files
committed
Add identity element to TOP
1 parent89b46e2 commitbd69e8f

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

‎src/tags_outer_product.jl‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ end
5858

5959
# integer power. Generic fallbacks use `power_by_squaring`, which assumes type closure under `*`, which is a property that Unitful matrices do not have.
6060
#TODO factorize so that this can be a O(1) operation
61-
function Base.:^(m::TagsOuterProduct{Tuple{TAA1, TAA2}}, pow::Integer)where {TAA1, TAA2}
61+
function Base.:^(m::TagsOuterProduct)
6262
@assert pow>0#TODO generalize for pow <= 0
6363
acc= m
6464
for i=2:pow
@@ -70,18 +70,33 @@ end
7070
"""
7171
Definition 3.5 from Hart Multidimensional Analysis
7272
"""
73-
functionis_endomorphic(m::TagsOuterProduct{Tuple{TAA1, TAA2}})where {TAA1, TAA2}
73+
functionis_endomorphic(m::TagsOuterProduct)
7474
returncanonicalize(m)==canonicalize(m^2)
7575
end
7676

7777
"""
7878
oneleft(x) * x = x
7979
"""
80-
functiononeleft(m::TagsOuterProduct{Tuple{TAA1, TAA2}})where {TAA1, TAA2}
80+
functiononeleft(::TagsOuterProduct{Tuple{TAA1, TAA2}})where {TAA1, TAA2}
81+
return TAA1*dual(TAA1)'
8182
end
8283

8384
"""
8485
x * oneright(x) = x
8586
"""
86-
functiononeright(m::TagsOuterProduct{Tuple{TAA1, TAA2}})where {TAA1, TAA2}
87+
functiononeright(::TagsOuterProduct{Tuple{TAA1, TAA2}})where {TAA1, TAA2}
88+
returndual(TAA2)* TAA2'
89+
end
90+
91+
struct NoCommutativeIdentityElement{E}<:Exception
92+
element::E
93+
end
94+
95+
Base.showerror(io::IO, e::NoCommutativeIdentityElement)=print(io, e.element," does not have an identity element. Try `oneright` or `oneleft`")
96+
97+
function Base.one(m::TagsOuterProduct)
98+
ifcanonicalize(oneright(m))==canonicalize(oneleft(m))
99+
returncanonicalize(oneright(m))
100+
end
101+
throw(NoCommutativeIdentityElement(m))
87102
end

‎test/runtests.jl‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ top2 = TagsOuterProduct(Tuple{taa_UXdot, taa_UXinv})
3333
@testset"TagsOuterProduct"begin
3434
@test top1[1]==u"m"
3535
@test top2[1,1]==u"s^-1"
36+
@testone(top2)* top2== top2
37+
@test top2*one(top2)== top2
3638
end
3739

3840
@testset"outer product construction"begin

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp