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
JeffBezanson committed Mar 4, 2014
2 parents 94d5767 + 037a469 commit 2135de0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ JULIA_VERSION = $(shell cat $(JULIAHOME)/VERSION)
ifneq ($(NO_GIT), 1)
JULIA_COMMIT = $(shell git rev-parse --short=10 HEAD)
else
JULIA_COMMIT = $JULIA_VERSION
JULIA_COMMIT = $(JULIA_VERSION)
endif

# Directories where said libraries get installed to
Expand Down
44 changes: 34 additions & 10 deletions base/cartesian.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Cartesian

export @ngenerate, @nsplat, @nloops, @nref, @ncall, @nexprs, @nextract, @nall, @ntuple, ngenerate
export @ngenerate, @nsplat, @nloops, @nref, @ncall, @nexprs, @nextract, @nall, @ntuple, @nif, ngenerate

const CARTESIAN_DIMS = 4

Expand Down Expand Up @@ -368,6 +368,18 @@ function _ntuple(N::Int, ex)
Expr(:escape, Expr(:tuple, vars...))
end

# if condition1; operation1; elseif condition2; operation2; else operation3
# You can pass one or two operations; the second, if present, is used in the final "else"
macro nif(N, condition, operation...)
# Handle the final "else"
ex = esc(inlineanonymous(length(operation) > 1 ? operation[2] : operation[1], N))
# Make the nested if statements
for i = N-1:-1:1
ex = Expr(:if, esc(inlineanonymous(condition,i)), esc(inlineanonymous(operation[1],i)), ex)
end
ex
end

## Utilities

# Simplify expressions like :(d->3:size(A,d)-3) given an explicit value for d
Expand All @@ -383,15 +395,7 @@ function inlineanonymous(ex::Expr, val)
exout = lreplace(ex, sym, val)
exout = poplinenum(exout)
exout = poparithmetic(exout)
# Inline ternary expressions
if isa(exout, Expr) && exout.head == :if
try
tf = eval(exout.args[1])
exout = tf?exout.args[2]:exout.args[3]
catch
end
end
exout
popconditionals(exout)
end

# Given :i and 3, this generates :i_3
Expand Down Expand Up @@ -450,4 +454,24 @@ function poparithmetic(ex::Expr)
ex
end

# Resolve if/else and ternary expressions that can be evaluated at parsing time
popconditionals(arg) = arg
function popconditionals(ex::Expr)
if isa(ex, Expr) && ex.head == :if
for i = 2:length(ex.args)
ex.args[i] = popconditionals(ex.args[i])
end
try
tf = eval(ex.args[1])
ex = tf?ex.args[2]:ex.args[3]
catch
end
else
for i = 1:length(ex.args)
ex.args[i] = popconditionals(ex.args[i])
end
end
ex
end

end
8 changes: 4 additions & 4 deletions base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -641,14 +641,14 @@ function reducedim{Tv,Ti}(f::Function, A::SparseMatrixCSC{Tv,Ti}, region, v0)
end

maximum{T}(A::SparseMatrixCSC{T}) =
isempty(A) ? throw(ArgumentError("argument must not be empty")) : reducedim(scalarmax,A,(1,2),typemin(T))
isempty(A) ? throw(ArgumentError("argument must not be empty")) : reducedim(Base.scalarmax,A,(1,2),typemin(T))
maximum{T}(A::SparseMatrixCSC{T}, region) =
isempty(A) ? similar(A, reduced_dims0(A,region)) : reducedim(scalarmax,A,region,typemin(T))
isempty(A) ? similar(A, reduced_dims0(A,region)) : reducedim(Base.scalarmax,A,region,typemin(T))

minimum{T}(A::SparseMatrixCSC{T}) =
isempty(A) ? throw(ArgumentError("argument must not be empty")) : reducedim(scalarmin,A,(1,2),typemax(T))
isempty(A) ? throw(ArgumentError("argument must not be empty")) : reducedim(Base.scalarmin,A,(1,2),typemax(T))
minimum{T}(A::SparseMatrixCSC{T}, region) =
isempty(A) ? similar(A, reduced_dims0(A,region)) : reducedim(scalarmin,A,region,typemax(T))
isempty(A) ? similar(A, reduced_dims0(A,region)) : reducedim(Base.scalarmin,A,region,typemax(T))

sum{T}(A::SparseMatrixCSC{T}) = reducedim(+,A,(1,2),zero(T))
sum{T}(A::SparseMatrixCSC{T}, region) = reducedim(+,A,region,zero(T))
Expand Down
2 changes: 1 addition & 1 deletion base/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ getindex(s::SubArray, i0::Real, i1::Real, i2::Real, i3::Real, i4::Real) =
getindex(s::SubArray, i0::Real, i1::Real, i2::Real, i3::Real, i4::Real, i5::Real) =
getindex(s, to_index(i0), to_index(i1), to_index(i2), to_index(i3), to_index(i4), to_index(i5))
getindex(s::SubArray, i0::Real, i1::Real, i2::Real, i3::Real, i4::Real, i5::Real, is::Int...) =
getindex(s, to_index(i0), to_index(i1), to_index(i2), to_index(i3), to_index(i4), to_index(5), is...)
getindex(s, to_index(i0), to_index(i1), to_index(i2), to_index(i3), to_index(i4), to_index(i5), is...)

getindex(s::SubArray, i::Integer) = s[ind2sub(size(s), i)...]

Expand Down
2 changes: 1 addition & 1 deletion contrib/repackage_system_suitesparse4.make
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ifeq ($(USE_SYSTEM_LAPACK),0)
$(build_libdir)/libgfortblas.dylib:
make -C ../deps/ $(build_libdir)/libgfortblas.dylib

default: $(build_ibdir)/libgfortblas.dylib
default: $(build_libdir)/libgfortblas.dylib
endif
endif
endif
Expand Down
2 changes: 1 addition & 1 deletion deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ OPENBLAS_BUILD_OPTS += BINARY=32
else ifeq ($(ARCH),x86_64)
OPENBLAS_BUILD_OPTS += BINARY=64
else
$(error "unknown arch for openblas cross-compile")
$(error "unknown arch for openblas cross-compile: $(ARCH)")
endif

ifeq ($(OS),WINNT)
Expand Down
8 changes: 8 additions & 0 deletions test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,11 @@ end
# test for "access to undefined error" types that initially allocate elements as #undef
@test all(sparse(1:2, 1:2, Any[1,2])^2 == sparse(1:2, 1:2, [1,4]))
sd1 = diff(sparse([1,1,1], [1,2,3], Any[1,2,3]), 1)

# issue #6036
P = spzeros(Float64, 3, 3)
for i = 1:3
P[i,i] = i
end
@test minimum(P) == [0]
@test maximum(P) == [3]

0 comments on commit 2135de0

Please sign in to comment.