Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: RNG cleanups #2070

Merged
merged 13 commits into from
Jan 22, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ function bitarray_rand_fill!(B::BitArray)
end
Bc = B.chunks
for i = 1 : length(Bc) - 1
Bc[i] = randi(Uint64)
Bc[i] = rand(Uint64)
end
msk = @_msk_end length(B)
Bc[end] = msk & randi(Uint64)
Bc[end] = msk & rand(Uint64)
return B
end

Expand Down
6 changes: 3 additions & 3 deletions base/combinatorics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pascal(n) = [binomial(i+j-2,i-1) for i=1:n,j=1:n]

function shuffle!(a::AbstractVector)
for i = length(a):-1:2
j = randi(i)
j = rand(1:i)
a[i], a[j] = a[j], a[i]
end
return a
Expand All @@ -76,7 +76,7 @@ function randperm(n::Integer)
a = Array(typeof(n), n)
a[1] = 1
for i = 2:n
j = randi(i)
j = rand(1:i)
a[i] = a[j]
a[j] = i
end
Expand All @@ -87,7 +87,7 @@ function randcycle(n::Integer)
a = Array(typeof(n), n)
a[1] = 1
for i = 2:n
j = randi(i-1)
j = rand(1:i-1)
a[i] = a[j]
a[j] = i
end
Expand Down
23 changes: 20 additions & 3 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ end
@deprecate idump xdump
@deprecate cwd pwd
@deprecate strlen length
@deprecate chi2rnd randchi2
@deprecate betarnd randbeta
@deprecate exprnd randexp
@deprecate islogical isbool
@deprecate csvread readcsv
@deprecate dlmread readdlm
Expand All @@ -35,3 +32,23 @@ end
@deprecate uc uppercase
@deprecate nCr binomial
@deprecate julia_pkgdir Pkg.dir
@deprecate chi2rnd randchi2
@deprecate betarnd randbeta
@deprecate exprnd randexp

randi(x...) = error("randi is deprecated. Instead use: rand(r::Range)")

randival(x...) = error("randi is deprecated. Instead use: rand(r::Range)")

