From e0b2323f9163b9d92e35db17fe7c96656584e4da Mon Sep 17 00:00:00 2001 From: Mateusz Baran Date: Tue, 7 Nov 2023 21:21:02 +0100 Subject: [PATCH] Some issues with allocation on complex manifolds --- NEWS.md | 6 ++++++ src/groups/general_unitary_groups.jl | 8 ++++++++ src/groups/group.jl | 5 +++-- test/groups/general_unitary_groups.jl | 2 ++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 869178c2f6..ea8b1da059 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.9.5] - 2023-11-dd + +### Changed + +- `identity_element` now returns a complex matrix for unitary group. + ## [0.9.4] - 2023-11-06 ### Added diff --git a/src/groups/general_unitary_groups.jl b/src/groups/general_unitary_groups.jl index 077497c0fd..a280caba26 100644 --- a/src/groups/general_unitary_groups.jl +++ b/src/groups/general_unitary_groups.jl @@ -45,6 +45,14 @@ function allocate_result(M::Rotations, ::typeof(rand), ::Identity{Multiplication return similar(Matrix{Float64}, representation_size(M)...) end +function allocation_promotion_function( + ::GeneralUnitaryMultiplicationGroup{<:Any,ℂ}, + ::typeof(identity_element), + args::Tuple, +) + return complex +end + decorated_manifold(G::GeneralUnitaryMultiplicationGroup) = G.manifold @doc raw""" diff --git a/src/groups/group.jl b/src/groups/group.jl index ed99cf2ab7..9d138b975e 100644 --- a/src/groups/group.jl +++ b/src/groups/group.jl @@ -244,8 +244,9 @@ end @trait_function identity_element!(G::AbstractDecoratorManifold, p) -function allocate_result(G::AbstractDecoratorManifold, ::typeof(identity_element)) - return zeros(representation_size(G)...) +function allocate_result(G::AbstractDecoratorManifold, f::typeof(identity_element)) + apf = allocation_promotion_function(G, f, ()) + return zeros(apf(Float64), representation_size(G)...) end @doc raw""" diff --git a/test/groups/general_unitary_groups.jl b/test/groups/general_unitary_groups.jl index 7168d59651..d681c818bb 100644 --- a/test/groups/general_unitary_groups.jl +++ b/test/groups/general_unitary_groups.jl @@ -89,6 +89,8 @@ include("group_utils.jl") @test manifold_volume(Unitary(3)) ≈ sqrt(3) * 2 * π^6 @test manifold_volume(Unitary(4)) ≈ sqrt(2) * 8 * π^10 / 12 + @test identity_element(U2) isa Matrix{ComplexF64} + for n in [1, 2, 3] Un = Unitary(n) X = zeros(ComplexF64, n, n)