Skip to content

Commit

Permalink
Merge branch 'master' of github.com:JuliaLang/julia
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Mar 5, 2012
2 parents 59c9032 + 68899bb commit 3d331c5
Show file tree
Hide file tree
Showing 23 changed files with 421 additions and 465 deletions.
4 changes: 2 additions & 2 deletions examples/image.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ function ssd{T}(A::Array{T}, B::Array{T})
end

# normalized by Array size
ssdn{T}(A::Array{T}, B::Array{T}) = ssd(A, B)/prod(size(A))
ssdn{T}(A::Array{T}, B::Array{T}) = ssd(A, B)/numel(A)

# sum of absolute differences
function sad{T}(A::Array{T}, B::Array{T})
return sum(abs(A-B))
end

# normalized by Array size
sadn{T}(A::Array{T}, B::Array{T}) = sad(A, B)/prod(size(A))
sadn{T}(A::Array{T}, B::Array{T}) = sad(A, B)/numel(A)

function imfilter{T}(img::Matrix{T}, filter::Matrix{T}, border::String, value)
si, sf = size(img), size(filter)
Expand Down
4 changes: 2 additions & 2 deletions external/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ openblas-$(OPENBLAS_VER)/Makefile: openblas-$(OPENBLAS_VER).tar.gz
touch $@
$(OPENBLAS_OBJ_SOURCE): openblas-$(OPENBLAS_VER)/Makefile
$(MAKE) -C openblas-$(OPENBLAS_VER) DYNAMIC_ARCH=1 USE_THREAD=0 NO_LAPACK=1 CC=$(CC) FC=$(FC) FFLAGS="$(FFLAGS)" TARGET=$(TARGET_OPENBLAS_ARCH)
cp -f libopenblas.dylib $(EXTROOTLIB)
cp -f openblas-$(OPENBLAS_VER)/libopenblas.$(SHLIB_EXT) $(EXTROOTLIB)

