Skip to content

Commit

Permalink
Merge branch 'main' into kmp5/debug/it_gpu_broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
kmp5VT authored Oct 12, 2024
2 parents c4f014e + 020efa3 commit 6693d70
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion NDTensors/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NDTensors"
uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"
authors = ["Matthew Fishman <[email protected]>"]
version = "0.3.43"
version = "0.3.44"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
2 changes: 0 additions & 2 deletions NDTensors/src/empty/EmptyTensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ end

setindex!!(T::EmptyTensor, x, I...) = setindex(T, x, I...)

promote_rule(::Type{EmptyNumber}, ::Type{T}) where {T<:Number} = T

function promote_rule(
::Type{T1}, ::Type{T2}
) where {T1<:EmptyStorage{EmptyNumber},T2<:TensorStorage}
Expand Down
8 changes: 8 additions & 0 deletions NDTensors/src/emptynumber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ convert(::Type{T}, x::EmptyNumber) where {T<:Number} = T(zero(T))
# This helps with defining `norm` of `EmptyStorage{EmptyNumber}`.
AbstractFloat(::EmptyNumber) = zero(AbstractFloat)

# Extra definitions fix ambiguity errors.
Base.promote_rule(::Type{EmptyNumber}, T::Type{<:Number}) = T
Base.promote_rule(T::Type{<:Number}, ::Type{EmptyNumber}) = T
Base.promote_rule(::Type{EmptyNumber}, ::Type{Bool}) = Bool
Base.promote_rule(::Type{Bool}, ::Type{EmptyNumber}) = Bool
Base.promote_rule(::Type{EmptyNumber}, T::Type{Complex{R}}) where {R<:Real} = T
Base.promote_rule(T::Type{Complex{R}}, ::Type{EmptyNumber}) where {R<:Real} = T

# Basic arithmetic
(::EmptyNumber + ::EmptyNumber) = EmptyNumber()
(::EmptyNumber - ::EmptyNumber) = EmptyNumber()
Expand Down
13 changes: 10 additions & 3 deletions NDTensors/test/test_emptynumber.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
@eval module $(gensym())
using NDTensors
using LinearAlgebra: norm
using NDTensors: EmptyNumber
using Test: @testset, @test, @test_throws

const 𝟎 = NDTensors.EmptyNumber()
const 𝟎 = EmptyNumber()

@testset "NDTensors.EmptyNumber" begin
x = 2.3

@test complex(𝟎) == 𝟎
@test complex(NDTensors.EmptyNumber) == Complex{NDTensors.EmptyNumber}
@test complex(EmptyNumber) == Complex{EmptyNumber}

# Promotion
for T in (Bool, Float32, Float64, Complex{Float32}, Complex{Float64})
@test promote_type(EmptyNumber, T) === T
@test promote_type(T, EmptyNumber) === T
end

# Basic arithmetic
@test 𝟎 + 𝟎 == 𝟎
Expand Down

0 comments on commit 6693d70

Please sign in to comment.