Skip to content

Commit 1563ab4

Browse files
authored
remove allocations in hasnumargs (#102)
1 parent b517afc commit 1563ab4

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.5.9"
3+
version = "0.5.10"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/LinearAlgebra/helper.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ promote_rule(::Type{UnsetNumber},::Type{N}) where {N<:Number} = N
3131
promote_rule(::Type{Bool}, ::Type{UnsetNumber}) = Bool
3232

3333
# Test the number of arguments a function takes
34-
hasnumargs(f,k) = applicable(f,zeros(k)...)
35-
34+
hasnumargs(f,k) = k == 1 ? applicable(f, 0.0) : applicable(f, (1.0:k)...)
3635

3736
# fast implementation of isapprox with atol a non-keyword argument in most cases
3837
isapprox_atol(a,b,atol;kwds...) = isapprox(a,b;atol=atol,kwds...)

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ import ApproxFunBase: ∞
3030
@test_throws MethodError ApproxFunBase.real(1,2)
3131
end
3232

33+
@testset "hasnumargs" begin
34+
onearg(x) = x
35+
twoargs(x, y) = x + y
36+
@test ApproxFunBase.hasnumargs(onearg, 1)
37+
@test ApproxFunBase.hasnumargs(twoargs, 2)
38+
end
39+
3340
# TODO: Tensorizer tests
3441
end
3542

0 commit comments

Comments
 (0)