In that case, defining the general fallback
function isapprox(a, b)
return a == b
end
should be sufficient because it will be called if there is no more
specific method, but it still generates an error.
By way of explanation, because I deal almost exclusively with data
that is the result of floating point math, approximate equality is the
only kind of equality that is important for my tests. The idea behind
the general fallback is to provide more specific methods for the
"inexact" type (Floats etc.) that falls back to exact equality for the
types where exact equality can be achieved.
Jared Crean
On 02/18/2016 09:55 PM, Steven G. Johnson wrote:
It is not enough to define isapprox(string, string). To use isapprox
for [1.5, "foo"] you need an isapprox method for Array{Any}.
However, I would be inclined to say you should re-consider using
isapprox in such cases. (What does it mean for two strings to be
"approximately" equal?)
Note that isapprox on two numeric arrays is *not* the same as
elementwise isapprox. So it's not necessarily a good idea to have a
fallback method isapprox(a::Array, b::Array) = mapreduce(ab ->
isapprox(ab[1], ab[2]), &, true, zip(a,b))