Skip to content

Commit

Permalink
Use more specific DimensionMismatch instead of ArgumentError
Browse files Browse the repository at this point in the history
  • Loading branch information
abhro committed Jun 17, 2024
1 parent 38023ec commit a0b3b5b
Show file tree
Hide file tree
Showing 25 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/altaz2hadec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ altaz2hadec(altaz::Tuple{Real, Real}, lat::Real) = altaz2hadec(altaz..., lat)
function altaz2hadec(alt::AbstractArray{R}, az::AbstractArray{<:Real},
lat::AbstractArray{<:Real}) where {R<:Real}
if !(length(alt) == length(az) == length(lat))
throw(ArgumentError("alt, az, and lat arrays must have the same length"))
throw(DimensionMismatch("alt, az, and lat arrays must have the same length"))
end
typealt = float(R)
ha = similar(alt, typealt)
Expand Down
4 changes: 2 additions & 2 deletions src/bprecess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function bprecess(ra::AbstractArray{R}, dec::AbstractArray{<:Real},
parallax::AbstractArray{<:Real}=zeros(R, length(ra)),
radvel::AbstractArray{<:Real}=zeros(R, length(ra))) where {R<:Real}
if !(length(ra) == length(dec) == size(muradec, 2) == length(parallax) == length(radvel))
throw(ArgumentError(
throw(DimensionMismatch(
"ra, dec, muradec[:,2], parallax, and radvel arrays should be of the same length"))
end
typer = float(R)
Expand All @@ -110,7 +110,7 @@ end
function bprecess(ra::AbstractArray{R}, dec::AbstractArray{D},
epoch::Real=2000.0) where {R<:Real,D<:Real}
if length(ra) != length(dec)
throw(ArgumentError("ra and dec arrays should be of the same length"))
throw(DimensionMismatch("ra and dec arrays should be of the same length"))
end
typer = float(R)
ra1950 = similar(ra, typer)
Expand Down
2 changes: 1 addition & 1 deletion src/co_aberration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ co_aberration(jd::Real, ra::Real, dec::Real, eps::Real=NaN) =
function co_aberration(jd::AbstractVector{R}, ra::AbstractVector{R},
dec::AbstractVector{R}, eps::Real=NaN) where {R<:Real}
if !(length(jd) == length(ra) == length(dec))
throw(ArgumentError("jd, ra and dec vectors should be of the same length"))
throw(DimensionMismatch("jd, ra and dec vectors should be of the same length"))
end
typejd = float(R)
ra_out = similar(ra, typejd)
Expand Down
2 changes: 1 addition & 1 deletion src/co_nutate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ co_nutate(jd::Real, ra::Real, dec::Real) =
function co_nutate(jd::AbstractVector{P}, ra::AbstractVector{<:Real},
dec::AbstractVector{<:Real}) where {P<:Real}
if !(length(jd) == length(ra) == length(dec))
throw(ArgumentError("jd, ra and dec vectors should be of the same length"))
throw(DimensionMismatch("jd, ra and dec vectors should be of the same length"))
end
typejd = float(P)
ra_out = similar(jd, typejd)
Expand Down
2 changes: 1 addition & 1 deletion src/deredd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function deredd(Eby::AbstractArray{E}, by::AbstractArray{<:Real},
m1::AbstractArray{<:Real}, c1::AbstractArray{<:Real},
ub::AbstractArray{<:Real}) where {E<:Real}
if !(length(Eby) == length(by) == length(m1) == length(c1) == length(ub))
throw(ArgumentError("Eby, by, m1, c1, and ub arrays should be of the same length"))
throw(DimensionMismatch("Eby, by, m1, c1, and ub arrays should be of the same length"))
end
typeeby = float(E)
by0 = similar(Eby, typeeby)
Expand Down
2 changes: 1 addition & 1 deletion src/eci2geo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ eci2geo(xyz::Tuple{Real, Real, Real}, jd::Real) =
function eci2geo(x::AbstractArray{X}, y::AbstractArray{<:Real}, z::AbstractArray{<:Real},
jd::AbstractArray{<:Real}) where {X<:Real}
if !(length(x) == length(y) == length(z) == length(jd))
throw(ArgumentError("x, y, z, and jd arrays should be of the same length"))
throw(DimensionMismatch("x, y, z, and jd arrays should be of the same length"))
end
typex = float(X)
lat = similar(x, typex)
Expand Down
2 changes: 1 addition & 1 deletion src/eqpole.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ eqpole(l::Real, b::Real; southpole::Bool=false) =
function eqpole(l::AbstractArray{L}, b::AbstractArray{<:Real};
southpole::Bool=false) where {L<:Real}
if length(l) != length(b)
throw(ArgumentError("l and b arrays should be of the same length"))
throw(DimensionMismatch("l and b arrays should be of the same length"))
end
typel = float(L)
x = similar(l, typel)
Expand Down
2 changes: 1 addition & 1 deletion src/euler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ euler(aibi::Tuple{Real, Real}, select::Integer; FK4::Bool=false, radians::Bool=f
function euler(ai::AbstractVector{R}, bi::AbstractVector{<:Real}, select::Integer;
FK4::Bool=false, radians::Bool=false) where {R<:Real}
if length(ai) != length(bi)
throw(ArgumentError("ai and bi arrays should be of the same length"))
throw(DimensionMismatch("ai and bi arrays should be of the same length"))
end
typeai = float(R)
ai_out = similar(ai, typeai)
Expand Down
2 changes: 1 addition & 1 deletion src/gal_uvw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function gal_uvw(ra::AbstractArray{R}, dec::AbstractArray{<:Real},
lsr::Bool=false) where {R<:Real}
if !(length(ra) == length(dec) == length(pmra) ==
length(pmdec) == length(vrad) == length(plx))
throw(ArgumentError(
throw(DimensionMismatch(
"ra, dec, pmra, pmdec, vrad, and plx arrays must all have the same length"))
end
typer = float(R)
Expand Down
2 changes: 1 addition & 1 deletion src/geo2eci.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function geo2eci(lat::AbstractArray{LA}, long::AbstractArray{<:Real},
alt::AbstractArray{<:Real},
jd::AbstractArray{<:Real}) where {LA<:Real}
if !(length(lat) == length(long) == length(alt) == length(jd))
throw(ArgumentError(
throw(DimensionMismatch(
"lat, long, alt, and jd arrays must have the same length"))
end
typela = float(LA)
Expand Down
4 changes: 2 additions & 2 deletions src/geo2geodetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function geo2geodetic(lat::AbstractArray{LA}, long::AbstractArray{<:Real},
alt::AbstractArray{<:Real},
eq::Real, pol::Real) where {LA<:Real}
if !(length(lat) == length(long) == length(alt))
throw(ArgumentError("lat, long, and alt arrays must have the same length"))
throw(DimensionMismatch("lat, long, and alt arrays must have the same length"))
end
typela = float(LA)
outlat = similar(lat, typela)
Expand All @@ -186,7 +186,7 @@ function geo2geodetic(lat::AbstractArray{LA}, long::AbstractArray{<:Real},
alt::AbstractArray{<:Real},
planet::AbstractString="earth") where {LA<:Real}
if !(length(lat) == length(long) == length(alt))
throw(ArgumentError("lat, long, and alt arrays must have the same length"))
throw(DimensionMismatch("lat, long, and alt arrays must have the same length"))
end
typela = float(LA)
outlat = similar(lat, typela)
Expand Down
2 changes: 1 addition & 1 deletion src/geo2mag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ geo2mag(lat::Real, long::Real, year::Real=Dates.year(Dates.now())) =
function geo2mag(lat::AbstractArray{LA}, long::AbstractArray{<:Real},
year::Real=Dates.year(Dates.now())) where {LA<:Real}
if length(lat) != length(long)
throw(ArgumentError("lat and long arrays should be of the same length"))
throw(DimensionMismatch("lat and long arrays should be of the same length"))
end
typela = float(LA)
maglat = similar(lat, typela)
Expand Down
4 changes: 2 additions & 2 deletions src/geodetic2geo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function geodetic2geo(lat::AbstractArray{LA}, long::AbstractArray{<:Real},
alt::AbstractArray{<:Real}, eq::Real,
pol::Real) where {LA<:Real}
if !(length(lat) == length(long) == length(alt))
throw(ArgumentError("lat, long, and alt arrays must have the same length"))
throw(DimensionMismatch("lat, long, and alt arrays must have the same length"))
end
typela = float(LA)
outlat = similar(lat, typela)
Expand All @@ -154,7 +154,7 @@ function geodetic2geo(lat::AbstractArray{LA},
alt::AbstractArray{<:Real},
planet::AbstractString="earth") where {LA<:Real}
if !(length(lat) == length(long) == length(alt))
throw(ArgumentError("lat, long, and alt arrays must have the same length"))
throw(DimensionMismatch("lat, long, and alt arrays must have the same length"))
end
typela = float(LA)
outlat = similar(lat, typela)
Expand Down
2 changes: 1 addition & 1 deletion src/hadec2altaz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ hadec2altaz(hadec::Tuple{Real, Real}, lat::Real; ws::Bool=false) =
function hadec2altaz(ha::AbstractArray{R}, dec::AbstractArray{<:Real},
lat::AbstractArray{<:Real}; ws::Bool=false) where {R<:Real}
if !(length(ha) == length(dec) == length(lat))
throw(ArgumentError("ha, dec, and lat arrays must have the same length"))
throw(DimensionMismatch("ha, dec, and lat arrays must have the same length"))
end
typeha = float(R)
alt = similar(ha, typeha)
Expand Down
2 changes: 1 addition & 1 deletion src/helio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ helio(jd::Real, num::Integer, radians::Bool=false) =
function helio(jd::AbstractVector{P}, num::AbstractVector{<:Real},
radians::Bool = false) where {P<:Real}
if length(jd) != length(num)
throw(ArgumentError("jd and num vectors should be of the same length"))
throw(DimensionMismatch("jd and num vectors should be of the same length"))
end
typejd = float(P)
hrad_out = similar(jd, typejd)
Expand Down
2 changes: 1 addition & 1 deletion src/imf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function imf(mass::AbstractVector{T}, expon::AbstractVector{T},
mass_range::AbstractVector{T}) where {T<:AbstractFloat}
ne_comp = length(expon)
if length(mass_range) != ne_comp + 1
throw(ArgumentError(
throw(DimensionMismatch(
"Length of array mass_range is not one more than that of expon"))
end
integ = Vector{T}(undef, ne_comp)
Expand Down
4 changes: 2 additions & 2 deletions src/jprecess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function jprecess(ra::AbstractArray{R}, dec::AbstractArray{<:Real},
radvel::AbstractArray{<:Real}=zeros(R, length(ra))) where {R<:Real}
if !(length(ra) == length(dec) == size(muradec)[2] == length(parallax) == length(radvel))
# TODO write more helpful error message
throw(ArgumentError(
throw(DimensionMismatch(
"ra, dec, muradec[:,2], parallax, and radvel must have the same length"))
end
typer = float(R)
Expand All @@ -114,7 +114,7 @@ end
function jprecess(ra::AbstractArray{R}, dec::AbstractArray{<:Real},
epoch::Real=1950.0) where {R<:Real}
if length(ra) != length(dec)
throw(ArgumentError("ra and dec arrays should be of the same length"))
throw(DimensionMismatch("ra and dec arrays should be of the same length"))
end
typer = float(R)
ra2000 = similar(ra, typer)
Expand Down
2 changes: 1 addition & 1 deletion src/mag2geo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mag2geo(lat::Real, long::Real, year::Real=Dates.year(Dates.now())) =
function mag2geo(lat::AbstractArray{LA}, long::AbstractArray{LO},
year::Real=Dates.year(Dates.now())) where {LA<:Real, LO<:Real}
if length(lat) != length(long)
throw(ArgumentError("lat and long arrays should be of the same length"))
throw(DimensionMismatch("lat and long arrays should be of the same length"))
end
typela = float(LA)
geolat = similar(lat, typela)
Expand Down
2 changes: 1 addition & 1 deletion src/planet_coords.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ planet_coords(date::Real, num::Integer) = _planet_coords(float(date), num)
function planet_coords(date::AbstractVector{R},
num::AbstractVector{<:Integer}) where {R<:Real}
if length(date) != length(num)
throw(ArgumentError("date and num arrays should be of the same length"))
throw(DimensionMismatch("date and num arrays should be of the same length"))
end
typedate = float(R)
ra_out = similar(date, typedate)
Expand Down
2 changes: 1 addition & 1 deletion src/polrec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ polrec(r_a::Tuple{Real, Real}; degrees::Bool=false) = polrec(r_a...,
function polrec(r::AbstractArray{R}, a::AbstractArray{A};
degrees::Bool=false) where {R<:Real, A<:Real}
if length(r) != length(a)
throw(ArgumentError("r and a arrays should be of the same length"))
throw(DimensionMismatch("r and a arrays should be of the same length"))
end
typer = float(R)
x = similar(r, typer)
Expand Down
2 changes: 1 addition & 1 deletion src/precess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function precess(ra::AbstractArray{R}, dec::AbstractArray{D}, equinox1::Real,
equinox2::Real; FK4::Bool=false,
radians::Bool=false) where {R<:Real, D<:Real}
if length(ra) != length(dec)
throw(ArgumentError("ra and dec arrays should be of the same length"))
throw(DimensionMismatch("ra and dec arrays should be of the same length"))
end
typera = float(R)
ra_out = similar(ra, typera)
Expand Down
2 changes: 1 addition & 1 deletion src/precess_xyz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function precess_xyz(x::AbstractArray{X}, y::AbstractArray{<:Real},
z::AbstractArray{<:Real}, equinox1::Real,
equinox2::Real) where {X<:Real}
if !(length(x) == length(y) == length(z))
throw(ArgumentError("x, y, z arrays should be of the same length"))
throw(DimensionMismatch("x, y, z arrays should be of the same length"))
end
typex = float(X)
x_out = similar(x, typex)
Expand Down
2 changes: 1 addition & 1 deletion src/radec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ radec(ra::Real, dec::Real; hours::Bool=false) =
function radec(ra::AbstractArray{R}, dec::AbstractArray{D};
hours::Bool=false) where {R<:Real, D<:Real}
if length(ra) != length(dec)
throw(ArgumentError("ra and dec arrays should be of the same length"))
throw(DimensionMismatch("ra and dec arrays should be of the same length"))
end
typera = float(R)
ra_hr = similar(ra, typera)
Expand Down
2 changes: 1 addition & 1 deletion src/recpol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ recpol(xy::Tuple{Real, Real}; degrees::Bool=false) =
function recpol(x::AbstractArray{X}, y::AbstractArray{Y};
degrees::Bool=false) where {X<:Real, Y<:Real}
if length(x) != length(y)
throw(ArgumentError("x and y arrays must have the same length"))
throw(DimensionMismatch("x and y arrays must have the same length"))
end
typex = float(X)
r = similar(x, typex)
Expand Down
2 changes: 1 addition & 1 deletion test/utils-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ end
# correlated with the output from imf routine of IDL AstroLib, with
# differences only in the least significant digits.
@testset "imf" begin
@test_throws ArgumentError @inferred(imf([5], [-6.75], [0.9]))
@test_throws DimensionMismatch @inferred(imf([5], [-6.75], [0.9]))
@test @inferred(imf([0.1, 0.01], [-0.6, -1], [ 0.007, 1.8, 110]))
[0.49627714725007616, 1.9757149090208912]
@test imf.([[3],[5]], [[-1.35], [-0.6, -1.7]], [[0.1, 100], [0.007, 1.8, 110]])
Expand Down

0 comments on commit a0b3b5b

Please sign in to comment.