I am trying to extend Uniform so rand
can generate random numbers for Complex types (to test IntelVectorMath library for Complex types)
# zeros like syntax
function Distributions.Uniform(::Type{T}, a, b) where {T <: Real}
return Uniform(T(a), T(b))
end
# Complex support
function Distributions.Uniform(T::Type{Complex{P}}, a, b) where {P}
aR, aI =reim(T(a))
bR, bI =reim(T(b))
if aR == bR
outR = P(0) #?? Ask about this
else
outR = Uniform(P, min(aR,bR), max(aR,bR))
end
if aI == bI
outI = P(0) #?? Ask about this
else
outI = Uniform(P, min(aI,bI), max(aI,bI))
end
return complex(outR, outI)
end
# doesn't work:
Uniform(Complex{Float64},1,2)
The problem arises when a and b are equal. In literature, the probability is 0. However, in Julia’s implementation, it is not apparent that when we define Unifrom(a,b)
, is it a [a, b]
or (a,b)
.
If it is [a, b]
then Uniform(a, a)
should always give a
if is is (a, b)
then Uniform(a, a)
should give a constant 0 distribution that rand always gives some null situation.
My implementation is faulty, but I can’t find anything in Distributions doc anything about Complex
types. Probably it should be a multi-dimensional distribution.