I defined a new type (Mod29
– integers mod 29).
struct Mod29 <: Real
value::Int8
function Mod29(value::Integer)
new(Int8(mod(value, 29)))
end
end
In another, generic, algorithm, I need to know whether comparison is defined on a type. I did not define comparison on Mod29
, and indeed Mod29(1) < Mod29(3)
fails:
**julia>** Mod29(1) < Mod29(3)
**ERROR:** < not defined for Mod29
Stacktrace:
[1] **error(** ::String, ::String, ::Type **)** at **./error.jl:42**
[2] **no_op_err(** ::String, ::Type **)** at **./promotion.jl:410**
[3] **<(** ::Mod29, ::Mod29 **)** at **./promotion.jl:426**
[4] top-level scope at **none:0**
But hasmethod(<, (Mod29, Mod29))
and hasmethod(isless, (Mod29, Mod29))
both return true
.
I see that <
and isless
fail trying to do promotion, but I don’t see how to tell that ‘<’ will fail, without trying it and catching the error.
For your amusement, the algorithm I need to change is LU decomposition, where it tries to pivot on the max. If comparison isn’t defined, I just want it to find an element with an inverse, to pivot on. I want to be able to take inverses of matrices of modular numbers.