Open jfhc opened 9 years ago
Simpler replication
plot(x=[0, 2.0, 3.0], y=Real[0,0.1,3.1], Geom.line)
InexactError()
in setindex! at /home/juser/.julia/v0.3/DataArrays/src/indexing.jl:189
in apply_scale_typed! at /home/juser/.julia/v0.3/Gadfly/src/scale.jl:282
in apply_scale at /home/juser/.julia/v0.3/Gadfly/src/scale.jl:244
in apply_scales at /home/juser/.julia/v0.3/Gadfly/src/scale.jl:38
in apply_scales at /home/juser/.julia/v0.3/Gadfly/src/scale.jl:58
in render at /home/juser/.julia/v0.3/Gadfly/src/Gadfly.jl:650
in writemime at /home/juser/.julia/v0.3/Gadfly/src/Gadfly.jl:804
in sprint at iostream.jl:229
in display_dict at /home/juser/.julia/v0.3/IJulia/src/execute_request.jl:31
The input array is an abstract type Real
. The first element is an Int
, but the subsequent elements are Float64
. map
actually has found a tight bound, but that confuses Gadfly. Gadfly should probably have a fallback conversion of Number
to Float
.
@jfhc The Hx
function that you have written is not type stable. If you write it as follows, that makes it type stable. This will improve performance of any code that calls Hx
, and will make Gadfly plot the result properly.
function Hx(Ph)
return Ph == 0 || Ph == 1 ? 0.0 : -1 * ((Ph * log2(Ph)) + ((1-Ph) * log2(1-Ph)))
end
This is the code that gave me the problem:
Giving rise to this error:
Changing the plot to
Fixes it fine (i.e. converting the y values to Float32).
This was in iJulia on JuliaBox running Julia v0.3.5.