Skip to content

Commit 32a9a67

Browse files
committed
Merge pull request #2146 from andreasnoackjensen/master
Change dot and the Faddeeva functions to use new complex return possibility and remove the Faddeeva wrapper.
2 parents ab3440a + b962474 commit 32a9a67

File tree

6 files changed

+38
-92
lines changed

6 files changed

+38
-92
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ JL_LIBS = julia-release julia-debug
4848
# private libraries, that are installed in $(PREFIX)/lib/julia
4949
JL_PRIVATE_LIBS = amd arpack cholmod colamd fftw3 fftw3f fftw3_threads \
5050
fftw3f_threads glpk glpk_wrapper gmp gmp_wrapper grisu \
51-
history Faddeeva_wrapper openlibm openlibm-extras pcre \
51+
history openlibm openlibm-extras pcre \
5252
random readline Rmath spqr suitesparse_wrapper \
5353
tk_wrapper umfpack z openblas
5454

base/blas.jl

+27-4
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,42 @@ for (fname, elty) in ((:dscal_,:Float64), (:sscal_,:Float32),
7272
end
7373
end
7474

75-
# ccall is unable to return complex values (Issue #85)
76-
#@blas_dot :zdotc_ Complex128
77-
#@blas_dot :cdotc_ Complex64
78-
# DOUBLE PRECISION FUNCTION DDOT(N,DX,INCX,DY,INCY)
75+
# dot
7976
for (fname, elty) in ((:ddot_,:Float64), (:sdot_,:Float32))
8077
@eval begin
78+
# DOUBLE PRECISION FUNCTION DDOT(N,DX,INCX,DY,INCY)
79+
# * .. Scalar Arguments ..
80+
# INTEGER INCX,INCY,N
81+
# * ..
82+
# * .. Array Arguments ..
83+
# DOUBLE PRECISION DX(*),DY(*)
8184
function dot(n::Integer, DX::Union(Ptr{$elty},Array{$elty}), incx::Integer, DY::Union(Ptr{$elty},Array{$elty}), incy::Integer)
8285
ccall(($(string(fname)),libblas), $elty,
8386
(Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
8487
&n, DX, &incx, DY, &incy)
8588
end
8689
end
8790
end
91+
for (fname, elty, relty) in ((:zdotc_,:Complex128,:Float64), (:cdotc_,:Complex64,:Float32))
92+
@eval begin
93+
# DOUBLE COMPLEX FUNCTION ZDOTC(N,ZX,INCX,ZY,INCY)
94+
# * .. Scalar Arguments ..
95+
# INTEGER INCX,INCY,N
96+
# * ..
97+
# * .. Array Arguments ..
98+
# DOUBLE COMPLEX ZX(*),ZY(*)
99+
function dot(n::Integer, DX::Union(Ptr{$elty},Array{$elty}), incx::Integer, DY::Union(Ptr{$elty},Array{$elty}), incy::Integer)
100+
convert($elty, ccall(($(string(fname)),libblas), ComplexPair{$relty},
101+
(Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
102+
&n, DX, &incx, DY, &incy))
103+
end
104+
end
105+
end
106+
function dot{T<:BlasFloat}(DX::Array{T}, DY::Array{T})
107+
n = length(DX)
108+
if n != length(DY) throw(BlasDimMisMatch) end
109+
return dot(n, DX, 1, DY, 1)
110+
end
88111

89112
# DOUBLE PRECISION FUNCTION DNRM2(N,X,INCX)
90113
for (fname, elty, ret_type) in ((:dnrm2_,:Float64,:Float64),

base/math.jl

+2-12
Original file line numberDiff line numberDiff line change
@@ -667,21 +667,11 @@ function zeta(z::Number)
667667
end
668668
@vectorize_1arg Number zeta
669669

670-
const Faddeeva_tmp = Array(Float64,2)
671-
672-
# wrappers for complex Faddeeva functions; these will get a lot simpler,
673-
# and can call openopenlibm_extras directly, once ccall supports C99 complex types.
674670
for f in (:erf, :erfc, :erfcx, :erfi, :Dawson)
675671
fname = (f === :Dawson) ? :dawson : f
676672
@eval begin
677-
function ($fname)(z::Complex128)
678-
ccall(($(string("wrapFaddeeva_",f)),:libFaddeeva_wrapper), Void, (Ptr{Complex128},Ptr{Complex128},Float64,), Faddeeva_tmp, &z, zero(Float64))
679-
return complex128(Faddeeva_tmp[1],Faddeeva_tmp[2])
680-
end
681-
function ($fname)(z::Complex64)
682-
ccall(($(string("wrapFaddeeva_",f)),:libFaddeeva_wrapper), Void, (Ptr{Complex128},Ptr{Complex128},Float64,), Faddeeva_tmp, &complex128(z), float64(eps(Float32)))
683-
return complex64(Faddeeva_tmp[1],Faddeeva_tmp[2])
684-
end
673+
($fname)(z::Complex128) = complex128(ccall(($(string("Faddeeva_",f)),openlibm_extras), ComplexPair{Float64}, (ComplexPair{Float64}, Float64), z, zero(Float64)))
674+
($fname)(z::Complex64) = complex64(ccall(($(string("Faddeeva_",f)),openlibm_extras), ComplexPair{Float64}, (ComplexPair{Float64}, Float64), complex128(z), float64(eps(Float32))))
685675
($fname)(z::Complex) = ($fname)(complex128(z))
686676
end
687677
end

base/matmul.jl

+5-10
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,24 @@ diagmm(b::Vector, A::Matrix) =
3636

3737
# Dot products
3838

39-
function dot{T<:Union(Vector{Float64}, Vector{Float32})}(x::T, y::T)
40-
length(x) != length(y) ? error("Inputs should be of same length") : true
41-
BLAS.dot(length(x), x, 1, y, 1)
42-
end
43-
44-
function dot{T<:Union(Float64, Float32), TI<:Integer}(x::Vector{T}, rx::Union(Range1{TI},Range{TI}), y::Vector{T}, ry::Union(Range1{TI},Range{TI}))
39+
dot{T<:BLAS.BlasFloat}(x::Vector{T}, y::Vector{T}) = BLAS.dot(x, y)
40+
function dot{T<:BLAS.BlasFloat, TI<:Integer}(x::Vector{T}, rx::Union(Range1{TI},Range{TI}), y::Vector{T}, ry::Union(Range1{TI},Range{TI}))
4541
length(rx) != length(ry) ? error("Ranges should be of same length") : true
4642
if min(rx) < 1 || max(rx) > length(x) || min(ry) < 1 || max(ry) > length(y)
4743
throw(BoundsError())
4844
end
4945
BLAS.dot(length(rx), pointer(x)+(first(rx)-1)*sizeof(T), step(rx), pointer(y)+(first(ry)-1)*sizeof(T), step(ry))
5046
end
51-
52-
Ac_mul_B(x::Vector, y::Vector) = [dot(x, y)]
53-
At_mul_B{T<:Real}(x::Vector{T}, y::Vector{T}) = [dot(x, y)]
54-
5547
function dot(x::Vector, y::Vector)
5648
s = zero(eltype(x))
5749
for i=1:length(x)
5850
s += conj(x[i])*y[i]
5951
end
6052
s
6153
end
54+
dot(x::Number, y::Number) = conj(x) * y
55+
Ac_mul_B(x::Vector, y::Vector) = [dot(x, y)]
56+
At_mul_B{T<:Real}(x::Vector{T}, y::Vector{T}) = [dot(x, y)]
6257

6358
dot(x::Number, y::Number) = conj(x) * y
6459

deps/Faddeeva_wrapper.c

-45
This file was deleted.

deps/Makefile

+3-20
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ endif
2020

2121
#autoconf configure-driven scripts: llvm readline pcre arpack fftw unwind gmp glpk patchelf
2222
#custom configure-driven script: zlib nginx
23-
#custom Makefile rules: openlibm Faddeeva-wrapper rmath double-conversion random gmp-wrapper suitesparse-wrapper suitesparse lapack openblas uv tk-wrapper
23+
#custom Makefile rules: openlibm rmath double-conversion random gmp-wrapper suitesparse-wrapper suitesparse lapack openblas uv tk-wrapper
2424

2525
# prevent installing libs into usr/lib64 on opensuse
2626
unexport CONFIG_SITE
2727

2828
STAGE1_DEPS = uv openlibm-extras random rmath double-conversion
29-
STAGE2_DEPS = gmp-wrapper Faddeeva-wrapper
29+
STAGE2_DEPS = gmp-wrapper
3030
STAGE3_DEPS = glpk-wrapper suitesparse-wrapper
3131

3232
ifeq ($(USE_SYSTEM_LIBUNWIND), 0)
@@ -551,24 +551,7 @@ get-openlibm-extras: openlibm/Makefile.extras
551551
configure-openlibm-extras: get-openlibm-extras
552552
compile-openlibm-extras: $(OPENLIBMEXT_OBJ_SOURCE)
553553
check-openlibm-extras: compile-openlibm-extras
554-
install-openlibm-extras: $(OPENLIBMEXT_OBJ_TARGET) $(BUILD)/lib/libFaddeeva_wrapper.$(SHLIB_EXT)
555-
556-
# Wrapper for openlibm/Faddeeva since ccall doesn't support C99 complex:
557-
$(BUILD)/lib/libFaddeeva_wrapper.$(SHLIB_EXT): Faddeeva_wrapper.c $(OPENLIBMEXT_OBJ_TARGET)
558-
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -O2 -shared $(fPIC) -I openlibm/Faddeeva Faddeeva_wrapper.c -o $@ -L $(BUILD)/lib -lopenlibm-extras $(RPATH_ORIGIN)
559-
$(INSTALL_NAME_CMD)libFaddeeva_wrapper.$(SHLIB_EXT) $@
560-
touch -c $@
561-
562-
clean-Faddeeva-wrapper:
563-
-rm -f $(OPENLIBMEXT_OBJ_TARGET) $(BUILD)/lib/libFaddeeva_wrapper.$(SHLIB_EXT)
564-
distclean-Faddeeva-wrapper: clean-Faddeeva-wrapper
565-
566-
get-Faddeeva-wrapper: get-openlibm
567-
configure-Faddeeva-wrapper: get-openlibm
568-
compile-Faddeeva-wrapper: $(BUILD)/lib/libFaddeeva_wrapper.$(SHLIB_EXT)
569-
check-Faddeeva-wrapper: compile-Faddeeva-wrapper
570-
install-Faddeeva-wrapper: $(BUILD)/lib/libFaddeeva_wrapper.$(SHLIB_EXT)
571-
554+
install-openlibm-extras: $(OPENLIBMEXT_OBJ_TARGET)
572555

573556
## LIBRANDOM ##
574557

0 commit comments

Comments
 (0)