# Isapprox documentation has argument norm, but call signature does not?

**URL:** <https://discourse.julialang.org/t/isapprox-documentation-has-argument-norm-but-call-signature-does-not/31072>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 14, 2019, 5:14am UTC](https://discourse.julialang.org/t/isapprox-documentation-has-argument-norm-but-call-signature-does-not/31072 "2019-11-14T05:14:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jtg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jtg/32/8551_2.png) [@jtg](https://discourse.julialang.org/u/jtg)\
**Post date:** [November 14, 2019, 5:14am UTC](https://discourse.julialang.org/t/isapprox-documentation-has-argument-norm-but-call-signature-does-not/31072/1 "2019-11-14T05:14:18Z")

</div>

I noticed this trying to extend the function. I am using:

```julia
 Julia Version 1.3.0-rc4.1
Commit 8c4656b97a (2019-10-15 14:08 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.6.0)
  CPU: Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 4

```

first post, so be kind 😉

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [November 14, 2019, 5:50am UTC](https://discourse.julialang.org/t/isapprox-documentation-has-argument-norm-but-call-signature-does-not/31072/2 "2019-11-14T05:50:02Z")

</div>

```julia
julia> methods(isapprox)
# 9 methods for generic function "isapprox":
[1] isapprox(::Missing, ::Missing; kwargs...) in Base at missing.jl:89
[2] isapprox(::Missing, ::Any; kwargs...) in Base at missing.jl:90
[3] isapprox(::Any, ::Missing; kwargs...) in Base at missing.jl:91
[4] isapprox(x::Number, y::Number; atol, rtol, nans) in Base at floatfuncs.jl:274
[5] isapprox(x::AbstractArray, y::AbstractArray; atol, rtol, nans, norm) in LinearAlgebra at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\LinearAlgebra\src\generic.jl:1522
[6] isapprox(J1::LinearAlgebra.UniformScaling{T}, J2::LinearAlgebra.UniformScaling{S}; atol, rtol, nans) where {T<:Number, S<:Number} in LinearAlgebra at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\LinearAlgebra\src\uniformscaling.jl:253
[7] isapprox(J::LinearAlgebra.UniformScaling, A::AbstractArray{T,2} where T; atol, rtol, nans, norm) in LinearAlgebra at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\LinearAlgebra\src\uniformscaling.jl:259
[8] isapprox(A::AbstractArray{T,2} where T, J::LinearAlgebra.UniformScaling; kwargs...) in LinearAlgebra at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.3\LinearAlgebra\src\uniformscaling.jl:265
[9] isapprox(c1::D, c2::D) where D<:DiscreteNonParametric in Distributions at C:\Users\andre\.julia\packages\Distributions\wRw5p\src\univariate\discrete\discretenonparametric.jl:66

```

hi!, maybe it’s because is a keyword argument? and keywords don’t participate in dispatch. but it works anyway. for example:

```julia
x = rand(5)
y = rand(5)
mynorm(x) = length(x) - 5 #not a real norm, but if the length of (y-x) is 5, then they are equal
isapprox(x,y,norm=mynorm) #returns true

```

---

<div class="post-metadata">

**Author:** ![jtg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jtg/32/8551_2.png) [@jtg](https://discourse.julialang.org/u/jtg)\
**Post date:** [November 14, 2019, 9:17am UTC](https://discourse.julialang.org/t/isapprox-documentation-has-argument-norm-but-call-signature-does-not/31072/3 "2019-11-14T09:17:56Z")

</div>

> [@longemen3000](#):
>
> x = rand(5) y = rand(5) mynorm(x) = length(x) - 5 #not a real norm, but if the length of (y-x) is 5, then they are equal isapprox(x,y,norm=mynorm) #returns true

Thanks.

There is no norm option if the entries are Numbers. I have a composite data type that contained a Number and several Arrays. I need to pass the “norm” option on when computing the Array parts and not when computing the scalar part. This is clear from method list item [4] in the isapprox methods.

```julia
x = rand(1)
y = rand(1)
mynorm(x) = length(x) - 5 #not a real norm, but if the length of (y-x) is 5, then they are equal
isapprox(x,y,norm=mynorm)

```

Works

But

```julia
mynorm(x) = length(x) - 5 #a real norm, but if the length of (y-x) is 5, then they are equal
isapprox(1, 1,norm=mynorm)

```

Yields

```julia
ERROR: MethodError: no method matching isapprox(::Int64, ::Int64; norm=mynorm)
Closest candidates are:
  isapprox(::Number, ::Number; atol, rtol, nans) at floatfuncs.jl:274 got unsupported keyword argument "norm"

```

The Array parts fall into methods list item [5] and so they can use it.

I can actually see a use for the norm on Numbers, but it’s sufficiently weird that it is not a worry at least for now.

Rookie error. Your post helped me see it. Thanks!

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 14, 2019, 11:05am UTC](https://discourse.julialang.org/t/isapprox-documentation-has-argument-norm-but-call-signature-does-not/31072/4 "2019-11-14T11:05:46Z")

</div>

> [@jtg](#):
>
> I can actually see a use for the norm on Numbers, but it’s sufficiently weird that it is not a worry at least for now.

I think that the docstring of `isapprox` is a bit misleading, since not all methods support all keyword arguments. Perhaps it should be broken up into relevant parts for each method.

That said, I think that specifying a custom norm, especially in tests, is often more convoluted than just calculating the discrepancy I care about directly.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 18, 2019, 2:09am UTC](https://discourse.julialang.org/t/isapprox-documentation-has-argument-norm-but-call-signature-does-not/31072/5 "2019-11-18T02:09:41Z")

</div>

Alternatively, the call signatures could be made more uniform. The norm option isn’t terribly useful for scalars, but why not support it?

---

<div class="post-metadata">

**Author:** ![jtg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jtg/32/8551_2.png) [@jtg](https://discourse.julialang.org/u/jtg)\
**Post date:** [November 21, 2019, 11:01pm UTC](https://discourse.julialang.org/t/isapprox-documentation-has-argument-norm-but-call-signature-does-not/31072/6 "2019-11-21T23:01:17Z")

</div>

I noticed it because I wanted to use it.

Contrived:  
Where scalars are part of a larger structure, think unit quaternions, with a scalar part and a vector part. In such a case the scalar norm might be part of a larger computation, and the most convenient thing might be a different scalar norm.

If I’m trying to optimize an attitude maneuver (a rotation), I want a partial order (semi-norm), on the size of the angle. The scalar part of a unit quaternion is \cos \frac{\theta}{2}, when the unit quaternion is representing a rotation. So I would want to take the \arccos and compare \theta’s not \cos \frac{\theta}{2}’s.

N.B. There are better ways to do this - I indicated it’s contrived.

Of course, scalar norm in the usual case should be blazingly fast. But that’s why Julia is compiled.

I hope this helps.
