Skip to content

Commit c1fc438

Browse files
authored
Merge pull request #33 from JuliaMath/sf/1.0_compat
Update `AppleAccelerate` for 1.0
2 parents 5f6f591 + ddcca3d commit c1fc438

File tree

7 files changed

+177
-174
lines changed

7 files changed

+177
-174
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: julia
22
os:
33
- osx
44
julia:
5-
- 0.4
5+
- 1.0
66
- nightly
77
notifications:
88
email: false

REQUIRE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
julia 0.4
1+
julia 1.0
2+
DSP

src/Array.jl

Lines changed: 67 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,126 +2,129 @@
22

33
for (T, suff) in ((Float64, ""), (Float32, "f"))
44

5-
# 1 arg functions
6-
for f in (:ceil,:floor,:sqrt,:rsqrt,:rec,
5+
# 1-arg functions
6+
onearg_funcs = (:ceil,:floor,:sqrt,:rsqrt,:rec,
77
:exp,:exp2,:expm1,:log,:log1p,:log2,:log10,
88
:sin,:sinpi,:cos,:cospi,:tan,:tanpi,:asin,:acos,:atan,
99
:sinh,:cosh,:tanh,:asinh,:acosh,:atanh)
10-
f! = symbol("$(f)!")
10+
# Combine this with the list of renamed 1-arg funcs
11+
onearg_funcs = (
12+
((x,x) for x in onearg_funcs)...,
13+
(:trunc,:int),
14+
(:round,:nint),
15+
(:exponent,:logb),
16+
(:abs,:fabs)
17+
)
18+
19+
for (f,fa) in onearg_funcs
20+
f! = Symbol("$(f)!")
1121
@eval begin
22+
# Allocating variant
1223
function ($f)(X::Array{$T})
13-
out = Array($T,size(X))
24+
out = Array{$T}(undef, size(X))
1425
($f!)(out, X)
1526
end
16-
function ($f!)(out::Array{$T}, X::Array{$T})
17-
ccall(($(string("vv",f,suff)),libacc),Void,
18-
(Ptr{$T},Ptr{$T},Ptr{Cint}),out,X,&length(X))
19-
out
20-
end
21-
end
22-
end
2327

24-
# renamed 1 arg functions
25-
for (f,fa) in ((:trunc,:int),(:round,:nint),(:exponent,:logb),
26-
(:abs,:fabs))
27-
f! = symbol("$(f)!")
28-
@eval begin
29-
function ($f)(X::Array{$T})
30-
out = Array($T,size(X))
31-
($f!)(out, X)
32-
end
28+
# In-place mutating variant
3329
function ($f!)(out::Array{$T}, X::Array{$T})
34-
ccall(($(string("vv",fa,suff)),libacc),Void,
35-
(Ptr{$T},Ptr{$T},Ptr{Cint}),out,X,&length(X))
30+
ccall(($(string("vv",fa,suff)),libacc),Cvoid,
31+
(Ptr{$T},Ptr{$T},Ref{Cint}),out,X,length(X))
3632
out
3733
end
3834
end
3935
end
4036

37+
4138
# 2 arg functions
42-
for f in (:copysign,:atan2)
43-
f! = symbol("$(f)!")
39+
twoarg_funcs = (
40+
(:copysign,:copysign),
41+
(:rem,:fmod),
42+
(:div_float,:div),
43+
(:atan,:atan2)
44+
)
45+
46+
for (f, fa) in twoarg_funcs
47+
f! = Symbol("$(f)!")
4448
@eval begin
4549
function ($f)(X::Array{$T}, Y::Array{$T})
4650
size(X) == size(Y) || throw(DimensionMismatch("Arguments must have same shape"))
47-
out = Array($T,size(X))
51+
out = Array{$T}(undef, size(X))
4852
($f!)(out, X, Y)
4953
end
5054
function ($f!)(out::Array{$T}, X::Array{$T}, Y::Array{$T})
51-
ccall(($(string("vv",f,suff)),libacc),Void,
52-
(Ptr{$T},Ptr{$T},Ptr{$T},Ptr{Cint}),out,X,Y,&length(X))
55+
ccall(($(string("vv",fa,suff)),libacc),Cvoid,
56+
(Ptr{$T},Ptr{$T},Ptr{$T},Ref{Cint}),out,X,Y,length(X))
5357
out
5458
end
5559
end
5660
end
5761

5862
# for some bizarre reason, vvpow/vvpowf reverse the order of arguments.
59-
for f in (:pow,)
60-
f! = symbol("$(f)!")
63+
for (f, fa) in ((:pow,:pow),)
64+
f! = Symbol("$(f)!")
6165
@eval begin
6266
function ($f)(X::Array{$T}, Y::Array{$T})
6367
size(X) == size(Y) || throw(DimensionMismatch("Arguments must have same shape"))
64-
out = Array($T,size(X))
68+
out = Array{$T}(undef, size(X))
6569
($f!)(out, X, Y)
6670
end
6771
function ($f!)(out::Array{$T}, X::Array{$T}, Y::Array{$T})
68-
ccall(($(string("vv",f,suff)),libacc),Void,
69-
(Ptr{$T},Ptr{$T},Ptr{$T},Ptr{Cint}),out,Y,X,&length(X))
70-
out
71-
end
72-
end
73-
end
74-
75-
76-
# renamed 2 arg functions
77-
for (f,fa) in ((:rem,:fmod),(:fdiv,:div))
78-
f! = symbol("$(f)!")
79-
@eval begin
80-
function ($f)(X::Array{$T}, Y::Array{$T})
81-
size(X) == size(Y) || throw(DimensionMismatch("Arguments must have same shape"))
82-
out = Array($T,size(X))
83-
($f!)(out, X, Y)
84-
end
85-
function ($f!)(out::Array{$T}, X::Array{$T}, Y::Array{$T})
86-
ccall(($(string("vv",fa,suff)),libacc),Void,
87-
(Ptr{$T},Ptr{$T},Ptr{$T},Ptr{Cint}),out,X,Y,&length(X))
72+
ccall(($(string("vv",fa,suff)),libacc),Cvoid,
73+
(Ptr{$T},Ptr{$T},Ptr{$T},Ref{Cint}),out,Y,X,length(X))
8874
out
8975
end
9076
end
9177
end
9278

9379
# two-arg return
94-
for f in (:sincos,)
95-
f! = symbol("$(f)!")
80+
for (f, fa) in ((:sincos,:sincos),)
81+
f! = Symbol("$(f)!")
9682
@eval begin
9783
function ($f)(X::Array{$T})
98-
out1 = Array($T,size(X))
99-
out2 = Array($T,size(X))
84+
out1 = Array{$T}(undef, size(X))
85+
out2 = Array{$T}(undef, size(X))
10086
($f!)(out1, out2, X)
10187
end
10288
function ($f!)(out1::Array{$T}, out2::Array{$T}, X::Array{$T})
103-
ccall(($(string("vv",f,suff)),libacc),Void,
104-
(Ptr{$T},Ptr{$T},Ptr{$T},Ptr{Cint}),out1,out2,X,&length(X))
89+
ccall(($(string("vv",f,suff)),libacc),Cvoid,
90+
(Ptr{$T},Ptr{$T},Ptr{$T},Ref{Cint}),out1,out2,X,length(X))
10591
out1, out2
10692
end
10793
end
10894
end
10995

11096
# complex return
11197
for (f,fa) in ((:cis,:cosisin),)
112-
f! = symbol("$(f)!")
98+
f! = Symbol("$(f)!")
11399
@eval begin
114100
function ($f)(X::Array{$T})
115-
out = Array(Complex{$T},size(X))
101+
out = Array{Complex{$T}}(undef, size(X))
116102
($f!)(out, X)
117103
end
118104
function ($f!)(out::Array{Complex{$T}}, X::Array{$T})
119-
ccall(($(string("vv",fa,suff)),libacc),Void,
120-
(Ptr{Complex{$T}},Ptr{$T},Ptr{Cint}),out,X,&length(X))
105+
ccall(($(string("vv",fa,suff)),libacc),Cvoid,
106+
(Ptr{Complex{$T}},Ptr{$T},Ref{Cint}),out,X,length(X))
121107
out
122108
end
123109
end
124110
end
111+
112+
for (f, fa) in onearg_funcs
113+
f! = Symbol("$(f)!")
114+
@eval begin
115+
# Broadcasting override such that f.(X) turns into f(X)
116+
Base.copy(bc::Base.Broadcast.Broadcasted{Style, Axes, typeof($f), Tuple{Array{$T, N}}}) where {Style, Axes, N} = ($f)(bc.args...)
117+
Base.copyto!(dest::Array{$T, N}, bc::Base.Broadcast.Broadcasted{Style, Axes, typeof($f), Tuple{Array{$T, N}}}) where {Style, Axes, N} = ($f!)(dest, bc.args...)
118+
end
119+
end
120+
for (f, fa) in (twoarg_funcs...,(:pow,:pow))
121+
f! = Symbol("$(f)!")
122+
@eval begin
123+
# Broadcasting override such that f.(X) turns into f(X)
124+
Base.copy(bc::Base.Broadcast.Broadcasted{Style, Axes, typeof($f), Tuple{Array{$T, N},Array{$T,N}}}) where {Style, Axes, N} = ($f)(bc.args...)
125+
Base.copyto!(dest::Array{$T, N}, bc::Base.Broadcast.Broadcasted{Style, Axes, typeof($f), Tuple{Array{$T,N},Array{$T,N}}}) where {Style, Axes, N} = ($f!)(dest, bc.args...)
126+
end
127+
end
125128
end
126129

127130
# Functions over single vectors that return scalars/tuples
@@ -132,7 +135,7 @@ for (T, suff) in ((Float32, ""), (Float64, "D"))
132135
@eval begin
133136
function ($f)(X::Vector{$T})
134137
val = Ref{$T}(0.0)
135-
ccall(($(string("vDSP_", fa, suff), libacc)), Void,
138+
ccall(($(string("vDSP_", fa, suff), libacc)), Cvoid,
136139
(Ptr{$T}, Int64, Ref{$T}, UInt64),
137140
X, 1, val, length(X))
138141
return val[]
@@ -145,7 +148,7 @@ for (T, suff) in ((Float32, ""), (Float64, "D"))
145148
function ($f)(X::Vector{$T})
146149
index = Ref{Int}(0)
147150
val = Ref{$T}(0.0)
148-
ccall(($(string("vDSP_", fa, suff), libacc)), Void,
151+
ccall(($(string("vDSP_", fa, suff), libacc)), Cvoid,
149152
(Ptr{$T}, Int64, Ref{$T}, Ref{Int}, UInt64),
150153
X, 1, val, index, length(X))
151154
return (val[], index[]+1)
@@ -159,7 +162,7 @@ for (T, suff) in ((Float32, ""), (Float64, "D"))
159162

160163
for (f, name) in ((:vadd, "addition"), (:vsub, "subtraction"),
161164
(:vdiv, "division"), (:vmul, "multiplication"))
162-
f! = symbol("$(f)!")
165+
f! = Symbol("$(f)!")
163166

164167
@eval begin
165168
@doc """
@@ -169,7 +172,7 @@ for (T, suff) in ((Float32, ""), (Float64, "D"))
169172
the result vector with computed value. *Returns:* **Vector{$($T)}** `result`
170173
""" ->
171174
function ($f!)(result::Vector{$T}, X::Vector{$T}, Y::Vector{$T})
172-
ccall(($(string("vDSP_", f, suff), libacc)), Void,
175+
ccall(($(string("vDSP_", f, suff), libacc)), Cvoid,
173176
(Ptr{$T}, Int64, Ptr{$T}, Int64, Ptr{$T}, Int64, UInt64),
174177
Y, 1, X, 1, result, 1, length(result))
175178
return result

0 commit comments

Comments
 (0)