randexp(x...) = error("randexp is deprecated. Instead use the Distributions package:
using Distributions; rand(Exponential())")

randg(x...) = error("randg is deprecated. Instead use the Distributions package:
using Distributions; rand(Gamma())")

randbeta(x...) = error("randbeta is deprecated. Instead use the Distributions package:
using Distributions; rand(Beta)")

randchi2(x...) = error("randbeta is deprecated. Instead use the Distributions package:
using Distributions; rand(Chisq())")

43 changes: 20 additions & 23 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export
LAPACK,
BLAS,
LibRandom,
RNG,
Random,
Math,
Sort,
Test,
Expand Down Expand Up @@ -935,7 +935,25 @@ export
info,
warn,

# statistics and random numbers
# random numbers
AbstractRNG,
MersenneTwister,
rand!,
rand,
randbool!,
randbool,
randn!,
randn,
# deprecated stuff
randbeta,
randchi2,
randexp,
randg,
randg2,
randi,
randival,

# statistics
autocor,
cor,
cor_pearson,
Expand All @@ -957,28 +975,7 @@ export
quantile,
quartile,
quintile,
rand!,
rand,
randbeta!,
randbeta,
randbool!,
randbool,
randchi2!,
randchi2,
randexp!,
randexp,
randg!,
randg,
randg2,
randi!,
randi,
randival!,
randival,
randn!,
randn,
rle,
Rng,
Rng_MT,
skewness,
srand,
std,
Expand Down
2 changes: 1 addition & 1 deletion base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ end
end

@windows_only function mktempdir()
seed = randi(Uint32)
seed = rand(Uint32)
while true
filename = GetTempFileName(seed)
ret = ccall(:_mkdir, Int32, (Ptr{Uint8},), filename)
Expand Down
75 changes: 35 additions & 40 deletions base/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ end
# gegp3 - pivoted QR decomposition
# gerqf - unpivoted RQ decomposition
# getrf - LU decomposition
for (gebrd, gelqf, geqlf, geqrf, geqp3, gerqf, getrf, elty) in
((:dgebrd_,:dgelqf_,:dgeqlf_,:dgeqrf_,:dgeqp3_,:dgerqf_,:dgetrf_,:Float64),
(:sgebrd_,:sgelqf_,:sgeqlf_,:sgeqrf_,:sgeqp3_,:sgerqf_,:sgetrf_,:Float32),
(:zgebrd_,:zgelqf_,:zgeqlf_,:zgeqrf_,:zgeqp3_,:zgerqf_,:zgetrf_,:Complex128),
(:cgebrd_,:cgelqf_,:cgeqlf_,:cgeqrf_,:cgeqp3_,:cgerqf_,:cgetrf_,:Complex64))
for (gebrd, gelqf, geqlf, geqrf, geqp3, gerqf, getrf, elty, relty) in
((:dgebrd_,:dgelqf_,:dgeqlf_,:dgeqrf_,:dgeqp3_,:dgerqf_,:dgetrf_,:Float64,:Float64),
(:sgebrd_,:sgelqf_,:sgeqlf_,:sgeqrf_,:sgeqp3_,:sgerqf_,:sgetrf_,:Float32,:Float32),
(:zgebrd_,:zgelqf_,:zgeqlf_,:zgeqrf_,:zgeqp3_,:zgerqf_,:zgetrf_,:Complex128,:Float64),
(:cgebrd_,:cgelqf_,:cgeqlf_,:cgeqrf_,:cgeqp3_,:cgerqf_,:cgetrf_,:Complex64,:Float32))
@eval begin
# SUBROUTINE DGEBRD( M, N, A, LDA, D, E, TAUQ, TAUP, WORK, LWORK,
# INFO )
Expand Down Expand Up @@ -248,15 +248,14 @@ for (gebrd, gelqf, geqlf, geqrf, geqp3, gerqf, getrf, elty) in
work = Array($elty, 1)
lwork = blas_int(-1)
info = Array(BlasInt, 1)
Rtyp = typeof(real(A[1]))
cmplx = iscomplex(A)
if cmplx rwork = Array(Rtyp, 2n) end
if cmplx; rwork = Array($relty, 2n); end
for i in 1:2
if cmplx
ccall(($(string(geqp3)),liblapack), Void,
(Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt},
Ptr{Rtyp}, Ptr{BlasInt}),
Ptr{$relty}, Ptr{BlasInt}),
&m, &n, A, &stride(A,2), jpvt, tau, work, &lwork, rwork, info)
else
ccall(($(string(geqp3)),liblapack), Void,
Expand Down Expand Up @@ -455,8 +454,8 @@ for (gels, gesv, getrs, getri, elty) in
end
end
end
for (gelsd, elty) in ((:dgelsd_, Float64),
(:sgelsd_, Float32))
for (gelsd, elty) in ((:dgelsd_, :Float64),
(:sgelsd_, :Float32))
@eval begin
# SUBROUTINE DGELSD( M, N, NRHS, A, LDA, B, LDB, S, RCOND, RANK,
# $ WORK, LWORK, IWORK, INFO )
Expand Down Expand Up @@ -503,8 +502,8 @@ for (gelsd, elty) in ((:dgelsd_, Float64),
gelsd!(A::StridedMatrix{$elty}, B::StridedVecOrMat{$elty}) = gelsd!(A, B, -1.)
end
end
for (gelsd, elty, relty) in ((:zgelsd_, Complex128, Float64),
(:cgelsd_, Complex64, Float32))
for (gelsd, elty, relty) in ((:zgelsd_, :Complex128, :Float64),
(:cgelsd_, :Complex64, :Float32))
@eval begin
# SUBROUTINE ZGELSD( M, N, NRHS, A, LDA, B, LDB, S, RCOND, RANK,
# $ WORK, LWORK, RWORK, IWORK, INFO )
Expand Down Expand Up @@ -556,11 +555,11 @@ for (gelsd, elty, relty) in ((:zgelsd_, Complex128, Float64),
end

# (GE) general matrices eigenvalue-eigenvector and singular value decompositions
for (geev, gesvd, gesdd, elty) in
((:dgeev_,:dgesvd_,:dgesdd_,:Float64),
(:sgeev_,:sgesvd_,:sgesdd_,:Float32),
(:zgeev_,:zgesvd_,:zgesdd_,:Complex128),
(:cgeev_,:cgesvd_,:cgesdd_,:Complex64))
for (geev, gesvd, gesdd, elty, relty) in
((:dgeev_,:dgesvd_,:dgesdd_,:Float64,Float64),
(:sgeev_,:sgesvd_,:sgesdd_,:Float32,:Float32),
(:zgeev_,:zgesvd_,:zgesdd_,:Complex128,:Float64),
(:cgeev_,:cgesvd_,:cgesdd_,:Complex64,:Float32))
@eval begin
# SUBROUTINE DGEEV( JOBVL, JOBVR, N, A, LDA, WR, WI, VL, LDVL, VR,
# $ LDVR, WORK, LWORK, INFO )
Expand All @@ -578,11 +577,10 @@ for (geev, gesvd, gesdd, elty) in
rvecs = jobvr == 'V'
VL = Array($elty, (n, lvecs ? n : 0))
VR = Array($elty, (n, rvecs ? n : 0))
Rtyp = typeof(real(A[1]))
cmplx = iscomplex(A)
if cmplx
W = Array($elty, n)
rwork = Array(Rtyp, 2n)
rwork = Array($relty, 2n)
else
WR = Array($elty, n)
WI = Array($elty, n)
Expand All @@ -596,7 +594,7 @@ for (geev, gesvd, gesdd, elty) in
(Ptr{Uint8}, Ptr{Uint8}, Ptr{BlasInt}, Ptr{$elty},
Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt},
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
Ptr{Rtyp}, Ptr{BlasInt}),
Ptr{$relty}, Ptr{BlasInt}),
&jobvl, &jobvr, &n, A, &stride(A,2), W, VL, &n, VR, &n,
work, &lwork, rwork, info)
else
Expand Down Expand Up @@ -645,11 +643,10 @@ for (geev, gesvd, gesdd, elty) in
end
work = Array($elty, 1)
lwork = blas_int(-1)
Rtyp = typeof(real(A[1]))
S = Array(Rtyp, minmn)
S = Array($relty, minmn)
cmplx = iscomplex(A)
if cmplx
rwork = Array(Rtyp, job == 'N' ? 7*minmn : 5*minmn*minmn + 5*minmn)
rwork = Array($relty, job == 'N' ? 7*minmn : 5*minmn*minmn + 5*minmn)
end
iwork = Array(BlasInt, 8*minmn)
info = Array(BlasInt, 1)
Expand All @@ -659,7 +656,7 @@ for (geev, gesvd, gesdd, elty) in
(Ptr{Uint8}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty},
Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt},
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
Ptr{Rtyp}, Ptr{BlasInt}, Ptr{BlasInt}),
Ptr{$relty}, Ptr{BlasInt}, Ptr{BlasInt}),
&job, &m, &n, A, &stride(A,2), S, U, &max(1,stride(U,2)), VT, &max(1,stride(VT,2)),
work, &lwork, rwork, iwork, info)
else
Expand Down Expand Up @@ -693,15 +690,14 @@ for (geev, gesvd, gesdd, elty) in
# $ VT( LDVT, * ), WORK( * )
function gesvd!(jobu::BlasChar, jobvt::BlasChar, A::StridedMatrix{$elty})
chkstride1(A)
Rtyp = typeof(real(A[1]))
m, n = size(A)
minmn = min(m, n)
S = Array(Rtyp, minmn)
S = Array($relty, minmn)
U = Array($elty, jobu == 'A'? (m, m):(jobu == 'S'? (m, minmn) : (m, 0)))
VT = Array($elty, jobvt == 'A'? (n, n):(jobvt == 'S'? (minmn, n) : (n, 0)))
work = Array($elty, 1)
cmplx = iscomplex(A)
if cmplx rwork = Array(Rtyp, 5minmn) end
if cmplx; rwork = Array($relty, 5minmn); end
lwork = blas_int(-1)
info = Array(BlasInt, 1)
for i in 1:2
Expand All @@ -710,7 +706,7 @@ for (geev, gesvd, gesdd, elty) in
(Ptr{Uint8}, Ptr{Uint8}, Ptr{BlasInt}, Ptr{BlasInt},
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty},
Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty},
Ptr{BlasInt}, Ptr{Rtyp}, Ptr{BlasInt}),
Ptr{BlasInt}, Ptr{$relty}, Ptr{BlasInt}),
&jobu, &jobvt, &m, &n, A, &stride(A,2), S, U, &max(1,stride(U,2)), VT, &max(1,stride(VT,2)),
work, &lwork, rwork, info)
else
Expand Down Expand Up @@ -1130,7 +1126,7 @@ end
## (TR) triangular matrices: solver and inverse
for (trtri, trtrs, elty) in
((:dtrtri_,:dtrtrs_,:Float64),
(:strtri_,:strtrs_,Float32),
(:strtri_,:strtrs_,:Float32),
(:ztrtri_,:ztrtrs_,:Complex128),
(:ctrtri_,:ctrtrs_,:Complex64))
@eval begin
Expand Down Expand Up @@ -1203,11 +1199,11 @@ end