clean-openblas:
$(MAKE) -C openblas-$(OPENBLAS_VER) clean
Expand Down Expand Up @@ -313,7 +313,7 @@ lapack-$(LAPACK_VER)/INSTALL/dlamch.o: lapack-$(LAPACK_VER)/Makefile
cd lapack-$(LAPACK_VER) && \
cp INSTALL/make.inc.gfortran ./make.inc && \
$(MAKE) lapacklib NOOPT="-O0 -fPIC" OPTS="$(FFLAGS)" FORTRAN=$(FC)
$(LAPACK_OBJ_SOURCE): lapack-$(LAPACK_VER)/INSTALL/dlamch.o
$(LAPACK_OBJ_SOURCE): lapack-$(LAPACK_VER)/INSTALL/dlamch.o $(OPENBLAS_OBJ_SOURCE)
cd lapack-$(LAPACK_VER) && \
$(FC) -shared $(FFLAGS) SRC/*.o INSTALL/dlamch.o INSTALL/dsecnd_INT_ETIME.o INSTALL/ilaver.o INSTALL/slamch.o $(LIBBLAS) -o liblapack.$(SHLIB_EXT)
$(LAPACK_OBJ_TARGET): $(LAPACK_OBJ_SOURCE)
Expand Down
38 changes: 8 additions & 30 deletions jl/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@ function conj!{T<:Number}(A::StridedArray{T})
return A
end

macro unary_op(f)
quote
for f in (:-, :~, :conj, :sign)
@eval begin
function ($f)(A::StridedArray)
F = similar(A)
for i=1:numel(A)
Expand All @@ -567,13 +567,8 @@ macro unary_op(f)
end
end

@unary_op (-)
@unary_op (~)
@unary_op (conj)
@unary_op (sign)

macro unary_c2r_op(f)
quote
for f in (:real, :imag)
@eval begin
function ($f){T}(A::StridedArray{T})
S = typeof(($f)(zero(T)))
F = similar(A, S)
Expand All @@ -585,9 +580,6 @@ macro unary_c2r_op(f)
end
end

@unary_c2r_op (real)
@unary_c2r_op (imag)

function !(A::StridedArray{Bool})
F = similar(A)
for i=1:numel(A)
Expand Down Expand Up @@ -637,8 +629,8 @@ function .^{T<:Integer}(A::Array{T}, B::Integer)
_jl_power_array_int_body(F, A, B)
end

macro binary_arithmetic_op(f)
quote
for f in (:+, :-, :.*, :div, :mod, :&, :|, :$)
@eval begin
function ($f){S,T}(A::Array{S}, B::Array{T})
if size(A) != size(B); error("argument dimensions must match"); end
F = similar(A, promote_type(S,T))
Expand All @@ -664,15 +656,6 @@ macro binary_arithmetic_op(f)
end
end

@binary_arithmetic_op (+)
@binary_arithmetic_op (-)
@binary_arithmetic_op (.*)
@binary_arithmetic_op div
@binary_arithmetic_op mod
@binary_arithmetic_op (&)
@binary_arithmetic_op (|)
@binary_arithmetic_op ($)

## promotion to complex ##

function complex{S<:Real,T<:Real}(A::Array{S}, B::Array{T})
Expand Down Expand Up @@ -710,8 +693,8 @@ end

## Binary comparison operators ##

macro binary_comparison_op(f)
quote
for f in (:(==), :!=, :<, :<=)
@eval begin
function ($f)(A::Array, B::Array)
if size(A) != size(B); error("argument dimensions must match"); end
F = similar(A, Bool)
Expand All @@ -737,11 +720,6 @@ macro binary_comparison_op(f)
end
end

@binary_comparison_op (==)
@binary_comparison_op (!=)
@binary_comparison_op (<)
@binary_comparison_op (<=)

## data movement ##

function slicedim(A::Array, d::Integer, i::Integer)
Expand Down
8 changes: 4 additions & 4 deletions jl/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ end
complex128(r::Real, i::Real) = complex128(float64(r),float64(i))
complex128(z) = complex128(real(z), imag(z))

real(c::Complex128) = boxf64(trunc64(unbox(Complex128,c)))
imag(c::Complex128) = boxf64(trunc64(ashr_int(unbox(Complex128,c), 64)))
real(c::Complex128) = boxf64(trunc64(c))
imag(c::Complex128) = boxf64(trunc64(ashr_int(c, 64)))

convert(::Type{Complex128}, x::Real) = complex128(x,0)
convert(::Type{Complex128}, z::Complex) = complex128(real(z),imag(z))
Expand Down Expand Up @@ -86,8 +86,8 @@ end
complex64(r::Real, i::Real) = complex64(float32(r),float32(i))
complex64(z) = complex64(real(z), imag(z))

real(c::Complex64) = boxf32(trunc32(unbox(Complex64,c)))
imag(c::Complex64) = boxf32(trunc32(ashr_int(unbox(Complex64,c), 32)))
real(c::Complex64) = boxf32(trunc32(c))
imag(c::Complex64) = boxf32(trunc32(ashr_int(c, 32)))

convert(::Type{Complex64}, x::Real) = complex64(x,0)
convert(::Type{Complex64}, z::Complex) = complex64(real(z),imag(z))
Expand Down
41 changes: 12 additions & 29 deletions jl/darray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,8 @@ function .^{T<:Integer}(A::SubOrDArray{T}, B::Integer)
S, size(A), distdim(A), procs(A))
end

macro binary_darray_op(f)
quote
for f in (:+, :-, :.*, :./, :.^, :&, :|, :$)
@eval begin
function ($f){T}(A::Number, B::SubOrDArray{T})
S = typeof(($f)(one(A),one(T)))
darray((T,lsz,da)->($f)(A, localize(B, da)),
Expand All @@ -823,34 +823,22 @@ macro binary_darray_op(f)
darray((T,lsz,da)->($f)(localize(A, da), localize(B, da)),
R, size(A), distdim(A), procs(A))
end
end # quote
end # macro

@binary_darray_op (+)
@binary_darray_op (-)
@binary_darray_op (.*)
@binary_darray_op (./)
@binary_darray_op (.^)
@binary_darray_op (&)
@binary_darray_op (|)
@binary_darray_op ($)
end # eval
end # for

-(A::SubOrDArray) = darray(-, A)
~(A::SubOrDArray) = darray(~, A)
conj(A::SubOrDArray) = darray(conj, A)

macro unary_darray_c2r_op(f)
quote
for f in (:real, :imag)
@eval begin
function ($f){T}(A::SubOrDArray{T})
S = typeof(($f)(zero(T)))
darray((T,lsz,da)->($f)(localize(A, da)),
S, size(A), distdim(A), procs(A))
end
end # quote
end # macro

@unary_darray_c2r_op (real)
@unary_darray_c2r_op (imag)
end # eval
end # for

function map(f, A::SubOrDArray)
T = typeof(f(A[1]))
Expand All @@ -876,8 +864,8 @@ for f = (:ceil, :floor, :trunc, :round,
@eval ($f)(A::SubOrDArray) = map_vectorized($f, A)
end

macro binary_darray_comparison_op(f)
quote
for f in (:(==), :!=, :<, :<=)
@eval begin
function ($f)(A::Number, B::SubOrDArray)
darray((T,lsz,da)->($f)(A, localize(B, da)),
Bool, size(B), distdim(B), procs(B))
Expand All @@ -893,13 +881,8 @@ macro binary_darray_comparison_op(f)
darray((T,lsz,da)->($f)(localize(A, da), localize(B, da)),
Bool, size(A), distdim(A), procs(A))
end
end # quote
end # macro

@binary_darray_comparison_op (==)
@binary_darray_comparison_op (!=)
@binary_darray_comparison_op (<)
@binary_darray_comparison_op (<=)
end # eval
end # for

function reduce(f, v::DArray)
mapreduce(f, fetch,
Expand Down
14 changes: 9 additions & 5 deletions jl/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ function abstract_call(f, fargs, argtypes, vtypes, sv::StaticVarInfo, e)
end
end
end
if !is(f,apply) && isa(e,Expr) && isa(f,Function)
if !is(f,apply) && isa(e,Expr) && (isa(f,Function) || isa(f,IntrinsicFunction))
e.head = :call1
end
rt = builtin_tfunction(f, fargs, argtypes)
Expand Down Expand Up @@ -1060,7 +1060,7 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
linfo.inferred = true
end

compr = ccall(:jl_compress_ast, Any, (Any,), fulltree)
compr = ccall(:jl_compress_ast, Any, (Any, Any,), def, fulltree)

if !redo
if is(def.tfunc,())
Expand Down Expand Up @@ -1285,6 +1285,10 @@ function inlineable(f, e::Expr, vars)
isType(e.typ) && isleaftype(e.typ.parameters[1])
return e.typ.parameters[1]
end
if length(atypes)==1 && isa(atypes[1],BitsKind) &&
(is(f,unbox8) || is(f,unbox16) || is(f,unbox32) || is(f,unbox64) || is(f,unbox))
return e.args[2]
end

meth = getmethods(f, atypes)
if length(meth) != 1
Expand Down Expand Up @@ -1387,9 +1391,9 @@ function inlining_pass(e::Expr, vars)
return e
end
arg1 = e.args[1]
if is(e.head,:call) && (is(arg1, :ccall) ||
(isa(arg1,SymbolNode) && is(arg1.name, :ccall)) ||
(isa(arg1,TopNode) && is(arg1.name, :ccall)))
if is(e.head,:call1) && (is(arg1, :ccall) ||
(isa(arg1,SymbolNode) && is(arg1.name, :ccall)) ||
(isa(arg1,TopNode) && is(arg1.name, :ccall)))
i0 = 3
else
i0 = 1
Expand Down
63 changes: 49 additions & 14 deletions jl/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,25 +400,60 @@ function ^(A::AbstractMatrix, p::Number)
diagmm(X, v.^p)*Xinv
end

function findmax(a)
m = typemin(eltype(a))
mi = 0
for i=1:length(a)
if a[i] > m
m = a[i]
mi = i
end
end
return (m, mi)
end

function findmin(a)
m = typemax(eltype(a))
mi = 0
for i=1:length(a)
if a[i] < m
m = a[i]
mi = i
end
end
return (m, mi)
end

function rref{T}(A::Matrix{T})
(L,U) = lu(A)
nr, nc = size(A)
U = copy_to(similar(A,Float64), A)
e = eps(norm(U,Inf))
nr, nc = size(U)
for i = 1:nr
d = U[i,i]
if abs(d) > e
for k = i:nc
U[i,k] /= d
i = j = 1
while i <= nr && j <= nc
(m, mi) = findmax(abs(U[i:nr,j]))
mi = mi+i - 1
if m <= e
U[i:nr,j] = 0
j += 1
else
for k=j:nc
U[i, k], U[mi, k] = U[mi, k], U[i, k]
end
end
end
for i = 1:(nr-1)
for j = (i+1):min(nr,nc)
c = U[i,j]
d = U[i,j]
for k = j:nc
U[i,k] -= c*U[j,k]
U[i,k] /= d
end
for k = 1:nr
if k != i
d = U[k,j]
for l = j:nc
U[k,l] -= d*U[i,l]
end
end
end
i += 1
j += 1
end
end
U
return U
end
Loading

0 comments on commit 3d331c5

Please sign in to comment.