Skip to content

Commit

Permalink
Merge pull request JuliaLang#15 from JuliaLang/master
Browse files Browse the repository at this point in the history
update to 8c4111c
  • Loading branch information
tkelman committed Mar 12, 2014
2 parents a732ed0 + 8c4111c commit 17e8435
Show file tree
Hide file tree
Showing 30 changed files with 488 additions and 220 deletions.
17 changes: 14 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ Library improvements
the same length. This generalizes and replaces `normfro` ([#6057]),
and `norm` is now type-stable ([#6056]).

* + and - now only works when the sizes of the arrays are the same, i.e. the
operations no longer do broadcasting. New `UniformScaling` type and identity
`I` constant (#5810).
* `+` and `-` now require the sizes of the arrays to be the
same: the operations no longer do broadcasting. New
`UniformScaling` matrix type and identity `I` constant (#5810).

* Sparse linear algebra

Expand Down Expand Up @@ -214,6 +214,9 @@ Library improvements
* Constructors for collections (`Set`, `Dict`, etc.) now generally accept a
single iterable argument giving the elements of the collection ([#4996], [#4871])

* Ranges and arrays with the same elements are now unequal. This allows hashing
and comparing ranges to be faster. ([#5778])

Deprecated or removed
---------------------

Expand Down Expand Up @@ -307,6 +310,14 @@ Deprecated or removed
[#2333]: https://github.com/JuliaLang/julia/issues/2333
[#5636]: https://github.com/JuliaLang/julia/issues/5636
[#1268]: https://github.com/JuliaLang/julia/issues/1268
[#5677]: https://github.com/JuliaLang/julia/issues/5677
[#5545]: https://github.com/JuliaLang/julia/issues/5545
[#6057]: https://github.com/JuliaLang/julia/issues/6057
[#6056]: https://github.com/JuliaLang/julia/issues/6056
[#3344]: https://github.com/JuliaLang/julia/issues/3344
[#5737]: https://github.com/JuliaLang/julia/issues/5737
[#6073]: https://github.com/JuliaLang/julia/issues/6073
[#5778]: https://github.com/JuliaLang/julia/issues/5778

Julia v0.2.0 Release Notes
==========================
Expand Down
7 changes: 7 additions & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ for fn in _numeric_conversion_func_names
@eval begin
$fn(r::Range ) = Range($fn(r.start), $fn(r.step), r.len)
$fn(r::Range1) = Range1($fn(r.start), r.len)
$fn(r::FloatRange) = FloatRange($fn(r.start), $fn(r.step), r.len, $fn(r.divisor))
end
end

Expand Down Expand Up @@ -813,6 +814,9 @@ function isequal(A::AbstractArray, B::AbstractArray)
if size(A) != size(B)
return false
end
if isa(A,Ranges) != isa(B,Ranges)
return false
end
for i = 1:length(A)
if !isequal(A[i], B[i])
return false
Expand All @@ -834,6 +838,9 @@ function (==)(A::AbstractArray, B::AbstractArray)
if size(A) != size(B)
return false
end
if isa(A,Ranges) != isa(B,Ranges)
return false
end
for i = 1:length(A)
if !(A[i]==B[i])
return false
Expand Down
4 changes: 4 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ typealias Vector{T} Array{T,1}
typealias Matrix{T} Array{T,2}
typealias VecOrMat{T} Union(Vector{T}, Matrix{T})

typealias DenseVector{T} DenseArray{T,1}
typealias DenseMatrix{T} DenseArray{T,2}
typealias DenseVecOrMat{T} Union(DenseVector{T}, DenseMatrix{T})

typealias StoredVector{T} StoredArray{T,1}
typealias StridedArray{T,N,A<:DenseArray} Union(DenseArray{T,N}, SubArray{T,N,A})
typealias StridedVector{T,A<:DenseArray} Union(DenseArray{T,1}, SubArray{T,1,A})
Expand Down
10 changes: 0 additions & 10 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1108,16 +1108,6 @@ function (!=)(A::BitArray, B::BitArray)
return A.chunks != B.chunks
end

# TODO: avoid bitpack/bitunpack
for f in (:(==), :!=)
@eval begin
($f)(A::BitArray, B::AbstractArray{Bool}) = ($f)(A, bitpack(B))
($f)(A::AbstractArray{Bool}, B::BitArray) = ($f)(bitpack(A), B)
($f)(A::BitArray, B::AbstractArray) = ($f)(bitunpack(A), B)
($f)(A::AbstractArray, B::BitArray) = ($f)(A, bitunpack(B))
end
end


## Data movement ##

Expand Down
1 change: 1 addition & 0 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ end


function _start()
Sys.init_sysinfo()
if CPU_CORES > 8 && !("OPENBLAS_NUM_THREADS" in keys(ENV)) && !("OMP_NUM_THREADS" in keys(ENV))
# Prevent openblas from stating to many threads, unless/until specifically requested
ENV["OPENBLAS_NUM_THREADS"] = 8
Expand Down
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ export PipeString
@deprecate svdfact(A,thin) svdfact(A,thin=thin)
@deprecate svdfact!(A,thin) svdfact(A,thin=thin)
@deprecate svd(A,thin) svd(A,thin=thin)
# Note: These methods need a more helpfull error message than a `NoMethodError`,
# when the deprecation is removed
@deprecate (+)(A::Array{Bool},x::Bool) A .+ x
@deprecate (+)(x::Bool,A::Array{Bool}) x .+ A
@deprecate (-)(A::Array{Bool},x::Bool) A .- x
Expand Down
3 changes: 3 additions & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export
Complex64,
Complex32,
DArray,
DenseMatrix,
DenseVecOrMat,
DenseVector,
DevNull,
Diagonal,
Dict,
Expand Down
31 changes: 21 additions & 10 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ t_func[eval(Core.Intrinsics,:select_value)] =
t_func[is] = (2, 2, cmp_tfunc)
t_func[issubtype] = (2, 2, cmp_tfunc)
t_func[isa] = (2, 2, cmp_tfunc)
t_func[isdefined] = (1, 2, (args...)->Bool)
t_func[isdefined] = (1, Inf, (args...)->Bool)
t_func[Union] = (0, Inf,
(args...)->(if all(isType,args)
Type{Union(map(t->t.parameters[1],args)...)}
Expand Down Expand Up @@ -285,6 +285,9 @@ const tupleref_tfunc = function (A, t, i)
else
types = t
end
if !isa(types, Type)
return Any
end
T = reduce(tmerge, None, types)
if wrapType
return isleaftype(T) ? Type{T} : Type{TypeVar(:_,T)}
Expand Down Expand Up @@ -379,14 +382,16 @@ const getfield_tfunc = function (A, s0, name)
end
if isType(s0)
sp = s0.parameters[1]
if fld === :parameters && isleaftype(sp.parameters)
return Type{sp.parameters}
end
if fld === :types && isleaftype(sp.types)
return Type{sp.types}
end
if fld === :super && isleaftype(sp)
return Type{sp.super}
if isa(sp,DataType) && !any(x->isa(x,TypeVar), sp.parameters)
if fld === :parameters
return Type{sp.parameters}
end
if fld === :types
return Type{sp.types}
end
if fld === :super
return Type{sp.super}
end
end
end
for i=1:length(s.names)
Expand Down Expand Up @@ -1763,7 +1768,11 @@ function exprtype(x::ANY)
end
return abstract_eval(x, (), sv)
elseif isa(x,QuoteNode)
return typeof(x.value)
v = x.value
if isa(v,Type)
return Type{v}
end
return typeof(v)
elseif isa(x,Type)
return Type{x}
elseif isa(x,LambdaStaticData)
Expand Down Expand Up @@ -2149,6 +2158,8 @@ function inlining_pass(e::Expr, sv, ast)
if isa(aarg,Expr) && is_known_call(aarg, tuple, sv)
# apply(f,tuple(x,y,...)) => f(x,y,...)
newargs[i-2] = aarg.args[2:end]
elseif isa(aarg, Tuple)
newargs[i-2] = { QuoteNode(x) for x in aarg }
elseif isa(t,Tuple) && !isvatuple(t) && effect_free(aarg,sv)
# apply(f,t::(x,y)) => f(t[1],t[2])
newargs[i-2] = { mk_tupleref(aarg,j) for j=1:length(t) }
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ for Ti in (:Int32,:Int64)
ccall((@chm_nm "nnz" $Ti
,:libcholmod), Int, (Ptr{c_CholmodSparse{Tv,$Ti}},Ptr{Uint8}),&A.c,cmn($Ti))
end
function norm{Tv<:CHMVTypes}(A::CholmodSparse{Tv,$Ti},p::Number)
function norm{Tv<:CHMVTypes}(A::CholmodSparse{Tv,$Ti},p::Real)
ccall((@chm_nm "norm_sparse" $Ti
, :libcholmod), Float64,
(Ptr{c_CholmodSparse{Tv,$Ti}}, Cint, Ptr{Uint8}),
Expand Down
8 changes: 2 additions & 6 deletions base/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ function norm{T<:BlasFloat, TI<:Integer}(x::StridedVector{T}, rx::Union(Range1{T
BLAS.nrm2(length(rx), pointer(x)+(first(rx)-1)*sizeof(T), step(rx))
end

function vecnorm{T<:BlasFloat}(x::Union(Array{T},StridedVector{T}), p::Real=2)
length(x) == 0 && return zero(T)
p == 1 && T <: Real && return BLAS.asum(x)
p == 2 && return BLAS.nrm2(x)
invoke(vecnorm, (Any, Real), x, p)
end
vecnorm1{T<:BlasReal}(x::Union(Array{T},StridedVector{T})) = BLAS.asum(x)
vecnorm2{T<:BlasFloat}(x::Union(Array{T},StridedVector{T})) = BLAS.nrm2(x)

function triu!{T}(M::Matrix{T}, k::Integer)
m, n = size(M)
Expand Down
29 changes: 15 additions & 14 deletions base/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,36 +145,40 @@ norm(x::AbstractVector, p::Real=2) = vecnorm(x, p)

function norm1{T}(A::AbstractMatrix{T})
m,n = size(A)
nrm = zero(real(zero(T)))
Tnorm = typeof(float(real(zero(T))))
Tsum = promote_type(Float64,Tnorm)
nrm::Tsum = 0
@inbounds begin
for j = 1:n
nrmj = zero(real(zero(T)))
nrmj::Tsum = 0
for i = 1:m
nrmj += abs(A[i,j])
end
nrm = max(nrm,nrmj)
end
end
return nrm
return convert(Tnorm, nrm)
end
function norm2(A::AbstractMatrix)
function norm2{T}(A::AbstractMatrix{T})
m,n = size(A)
if m == 0 || n == 0 return real(zero(eltype(A))) end
svdvals(A)[1]
Tnorm = typeof(float(real(zero(T))))
(m == 0 || n == 0) ? zero(Tnorm) : convert(Tnorm, svdvals(A)[1])
end
function normInf{T}(A::AbstractMatrix{T})
m,n = size(A)
nrm = zero(real(zero(T)))
Tnorm = typeof(float(real(zero(T))))
Tsum = promote_type(Float64,Tnorm)
nrm::Tsum = 0
@inbounds begin
for i = 1:m
nrmi = zero(real(zero(T)))
nrmi::Tsum = 0
for j = 1:n
nrmi += abs(A[i,j])
end
nrm = max(nrm,nrmi)
end
end
return nrm
return convert(Tnorm, nrm)
end
function norm{T}(A::AbstractMatrix{T}, p::Real=2)
p == 2 && return norm2(A)
Expand All @@ -183,11 +187,8 @@ function norm{T}(A::AbstractMatrix{T}, p::Real=2)
throw(ArgumentError("invalid p-norm p=$p. Valid: 1, 2, Inf"))
end

function norm(x::Number, p=2)
if p == 1 || p == Inf || p == -Inf return abs(x) end
p == 0 && return ifelse(x != 0, 1, 0)
float(abs(x))
end
norm(x::Number, p::Real=2) =
p == 0 ? convert(typeof(real(x)), ifelse(x != 0, 1, 0)) : abs(x)

rank(A::AbstractMatrix, tol::Real) = sum(svdvals(A) .> tol)
function rank(A::AbstractMatrix)
Expand Down
65 changes: 42 additions & 23 deletions base/linalg/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ end
function A_mul_B!::Number, A::SparseMatrixCSC, x::AbstractVector, β::Number, y::AbstractVector)
A.n == length(x) || throw(DimensionMismatch(""))
A.m == length(y) || throw(DimensionMismatch(""))
for i = 1:A.m; y[i] *= β; end
if β != 1
β != 0 ? scale!(y,β) : fill!(y,zero(eltype(y)))
end
nzv = A.nzval
rv = A.rowval
for col = 1 : A.n
Expand All @@ -28,17 +30,24 @@ A_mul_B!(y::AbstractVector, A::SparseMatrixCSC, x::AbstractVector) = A_mul_B!(on

function *{TA,S,Tx}(A::SparseMatrixCSC{TA,S}, x::AbstractVector{Tx})
T = promote_type(TA,Tx)
A_mul_B!(one(T), A, x, zero(T), zeros(T, A.m))
A_mul_B!(one(T), A, x, zero(T), Array(T, A.m))
end

function Ac_mul_B!::Number, A::SparseMatrixCSC, x::AbstractVector, β::Number, y::AbstractVector)
A.n == length(y) || throw(DimensionMismatch(""))
A.m == length(x) || throw(DimensionMismatch(""))
nzv = A.nzval
rv = A.rowval
zro = zero(eltype(y))
@inbounds begin
for i = 1 : A.n
y[i] *= β
if β != 1
if β != 0
y[i] *= β
else
y[i] = zro
end
end
tmp = zero(eltype(y))
for j = A.colptr[i] : (A.colptr[i+1]-1)
tmp += conj(nzv[j])*x[rv[j]]
Expand All @@ -54,9 +63,16 @@ function At_mul_B!(α::Number, A::SparseMatrixCSC, x::AbstractVector, β::Number
A.m == length(x) || throw(DimensionMismatch(""))
nzv = A.nzval
rv = A.rowval
zro = zero(eltype(y))
@inbounds begin
for i = 1 : A.n
y[i] *= β
if β != 1
if β != 0
y[i] *= β
else
y[i] = zro
end
end
tmp = zero(eltype(y))
for j = A.colptr[i] : (A.colptr[i+1]-1)
tmp += nzv[j]*x[rv[j]]
Expand All @@ -69,11 +85,11 @@ end
At_mul_B!(y::AbstractVector, A::SparseMatrixCSC, x::AbstractVector) = At_mul_B!(one(eltype(x)), A, x, zero(eltype(y)), y)
function Ac_mul_B{TA,S,Tx}(A::SparseMatrixCSC{TA,S}, x::AbstractVector{Tx})
T = promote_type(TA, Tx)
Ac_mul_B!(one(T), A, x, zero(T), zeros(T, A.n))
Ac_mul_B!(one(T), A, x, zero(T), Array(T, A.n))
end
function At_mul_B{TA,S,Tx}(A::SparseMatrixCSC{TA,S}, x::AbstractVector{Tx})
T = promote_type(TA, Tx)
At_mul_B!(one(T), A, x, zero(T), zeros(T, A.n))
At_mul_B!(one(T), A, x, zero(T), Array(T, A.n))
end

*(X::BitArray{1}, A::SparseMatrixCSC) = invoke(*, (AbstractVector, SparseMatrixCSC), X, A)
Expand Down Expand Up @@ -462,28 +478,31 @@ vecnorm(A::SparseMatrixCSC, p::Real=2) = vecnorm(A.nzval, p)
function norm(A::SparseMatrixCSC,p::Real=1)
m, n = size(A)
if m == 0 || n == 0 || isempty(A)
return real(zero(eltype(A)))
return float(real(zero(eltype(A))))
elseif m == 1 || n == 1
return norm(reshape(full(A), length(A)), p)
elseif p==1
nA = real(zero(eltype(A)))
for j=1:n
colSum = real(zero(eltype(A)))
for i = A.colptr[j]:A.colptr[j+1]-1
colSum += abs(A.nzval[i])
else
Tnorm = typeof(float(real(zero(eltype(A)))))
Tsum = promote_type(Float64,Tnorm)
if p==1
nA::Tsum = 0
for j=1:n
colSum::Tsum = 0
for i = A.colptr[j]:A.colptr[j+1]-1
colSum += abs(A.nzval[i])
end
nA = max(nA, colSum)
end
nA = max(nA, colSum)
end
elseif p==Inf
rowSum = zeros(typeof(real(A[1])),m)
for i=1:length(A.nzval)
rowSum[A.rowval[i]] += abs(A.nzval[i])
return convert(Tnorm, nA)
elseif p==Inf
rowSum = zeros(Tsum,m)
for i=1:length(A.nzval)
rowSum[A.rowval[i]] += abs(A.nzval[i])
end
return convert(Tnorm, maximum(rowSum))
end
nA = maximum(rowSum)
else
throw(ArgumentError("invalid p-norm p=$p. Valid: 1, Inf"))
end
return nA
throw(ArgumentError("invalid p-norm p=$p. Valid: 1, Inf"))
end

# TODO
Expand Down
Loading

0 comments on commit 17e8435

Please sign in to comment.