|
| 1 | +macro print_and_throw(args...) |
| 2 | + quote |
| 3 | + @println "ERROR: " $(args...) "." |
| 4 | + throw(nothing) |
| 5 | + end |
| 6 | +end |
| 7 | + |
| 8 | +# math.jl |
| 9 | +@device_override @noinline Base.Math.throw_complex_domainerror(f::Symbol, x) = |
| 10 | + @print_and_throw "This operation requires a complex input to return a complex result" |
| 11 | +@device_override @noinline Base.Math.throw_exp_domainerror(x) = |
| 12 | + @print_and_throw "Exponentiation yielding a complex result requires a complex argument" |
| 13 | + |
| 14 | +# intfuncs.jl |
| 15 | +@device_override @noinline Base.throw_domerr_powbysq(::Any, p) = |
| 16 | + @print_and_throw "Cannot raise an integer to a negative power" |
| 17 | +@device_override @noinline Base.throw_domerr_powbysq(::Integer, p) = |
| 18 | + @print_and_throw "Cannot raise an integer to a negative power" |
| 19 | +@device_override @noinline Base.throw_domerr_powbysq(::AbstractMatrix, p) = |
| 20 | + @print_and_throw "Cannot raise an integer to a negative power" |
| 21 | + |
| 22 | +# checked.jl |
| 23 | +@device_override @noinline Base.Checked.throw_overflowerr_binaryop(op, x, y) = |
| 24 | + @print_and_throw "Binary operation overflowed" |
| 25 | +@device_override @noinline Base.Checked.throw_overflowerr_negation(op, x, y) = |
| 26 | + @print_and_throw "Negation overflowed" |
| 27 | + |
| 28 | +# boot.jl |
| 29 | +@device_override @noinline Core.throw_inexacterror(f::Symbol, ::Type{T}, val) where {T} = |
| 30 | + @print_and_throw "Inexact conversion" |
| 31 | + |
| 32 | +# abstractarray.jl |
| 33 | +@device_override @noinline Base.throw_boundserror(A, I) = |
| 34 | + @print_and_throw "Out-of-bounds array access" |
| 35 | + |
| 36 | +# trig.jl |
| 37 | +@device_override @noinline Base.Math.sincos_domain_error(x) = |
| 38 | + @print_and_throw "sincos(x) is only defined for finite x." |
| 39 | + |
| 40 | +# diagonal.jl |
| 41 | +# XXX: remove when we have malloc |
| 42 | +import LinearAlgebra |
| 43 | +@device_override function Base.setindex!(D::LinearAlgebra.Diagonal, v, i::Int, j::Int) |
| 44 | + @boundscheck checkbounds(D, i, j) |
| 45 | + if i == j |
| 46 | + @inbounds D.diag[i] = v |
| 47 | + elseif !iszero(v) |
| 48 | + @print_and_throw "cannot set off-diagonal entry to a nonzero value" |
| 49 | + end |
| 50 | + return v |
| 51 | +end |
| 52 | + |
| 53 | +# number.jl |
| 54 | +# XXX: remove when we have malloc |
| 55 | +@device_override @inline function Base.getindex(x::Number, I::Integer...) |
| 56 | + @boundscheck all(isone, I) || |
| 57 | + @print_and_throw "Out-of-bounds access of scalar value" |
| 58 | + x |
| 59 | +end |
0 commit comments