Skip to content

Commit 232326d

Browse files
authored
Merge pull request #42 from JuliaMath/kc/remove_macro
remove overload macro
2 parents 5172a19 + fd8ad75 commit 232326d

File tree

4 files changed

+8
-69
lines changed

4 files changed

+8
-69
lines changed

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
name = "IntelVectorMath"
22
uuid = "c8ce9da6-5d36-5c03-b118-5a70151be7bc"
3-
version = "0.3"
3+
version = "0.3.0"
44

55
[deps]
66
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
77
CpuId = "adafc99b-e345-5852-983c-f28acb93d879"
88
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
9-
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
109

1110
[compat]
1211
BinaryProvider = "0.5.8"
1312
CpuId = "0.2"
14-
SpecialFunctions = "0.8, 0.9, 0.10"
1513
julia = "0.7, 1.0"
1614

1715
[extras]
1816
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
17+
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
18+
1919

2020
[targets]
21-
test = ["Test"]
21+
test = ["Test", "SpecialFunctions"]

src/IntelVectorMath.jl

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export IVM
66
const IVM = IntelVectorMath
77

88
# import Base: .^, ./
9-
using SpecialFunctions
109
# using Libdl
1110
include("../deps/deps.jl")
1211

@@ -104,47 +103,6 @@ for t in (Float32, Float64)
104103
# def_binary_op(Complex{t}, Complex{t}, :multiply_conj, :multiply_conj!, :Mul, false)
105104
end
106105

107-
"""
108-
@overload exp log sin
109-
110-
This macro adds a method to each function in `Base` (or perhaps in `SpecialFunctions`),
111-
so that when acting on an array (or two arrays) it calls the `IntelVectorMath` function of the same name.
112-
113-
The existing action on scalars is unaffected. However, `exp(M::Matrix)` will now mean
114-
element-wise `IntelVectorMath.exp(M) == exp.(M)`, rather than matrix exponentiation.
115-
"""
116-
macro overload(funs...)
117-
out = quote end
118-
say = []
119-
for f in funs
120-
if f in _UNARY
121-
if isdefined(Base, f)
122-
push!(out.args, :( Base.$f(A::Array) = IntelVectorMath.$f(A) ))
123-
push!(say, "Base.$f(A)")
124-
elseif isdefined(SpecialFunctions, f)
125-
push!(out.args, :( IntelVectorMath.SpecialFunctions.$f(A::Array) = IntelVectorMath.$f(A) ))
126-
push!(say, "SpecialFunctions.$f(A)")
127-
else
128-
@error "function IntelVectorMath.$f is not defined in Base or SpecialFunctions, so there is nothing to overload"
129-
end
130-
end
131-
if f in _BINARY
132-
if isdefined(Base, f)
133-
push!(out.args, :( Base.$f(A::Array, B::Array) = IntelVectorMath.$f(A, B) ))
134-
push!(say, "Base.$f(A, B)")
135-
else
136-
@error "function IntelVectorMath.$f is not defined in Base, so there is nothing to overload"
137-
end
138-
end
139-
if !(f in _UNARY) && !(f in _BINARY)
140-
error("there is no function $f defined by IntelVectorMath.jl")
141-
end
142-
end
143-
str = string("Overloaded these functions: \n ", join(say, " \n "))
144-
push!(out.args, str)
145-
esc(out)
146-
end
147-
148-
export VML_LA, VML_HA, VML_EP, vml_set_accuracy, vml_get_accuracy, @overload
106+
export VML_LA, VML_HA, VML_EP, vml_set_accuracy, vml_get_accuracy
149107

150108
end

src/setup.jl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ const VML_LA = VMLAccuracy(0x00000001)
1818
const VML_HA = VMLAccuracy(0x00000002)
1919
const VML_EP = VMLAccuracy(0x00000003)
2020

21-
const _UNARY = [] # for @overload to check
22-
const _BINARY = []
23-
2421
Base.show(io::IO, m::VMLAccuracy) = print(io, m == VML_LA ? "VML_LA" :
2522
m == VML_HA ? "VML_HA" : "VML_EP")
2623
vml_get_mode() = ccall((:_vmlGetMode, libmkl_vml_avx), Cuint, ())
@@ -59,13 +56,12 @@ function vml_prefix(t::DataType)
5956
error("unknown type $t")
6057
end
6158

62-
function def_unary_op(tin, tout, jlname, jlname!, mklname;
59+
function def_unary_op(tin, tout, jlname, jlname!, mklname;
6360
vmltype = tin)
6461
mklfn = Base.Meta.quot(Symbol("$(vml_prefix(vmltype))$mklname"))
6562
exports = Symbol[]
6663
(@isdefined jlname) || push!(exports, jlname)
6764
(@isdefined jlname!) || push!(exports, jlname!)
68-
push!(_UNARY, jlname)
6965
@eval begin
7066
function ($jlname!)(out::Array{$tout,N}, A::Array{$tin,N}) where {N}
7167
size(out) == size(A) || throw(DimensionMismatch())
@@ -97,7 +93,6 @@ function def_binary_op(tin, tout, jlname, jlname!, mklname, broadcast)
9793
exports = Symbol[]
9894
(@isdefined jlname) || push!(exports, jlname)
9995
(@isdefined jlname!) || push!(exports, jlname!)
100-
push!(_BINARY, jlname)
10196
@eval begin
10297
$(isempty(exports) ? nothing : Expr(:export, exports...))
10398
function ($jlname!)(out::Array{$tout,N}, A::Array{$tin,N}, B::Array{$tin,N}) where {N}

test/real.jl

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const fns = [[x[1:2] for x in base_unary_real]; [x[1:2] for x in base_binary_rea
1717
@testset "Definitions and Comparison with Base for Reals" begin
1818

1919
for t in (Float32, Float64), i = 1:length(fns)
20-
inp = input[t][i]
20+
inp = input[t][i]
2121
mod, fn = fns[i]
2222
base_fn = getproperty(mod, fn)
2323
vml_fn = getproperty(IntelVectorMath, fn)
@@ -30,13 +30,12 @@ const fns = [[x[1:2] for x in base_unary_real]; [x[1:2] for x in base_binary_rea
3030
Test.@test vml_fn(inp...) base_fn.(inp...)
3131

3232
# cis changes type (float to complex, does not have mutating function)
33-
3433
if length(inp) == 1
3534
if fn != :cis
3635
vml_fn!(inp[1])
3736
Test.@test inp[1] baseres
3837
end
39-
elseif length(inp) == 2
38+
elseif length(inp) == 2
4039
out = similar(inp[1])
4140
vml_fn!(out, inp...)
4241
Test.@test out baseres
@@ -60,16 +59,3 @@ end
6059
Test.@test vml_get_accuracy() == VML_EP
6160

6261
end
63-
64-
@testset "@overload macro" begin
65-
66-
@test IntelVectorMath.exp([1.0]) exp.([1.0])
67-
@test_throws MethodError Base.exp([1.0])
68-
@test (@overload log exp) isa String
69-
@test Base.exp([1.0]) exp.([1.0])
70-
71-
@test_throws MethodError Base.atan([1.0], [2.0])
72-
@test (@overload atan) isa String
73-
@test Base.atan([1.0], [2.0]) atan.([1.0], [2.0])
74-
75-
end

0 commit comments

Comments
 (0)