## (SY) symmetric matrices - eigendecomposition, Bunch-Kaufman decomposition,
## solvers (direct and factored) and inverse.
for (syconv, syev, sysv, sytrf, sytri, sytrs, elty) in
((:dsyconv_,:dsyev_,:dsysv_,:dsytrf_,:dsytri_,:dsytrs_,:Float64),
(:ssyconv_,:ssyev_,:ssysv_,:ssytrf_,:ssytri_,:ssytrs_,:Float32),
(:zheconv_,:zheev_,:zhesv_,:zhetrf_,:zhetri_,:zhetrs_,:Complex128),
(:checonv_,:cheev_,:chesv_,:chetrf_,:chetri_,:chetrs_,:Complex64))
for (syconv, syev, sysv, sytrf, sytri, sytrs, elty, relty) in
((:dsyconv_,:dsyev_,:dsysv_,:dsytrf_,:dsytri_,:dsytrs_,:Float64, :Float64),
(:ssyconv_,:ssyev_,:ssysv_,:ssytrf_,:ssytri_,:ssytrs_,:Float32, :Float32),
(:zheconv_,:zheev_,:zhesv_,:zhetrf_,:zhetri_,:zhetrs_,:Complex128, :Float64),
(:checonv_,:cheev_,:chesv_,:chetrf_,:chetri_,:chetrs_,:Complex64, :Float32))
@eval begin
# SUBROUTINE DSYCONV( UPLO, WAY, N, A, LDA, IPIV, WORK, INFO )
# * .. Scalar Arguments ..
Expand Down Expand Up @@ -1239,25 +1235,24 @@ for (syconv, syev, sysv, sytrf, sytri, sytrs, elty) in
chkstride1(A)
chksquare(A)
cmplx = iscomplex(A)
Rtyp = typeof(real(A[1]))
n = size(A, 1)
W = Array(Rtyp, n)
W = Array($relty, n)
work = Array($elty, 1)
lwork = blas_int(-1)
if cmplx
rwork = Array(Rtyp, max(1, 3n-2))
rwork = Array($relty, max(1, 3n-2))
end
info = Array(BlasInt, 1)
for i in 1:2
if cmplx
ccall(($(string(syev)),liblapack), Void,
(Ptr{Uint8}, Ptr{Uint8}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
Ptr{Rtyp}, Ptr{$elty}, Ptr{BlasInt}, Ptr{Rtyp}, Ptr{BlasInt}),
Ptr{$relty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$relty}, Ptr{BlasInt}),
&jobz, &uplo, &n, A, &stride(A,2), W, work, &lwork, rwork, info)
else
ccall(($(string(syev)),liblapack), Void,
(Ptr{Uint8}, Ptr{Uint8}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
Ptr{Rtyp}, Ptr{$elty}, Ptr{BlasInt}, Ptr{BlasInt}),
Ptr{$relty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{BlasInt}),
&jobz, &uplo, &n, A, &stride(A,2), W, work, &lwork, info)
end
if info[1] != 0 throw(LapackException(info[1])) end
Expand Down Expand Up @@ -1777,4 +1772,4 @@ for (gees, elty, relty) in
end
end
end
end # module
end # module
Loading