Skip to content

Commit

Permalink
Merge branch 'master' into install
Browse files Browse the repository at this point in the history
Conflicts:
	deps/Makefile
  • Loading branch information
Viral B. Shah committed May 27, 2012
2 parents f917c96 + cd3359c commit 8bad637
Show file tree
Hide file tree
Showing 17 changed files with 256 additions and 142 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ First, acquire the source code by cloning the git repository:
Next, enter the `julia/` directory and run `make` to build the `julia` executable. To perform a parallel build, use `make -j N` and supply the maximum number of concurrent processes.
When compiled the first time, it will automatically download and build its [external dependencies](#Required-Build-Tools-External-Libraries).
This takes a while, but only has to be done once.
Building julia requires 1.5GiB of diskspace and 512MiB of memory.
Building julia requires 1.5GiB of diskspace and approximately 700MiB of virtual memory.

**Note:** the build process will not work if any of the build directory's parent directories have spaces in their names (this is due to a limitation in GNU make).

Expand Down
71 changes: 58 additions & 13 deletions base/distributions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,27 @@ _jl_libRmath = dlopen("libRmath")
## var -> variance
## std -> standard deviation
## rand -> random sampler
ccdf(d::Distribution, q::Real) = 1 - cdf(d,q)
logpdf(d::ContinuousDistribution, x::Real) = log(pdf(d,x))
logpmf(d::DiscreteDistribution, x::Real) = log(pmf(d,x))
logcdf(d::Distribution, q::Real) = log(cdf(d,q))
logccdf(d::Distribution, q::Real) = log(ccdf(d,q))
cquantile(d::Distribution, p::Real) = quantile(d, 1-p)
invlogcdf(d::Distribution, lp::Real) = quantile(d, exp(lp))
invlogccdf(d::Distribution, lp::Real) = quantile(d, exp(-lp))
std(d::Distribution) = sqrt(var(d))
rand(d::Distribution, n::Int) = [rand(d) for i=1:n]
## Should we add?
## rand(d::DiscreteDistribution, n::Int) = [int(rand(d)) for i=1:n]
ccdf(d::Distribution, q::Real) = 1 - cdf(d,q)
logpdf(d::ContinuousDistribution, x::Real) = log(pdf(d,x))
logpmf(d::DiscreteDistribution, x::Real) = log(pmf(d,x))
logcdf(d::Distribution, q::Real) = log(cdf(d,q))
logccdf(d::Distribution, q::Real) = log(ccdf(d,q))
cquantile(d::Distribution, p::Real) = quantile(d, 1-p)
invlogcdf(d::Distribution, lp::Real) = quantile(d, exp(lp))
invlogccdf(d::Distribution, lp::Real) = quantile(d, exp(-lp))
std(d::Distribution) = sqrt(var(d))
function rand!(d::ContinuousDistribution, A::Array{Float64})
for i in 1:numel(A) A[i] = rand(d) end
A
end
rand(d::ContinuousDistribution, dims::Dims) = rand!(d, Array(Float64,dims))
rand(d::ContinuousDistribution, dims::Int...) = rand(d, dims)
function rand!(d::DiscreteDistribution, A::Array{Int})
for i in 1:numel(A) A[i] = int(rand(d)) end
A
end
rand(d::DiscreteDistribution, dims::Dims) = rand!(d, Array(Int,dims))
rand(d::DiscreteDistribution, dims::Int...) = rand(d, dims)

## FIXME: Replace the three _jl_dist_*p macros with one by defining
## the argument tuples for the ccall dynamically from pn
Expand Down Expand Up @@ -276,6 +285,8 @@ Beta() = Beta(1) # uniform
mean(d::Beta) = d.alpha / (d.alpha + d.beta)
var(d::Beta) = (ab = d.alpha + d.beta; d.alpha * d.beta /(ab * ab * (ab + 1.)))
skewness(d::Beta) = 2(d.beta - d.alpha)*sqrt(d.alpha + d.beta + 1)/((d.alpha + d.beta + 2)*sqrt(d.alpha*d.beta))
rand(d::Beta) = randbeta(d.alpha, d.beta)
rand!(d::Beta, A::Array{Float64}) = randbeta!(alpha, beta, A)

type BetaPrime <: ContinuousDistribution
alpha::Float64
Expand Down Expand Up @@ -321,6 +332,8 @@ mean(d::Chisq) = d.df
var(d::Chisq) = 2d.df
skewness(d::Chisq) = sqrt(8/d.df)
kurtosis(d::Chisq) = 12/d.df
rand(d::Chisq) = randchi2(d.df)
rand!(d::Chisq, A::Array{Float64}) = randchi2!(d.df, A)

type Erlang <: ContinuousDistribution
shape::Float64
Expand All @@ -332,12 +345,43 @@ type Exponential <: ContinuousDistribution
Exponential(sc) = sc > 0 ? new(float64(sc)) : error("scale must be positive")
end
Exponential() = Exponential(1.)
@_jl_dist_1p Exponential exp
mean(d::Exponential) = d.scale
median(d::Exponential) = d.scale * log(2.)
var(d::Exponential) = d.scale * d.scale
skewness(d::Exponential) = 2.
kurtosis(d::Exponential) = 6.
function cdf(d::Exponential, q::Real)
q <= 0. ? 0. : -expm1(-q/d.scale)
end
function logcdf(d::Exponential, q::Real)
q <= 0. ? -Inf : (qs = -q/d.scale; qs > log(0.5) ? log(-expm1(qs)) : log1p(-exp(qs)))
end
function ccdf(d::Exponential, q::Real)
q <= 0. ? 1. : exp(-q/d.scale)
end
function logccdf(d::Exponential, q::Real)
q <= 0. ? 0. : -q/d.scale
end
function pdf(d::Exponential, x::Real)
x <= 0. ? 0. : exp(-x/d.scale) / d.scale
end
function logpdf(d::Exponential, x::Real)
x <= 0. ? -Inf : (-x/d.scale) - log(d.scale)
end
function quantile(d::Exponential, p::Real)
0. <= p <= 1. ? -d.scale * log1p(-p) : NaN
end
function invlogcdf(d::Exponential, lp::Real)
lp <= 0. ? -d.scale * (lp > log(0.5) ? log(-expm1(lp)) : log1p(-exp(lp))) : NaN
end
function cquantile(d::Exponential, p::Real)
0. <= p <= 1. ? -d.scale * log(p) : NaN
end
function invlogccdf(d::Exponential, lp::Real)
lp <= 0. ? -d.scale * lp : NaN
end
rand(d::Exponential) = d.scale * randexp()
rand!(d::Exponential, A::Array{Float64}) = d.scale * randexp!(A)

type FDist <: ContinuousDistribution
ndf::Float64
Expand All @@ -360,6 +404,7 @@ mean(d::Gamma) = d.shape * d.scale
var(d::Gamma) = d.shape * d.scale * d.scale
skewness(d::Gamma) = 2/sqrt(d.shape)
rand(d::Gamma) = d.scale * randg(d.shape)
rand!(d::Gamma, A::Array{Float64}) = d.scale * randg!(d.shape, A)

type Geometric <: DiscreteDistribution # In the form of # of failures before the first success
prob::Float64
Expand Down
86 changes: 46 additions & 40 deletions base/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,42 +141,6 @@ itrunc(x::Integer) = x
ifloor(x::Integer) = x
iceil (x::Integer) = x

## integer promotions ##

promote_rule(::Type{Int16}, ::Type{Int8} ) = Int
promote_rule(::Type{Int32}, ::Type{Int8} ) = Int
promote_rule(::Type{Int32}, ::Type{Int16}) = Int
promote_rule(::Type{Int64}, ::Type{Int8} ) = Int64
promote_rule(::Type{Int64}, ::Type{Int16}) = Int64
promote_rule(::Type{Int64}, ::Type{Int32}) = Int64

promote_rule(::Type{Uint16}, ::Type{Uint8} ) = Uint
promote_rule(::Type{Uint32}, ::Type{Uint8} ) = Uint
promote_rule(::Type{Uint32}, ::Type{Uint16}) = Uint
promote_rule(::Type{Uint64}, ::Type{Uint8} ) = Uint64
promote_rule(::Type{Uint64}, ::Type{Uint16}) = Uint64
promote_rule(::Type{Uint64}, ::Type{Uint32}) = Uint64

promote_rule(::Type{Uint8} , ::Type{Int8} ) = Uint
promote_rule(::Type{Uint8} , ::Type{Int16}) = Uint
promote_rule(::Type{Uint8} , ::Type{Int32}) = Uint
promote_rule(::Type{Uint8} , ::Type{Int64}) = Uint64

promote_rule(::Type{Uint16}, ::Type{Int8} ) = Uint
promote_rule(::Type{Uint16}, ::Type{Int16}) = Uint
promote_rule(::Type{Uint16}, ::Type{Int32}) = Uint
promote_rule(::Type{Uint16}, ::Type{Int64}) = Uint64

promote_rule(::Type{Uint32}, ::Type{Int8} ) = Uint
promote_rule(::Type{Uint32}, ::Type{Int16}) = Uint
promote_rule(::Type{Uint32}, ::Type{Int32}) = Uint
promote_rule(::Type{Uint32}, ::Type{Int64}) = Uint64

promote_rule(::Type{Uint64}, ::Type{Int8} ) = Uint64
promote_rule(::Type{Uint64}, ::Type{Int16}) = Uint64
promote_rule(::Type{Uint64}, ::Type{Int32}) = Uint64
promote_rule(::Type{Uint64}, ::Type{Int64}) = Uint64

## integer arithmetic ##

-(x::Signed) = -int(x)
Expand Down Expand Up @@ -410,6 +374,52 @@ trailing_ones(x::Integer) = trailing_zeros(~x)
<=(x::Signed , y::Unsigned) = (x <= 0) | (unsigned(x) <= y)
<=(x::Unsigned, y::Signed ) = (y >= 0) & (x <= unsigned(y))

## system word size ##

const WORD_SIZE = int(Int.nbits)

## integer promotions ##

promote_rule(::Type{Int16}, ::Type{Int8} ) = Int
promote_rule(::Type{Int32}, ::Type{Int8} ) = Int
promote_rule(::Type{Int32}, ::Type{Int16}) = Int
promote_rule(::Type{Int64}, ::Type{Int8} ) = Int64
promote_rule(::Type{Int64}, ::Type{Int16}) = Int64
promote_rule(::Type{Int64}, ::Type{Int32}) = Int64

promote_rule(::Type{Uint16}, ::Type{Uint8} ) = Uint
promote_rule(::Type{Uint32}, ::Type{Uint8} ) = Uint
promote_rule(::Type{Uint32}, ::Type{Uint16}) = Uint
promote_rule(::Type{Uint64}, ::Type{Uint8} ) = Uint64
promote_rule(::Type{Uint64}, ::Type{Uint16}) = Uint64
promote_rule(::Type{Uint64}, ::Type{Uint32}) = Uint64

promote_rule(::Type{Uint8} , ::Type{Int8} ) = Int
promote_rule(::Type{Uint8} , ::Type{Int16}) = Int
promote_rule(::Type{Uint8} , ::Type{Int32}) = Int
promote_rule(::Type{Uint8} , ::Type{Int64}) = Int64

promote_rule(::Type{Uint16}, ::Type{Int8} ) = Int
promote_rule(::Type{Uint16}, ::Type{Int16}) = Int
promote_rule(::Type{Uint16}, ::Type{Int32}) = Int
promote_rule(::Type{Uint16}, ::Type{Int64}) = Int64

if WORD_SIZE == 64
promote_rule(::Type{Uint32}, ::Type{Int8} ) = Int
promote_rule(::Type{Uint32}, ::Type{Int16}) = Int
promote_rule(::Type{Uint32}, ::Type{Int32}) = Int
else
promote_rule(::Type{Uint32}, ::Type{Int8} ) = Uint
promote_rule(::Type{Uint32}, ::Type{Int16}) = Uint
promote_rule(::Type{Uint32}, ::Type{Int32}) = Uint
end
promote_rule(::Type{Uint32}, ::Type{Int64}) = Int64

promote_rule(::Type{Uint64}, ::Type{Int8} ) = Uint64
promote_rule(::Type{Uint64}, ::Type{Int16}) = Uint64
promote_rule(::Type{Uint64}, ::Type{Int32}) = Uint64
promote_rule(::Type{Uint64}, ::Type{Int64}) = Uint64

## traits ##

typemin(::Type{Int8 }) = int8(-128)
Expand Down Expand Up @@ -437,7 +447,3 @@ sizeof(::Type{Int32}) = 4
sizeof(::Type{Uint32}) = 4
sizeof(::Type{Int64}) = 8
sizeof(::Type{Uint64}) = 8

## system word size ##

const WORD_SIZE = int(Int.nbits)
4 changes: 2 additions & 2 deletions base/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# It defines functions in cases where sufficiently few assumptions about
# storage can be made.

#aCb(x::AbstractVector, y::AbstractVector)
#aTb{T<:Real}(x::AbstractVector{T}, y::AbstractVector{T})
#Ac_mul_B(x::AbstractVector, y::AbstractVector)
#At_mul_B{T<:Real}(x::AbstractVector{T}, y::AbstractVector{T})

#dot(x::AbstractVector, y::AbstractVector)

Expand Down
16 changes: 8 additions & 8 deletions base/linalg_blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function (*){T<:Union(Float64,Float32,Complex128,Complex64)}(A::StridedMatrix{T}
_jl_gemm('N', 'N', A, B)
end

function aTb{T<:Union(Float64,Float32,Complex128,Complex64)}(A::StridedMatrix{T},
function At_mul_B{T<:Union(Float64,Float32,Complex128,Complex64)}(A::StridedMatrix{T},
B::StridedMatrix{T})
if is(A, B) && size(A,1)>=500
_jl_syrk('T', A)
Expand All @@ -246,7 +246,7 @@ function aTb{T<:Union(Float64,Float32,Complex128,Complex64)}(A::StridedMatrix{T}
end
end

function abT{T<:Union(Float64,Float32,Complex128,Complex64)}(A::StridedMatrix{T},
function A_mul_Bt{T<:Union(Float64,Float32,Complex128,Complex64)}(A::StridedMatrix{T},
B::StridedMatrix{T})
if is(A, B) && size(A,2)>=500
_jl_syrk('N', A)
Expand All @@ -255,13 +255,13 @@ function abT{T<:Union(Float64,Float32,Complex128,Complex64)}(A::StridedMatrix{T}
end
end

function aTbT{T<:Union(Float64,Float32,Complex128,Complex64)}(A::StridedMatrix{T},
function At_mul_Bt{T<:Union(Float64,Float32,Complex128,Complex64)}(A::StridedMatrix{T},
B::StridedMatrix{T})
_jl_gemm('T', 'T', A, B)
end

aCb{T<:Union(Float64,Float32)}(A::StridedMatrix{T}, B::StridedMatrix{T}) = aTb(A, B)
function aCb{T<:Union(Complex128,Complex64)}(A::StridedMatrix{T},
Ac_mul_B{T<:Union(Float64,Float32)}(A::StridedMatrix{T}, B::StridedMatrix{T}) = At_mul_B(A, B)
function Ac_mul_B{T<:Union(Complex128,Complex64)}(A::StridedMatrix{T},
B::StridedMatrix{T})
if is(A, B) && size(A,1)>=500
_jl_herk('C', A)
Expand All @@ -270,8 +270,8 @@ function aCb{T<:Union(Complex128,Complex64)}(A::StridedMatrix{T},
end
end

abC{T<:Union(Float64,Float32)}(A::StridedMatrix{T}, B::StridedMatrix{T}) = abT(A, B)
function abC{T<:Union(Complex128,Complex64)}(A::StridedMatrix{T},
A_mul_Bc{T<:Union(Float64,Float32)}(A::StridedMatrix{T}, B::StridedMatrix{T}) = A_mul_Bt(A, B)
function A_mul_Bc{T<:Union(Complex128,Complex64)}(A::StridedMatrix{T},
B::StridedMatrix{T})
if is(A, B) && size(A,2)>=500
_jl_herk('N', A)
Expand All @@ -280,7 +280,7 @@ function abC{T<:Union(Complex128,Complex64)}(A::StridedMatrix{T},
end
end

function aCbC{T<:Union(Float64,Float32,Complex128,Complex64)}(A::StridedMatrix{T},
function Ac_mul_Bc{T<:Union(Float64,Float32,Complex128,Complex64)}(A::StridedMatrix{T},
B::StridedMatrix{T})
_jl_gemm('C', 'C', A, B)
end
Expand Down
4 changes: 2 additions & 2 deletions base/linalg_dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# note that many functions have specific versions for Float/Complex arguments
# which use BLAS instead

aCb(x::Vector, y::Vector) = [dot(x, y)]
aTb{T<:Real}(x::Vector{T}, y::Vector{T}) = [dot(x, y)]
Ac_mul_B(x::Vector, y::Vector) = [dot(x, y)]
At_mul_B{T<:Real}(x::Vector{T}, y::Vector{T}) = [dot(x, y)]

function dot(x::Vector, y::Vector)
s = zero(eltype(x))
Expand Down
38 changes: 19 additions & 19 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,27 @@ mod1{T<:Real}(x::T, y::T) = y-mod(y-x,y)
cmp{T<:Real}(x::T, y::T) = int(sign(x-y))

# transposed multiply
aCb (a,b) = ctranspose(a)*b
abC (a,b) = a*ctranspose(b)
aCbC(a,b) = ctranspose(a)*ctranspose(b)
aTb (a,b) = transpose(a)*b
abT (a,b) = a*transpose(b)
aTbT(a,b) = transpose(a)*transpose(b)
Ac_mul_B (a,b) = ctranspose(a)*b
A_mul_Bc (a,b) = a*ctranspose(b)
Ac_mul_Bc(a,b) = ctranspose(a)*ctranspose(b)
At_mul_B (a,b) = transpose(a)*b
A_mul_Bt (a,b) = a*transpose(b)
At_mul_Bt(a,b) = transpose(a)*transpose(b)

# transposed divide
aC_rdiv_b (a,b) = ctranspose(a)/b
a_rdiv_bC (a,b) = a/ctranspose(b)
aC_rdiv_bC(a,b) = ctranspose(a)/ctranspose(b)
aT_rdiv_b (a,b) = transpose(a)/b
a_rdiv_bT (a,b) = a/transpose(b)
aT_rdiv_bT(a,b) = transpose(a)/transpose(b)

aC_ldiv_b (a,b) = ctranspose(a)\b
a_ldiv_bC (a,b) = a\ctranspose(b)
aC_ldiv_bC(a,b) = ctranspose(a)\ctranspose(b)
aT_ldiv_b (a,b) = transpose(a)\b
a_ldiv_bT (a,b) = a\transpose(b)
aT_ldiv_bT(a,b) = transpose(a)\transpose(b)
Ac_rdiv_B (a,b) = ctranspose(a)/b
A_rdiv_Bc (a,b) = a/ctranspose(b)
Ac_rdiv_Bc(a,b) = ctranspose(a)/ctranspose(b)
At_rdiv_B (a,b) = transpose(a)/b
A_rdiv_Bt (a,b) = a/transpose(b)
At_rdiv_Bt(a,b) = transpose(a)/transpose(b)

Ac_ldiv_B (a,b) = ctranspose(a)\b
A_ldiv_Bc (a,b) = a\ctranspose(b)
Ac_ldiv_Bc(a,b) = ctranspose(a)\ctranspose(b)
At_ldiv_B (a,b) = transpose(a)\b
A_ldiv_Bt (a,b) = a\transpose(b)
At_ldiv_Bt(a,b) = transpose(a)\transpose(b)


oftype{T}(::Type{T},c) = convert(T,c)
Expand Down
Loading

0 comments on commit 8bad637

Please sign in to comment.