Skip to content

Commit f7ea6b2

Browse files
authored
Fix the rescale function that was still testing against nothing instead of isnan() (#1959)
1 parent 76bc8cf commit f7ea6b2

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/utils.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ function rescale(A::AbstractArray; low=0.0, up=1.0, inputmin=NaN, inputmax=NaN,
775775
sc *= _tmax
776776
low *= _tmax
777777
if (have_nans)
778-
if (inputmin === nothing && inputmax === nothing) # Faster case. No IFs in loop
778+
if (isnan(inputmin) && isnan(inputmax))
779779
if (type == UInt8)
780780
@inbounds for k = 1:numel(A) isnan(A[k]) && (o[k] = 0; continue); o[k] = round(UInt8, low + (A[k] -_inmin) * sc) end
781781
else
@@ -789,7 +789,7 @@ function rescale(A::AbstractArray; low=0.0, up=1.0, inputmin=NaN, inputmax=NaN,
789789
end
790790
end
791791
else
792-
if (inputmin === nothing && inputmax === nothing) # Faster case. No IFs in loop
792+
if (isnan(inputmin) && isnan(inputmax))
793793
if (type == UInt8)
794794
@inbounds for k = 1:numel(A) o[k] = round(UInt8, low + (A[k] -_inmin) * sc) end
795795
else
@@ -807,7 +807,7 @@ function rescale(A::AbstractArray; low=0.0, up=1.0, inputmin=NaN, inputmax=NaN,
807807
oType = (eltype(A) <: AbstractFloat) ? eltype(A) : Float64
808808
o = Array{oType}(undef, size(A))
809809
if (oType <: Integer && have_nans) # Shitty case
810-
if (inputmin === nothing && inputmax === nothing) # Faster case. No IFs in loop
810+
if (isnan(inputmin) && isnan(inputmax)) # Faster case.
811811
@inbounds for k = 1:numel(A) isnan(A[k]) && (o[k] = 0; continue); o[k] = low + (A[k] -_inmin) * sc end
812812
else
813813
@inbounds for k = 1:numel(A)
@@ -816,7 +816,7 @@ function rescale(A::AbstractArray; low=0.0, up=1.0, inputmin=NaN, inputmax=NaN,
816816
end
817817
end
818818
else
819-
if (inputmin === nothing && inputmax === nothing) # Faster case. No IFs in loop
819+
if (isnan(inputmin) && isnan(inputmax)) # Faster case. No IFs in loop
820820
@inbounds for k = 1:numel(A) o[k] = low + (A[k] -_inmin) * sc end
821821
else
822822
@inbounds for k = 1:numel(A)

test/test_common_opts.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@
242242
img16 = rand(UInt16, 16, 16, 3);
243243
I = GMT.mat2img(img16);
244244
img16 = rand(UInt16, 8, 8, 3);
245-
I = GMT.GMTimage("", "", 0, -1, [1.,4,1,4,0,255], [1., 1], 1, NaN32, "", String[], String[], collect(1.:4),collect(1.:4),zeros(3),img16, vec(zeros(Int32,1,3)), String[], 0, Array{UInt8,2}(undef,1,1), "TCBa", 0)
245+
I = GMT.GMTimage("", "", 0, -1, [1.,4,1,4,minimum(img16),maximum(img16)], [1., 1], 1, NaN32, "", String[], String[], collect(1.:4),collect(1.:4),zeros(3),img16, vec(zeros(Int32,1,3)), String[], 0, Array{UInt8,2}(undef,1,1), "TCBa", 0)
246246
imagesc(I);
247247
GMT.mat2img(I);
248248
GMT.mat2img(img16, histo_bounds=8440);

0 commit comments

Comments
 (0)