Skip to content
Browse files

Merge branch 'master' of github.com:JuliaLang/julia

Conflicts:
	.gitmodules
	Makefile
	base/file.jl
	base/io.jl
	base/math_libm.jl
	base/show.jl
	base/start_image.jl
	deps/Makefile
	deps/fdlibm/CMakeLists.txt
	deps/openlibm
	extras/iostring.jl
	test/Makefile
	test/file.jl
  • Loading branch information...
2 parents e59566e + f30c586 commit a8ee9c0135aefa0eb408102aef849dc063eb8d5b @vtjnash vtjnash committed
Showing with 1,141 additions and 7,422 deletions.
  1. +2 −2 .gitmodules
  2. +16 −0 .mailmap
  3. +42 −0 CONTRIBUTING.md
  4. +1 −1 LICENSE.md
  5. +10 −5 Makefile
  6. +7 −7 README.md
  7. +46 −16 base/abstractarray.jl
  8. +14 −20 base/array.jl
  9. +1 −1 base/ascii.jl
  10. +9 −5 base/base.jl
  11. +15 −0 base/blas.jl
  12. +1 −1 base/bool.jl
  13. +1 −1 base/boot.jl
  14. +4 −0 base/client.jl
  15. +3 −0 base/complex.jl
  16. +4 −19 base/deepcopy.jl
  17. +29 −22 base/dict.jl
  18. +2 −1 base/error.jl
  19. +15 −5 base/export.jl
  20. +53 −26 base/file.jl
  21. +1 −1 base/float.jl
  22. +40 −24 base/inference.jl
  23. +187 −130 base/io.jl
  24. +4 −4 base/iterator.jl
  25. +116 −6 base/lapack.jl
  26. +2 −2 base/librandom.jl
  27. +3 −7 base/linalg.jl
  28. +85 −8 base/linalg_dense.jl
  29. +153 −26 base/math.jl
  30. +0 −156 base/math_libm.jl
  31. +12 −8 base/multi.jl
  32. +11 −11 base/operators.jl
  33. +10 −10 base/osutils.jl
  34. +15 −15 base/pkg.jl
  35. +1 −1 base/pkgmetadata.jl
  36. +2 −0 base/rational.jl
  37. +3 −3 base/rng.jl
  38. +6 −5 base/serialize.jl
  39. +40 −32 base/show.jl
  40. +3 −4 base/start_image.jl
  41. +9 −7 base/sysimg.jl
  42. +7 −2 base/tuple.jl
  43. +2 −2 base/utf8.jl
  44. +11 −10 base/util.jl
  45. +110 −39 contrib/julia.xml
  46. +32 −52 deps/Makefile
  47. +1 −1 deps/Versions.make
  48. +0 −4 deps/fdlibm/.gitignore
  49. +0 −167 deps/fdlibm/CMakeLists.txt
  50. +0 −130 deps/fdlibm/b_exp.c
  51. +0 −403 deps/fdlibm/b_log.c
  52. +0 −320 deps/fdlibm/b_tgamma.c
  53. +0 −77 deps/fdlibm/changes
  54. +0 −107 deps/fdlibm/e_acos.c
  55. +0 −77 deps/fdlibm/e_acosf.c
  56. +0 −65 deps/fdlibm/e_acosh.c
  57. +0 −45 deps/fdlibm/e_acoshf.c
  58. +0 −116 deps/fdlibm/e_asin.c
  59. +0 −80 deps/fdlibm/e_asinf.c
  60. +0 −125 deps/fdlibm/e_atan2.c
  61. +0 −93 deps/fdlibm/e_atan2f.c
  62. +0 −67 deps/fdlibm/e_atanh.c
  63. +0 −41 deps/fdlibm/e_atanhf.c
  64. +0 −89 deps/fdlibm/e_cosh.c
  65. +0 −60 deps/fdlibm/e_coshf.c
  66. +0 −162 deps/fdlibm/e_exp.c
  67. +0 −92 deps/fdlibm/e_expf.c
  68. +0 −136 deps/fdlibm/e_fmod.c
  69. +0 −101 deps/fdlibm/e_fmodf.c
  70. +0 −33 deps/fdlibm/e_gamma.c
  71. +0 −32 deps/fdlibm/e_gamma_r.c
  72. +0 −122 deps/fdlibm/e_hypot.c
  73. +0 −79 deps/fdlibm/e_hypotf.c
  74. +0 −479 deps/fdlibm/e_j0.c
  75. +0 −336 deps/fdlibm/e_j0f.c
  76. +0 −478 deps/fdlibm/e_j1.c
  77. +0 −332 deps/fdlibm/e_j1f.c
  78. +0 −273 deps/fdlibm/e_jn.c
  79. +0 −191 deps/fdlibm/e_jnf.c
  80. +0 −33 deps/fdlibm/e_lgamma.c
  81. +0 −305 deps/fdlibm/e_lgamma_r.c
  82. +0 −231 deps/fdlibm/e_lgammaf_r.c
  83. +0 −138 deps/fdlibm/e_log.c
  84. +0 −90 deps/fdlibm/e_log10.c
  85. +0 −51 deps/fdlibm/e_log10f.c
  86. +0 −74 deps/fdlibm/e_log2.c
  87. +0 −76 deps/fdlibm/e_log2f.c
  88. +0 −81 deps/fdlibm/e_logf.c
  89. +0 −312 deps/fdlibm/e_pow.c
  90. +0 −241 deps/fdlibm/e_powf.c
  91. +0 −180 deps/fdlibm/e_rem_pio2.c
Sorry, we could not display the entire diff because too many files (363) changed.
View
4 .gitmodules
@@ -3,7 +3,7 @@
url = git://github.com/JuliaLang/libuv.git
[submodule "deps/openlibm"]
path = deps/openlibm
- url = http://github.com/JuliaLang/openlibm.git
+ url = git://github.com/JuliaLang/openlibm.git
[submodule "deps/nginx"]
path = deps/nginx
- url = https://github.com/git-mirror/nginx
+ url = git://github.com/git-mirror/nginx
View
16 .mailmap
@@ -70,3 +70,19 @@ Andreas Noack Jensen <andreasnoackjensen@gmail.com> <andreas@Andreass-MacBook-Pr
Westley Argentum Hennigh <WestleyArgentum@gmail.com> <WestleyArgentum@gmail.com>
Westley Argentum Hennigh <WestleyArgentum@gmail.com> <whennigh@forio.com>
+
+George V. Neville-Neil <gnn@freebsd.org> <gnn@freebsd.org>
+George V. Neville-Neil <gnn@freebsd.org> <gvnn3>
+
+Alessandro Andrioni Silva <alessandroandrioni@gmail.com> <alessandroandrioni@gmail.com>
+Alessandro Andrioni Silva <alessandroandrioni@gmail.com> <jakedust@gmail.com>
+
+Toivo Henningsson <toivo.h.h@gmail.com> <toivo.h.h@gmail.com>
+Toivo Henningsson <toivo.h.h@gmail.com> <toivo@control.lth.se>
+
+Adam Savitzky <adam.savitzky@gmail.com> <adam.savitzky@gmail.com>
+Adam Savitzky <adam.savitzky@gmail.com> <asavitzky@forio.com>
+
+David Slate <dslate@speakeasy.net> <dslate@speakeasy.net>
+
+Francois Pepin <fpepin@gmail.com> <fpepin@gmail.com>
View
42 CONTRIBUTING.md
@@ -0,0 +1,42 @@
+Hi! Thanks for checking out Julia. If you have questions or problems, the [Julia dev list](https://groups.google.com/forum/?fromgroups#!forum/julia-dev) is a good place to post them, but you should check out the [online Julia docs](http://docs.julialang.org/en/latest/) first. If you have changes you'd like to contribute, you'll need a [free GitHub account](https://github.com/signup/free). (If you're reading this on GitHub, you probably already have one.) You'll also want a working copy of Julia, built from source (you can still contribute with a binary install, but it's harder and not really recommended). In list form, here's what to do to become a contributor:
+
+* Join the [dev list](https://groups.google.com/forum/?fromgroups#!forum/julia-dev).
+
+* Create a [GitHub account](https://github.com/signup/free).
+
+* [Fork Julia](https://github.com/JuliaLang/julia/fork_select).
+
+* Build the software and libraries (the first time takes a while, but it's fast after that). Detailed build instructions are in the [README](https://github.com/JuliaLang/julia/tree/master/README.md). Julia depends on several external packages; most are automatically downloaded and installed, but are less frequently updated than Julia itself.
+
+* Keep Julia current. Julia is a fast-moving target, and many details of the language are still settling out. Keep your repository up-to-date and rebase your work in progress frequently.
+
+* Relax and have fun.
+
+## Submitting your contributions
+
+The Julia team uses [GitHub issues](https://github.com/JuliaLang/julia/issues) to track and discuss problems, feature requests, and pull requests.
+
+You can make pull requests for incomplete features to get code review, in which case we have a convention of prefixing the pull request title with "RFC:" to indicate that the work is incomplete so it doesn't accidentally get merged into the master branch before it's ready.
+
+Before submitting, make sure that all tests pass by running `make testall`. Even better, add your own tests for your change or feature to the test files in `tests/`. If your contribution includes changes to Makefiles or external dependencies, make sure you can build Julia from a clean tree using `git clean -fdx` or equivalent (be careful – this command will delete any files lying around that aren't checked into git).
+
+*By contributing code to Julia, you are agreeing to release it under the [MIT License](https://github.com/JuliaLang/julia/tree/master/LICENSE.md).*
+
+## Getting help
+
+While getting familiar with Julia, remember to check out [the docs](http://docs.julialang.org/en/latest/), keeping in mind that they are [searchable](http://docs.julialang.org/en/latest/search/). (If you use a script blocker then you'll have to unblock that page.) The [source code](https://github.com/JuliaLang/julia) is an excellent source of examples (and it's mostly pretty approachable). If you're still stumped, post something on [the dev list](https://groups.google.com/forum/?fromgroups#!forum/julia-dev), but you may want to search the archives first to see if there's already been a discussion about what you're stuck on.
+
+## Resources
+
+* Julia
+ - [Julia](http://julialang.org)
+ - [Julia Manual and Library Guide](http://docs.julialang.org/en/latest/)
+ - [Julia dev list](https://groups.google.com/forum/?fromgroups#!forum/julia-dev)
+* Working with Types
+ - [Some Type Patterns](https://github.com/JuliaLang/julia/wiki/Code-Patterns)
+ - [The Type Hierarchy](https://github.com/JuliaLang/julia/wiki/Types-Hierarchy)
+* Using GitHub
+ - [Using Julia with GitHub (video)](http://www.youtube.com/watch?v=wnFYV3ZKtOg&feature=youtu.be)
+ - [Using Julia on GitHub (notes for video)](https://gist.github.com/2712118#file_julia_git_pull_request.md)
+ - [General GitHub documentation](http://help.github.com/)
+ - [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
View
2 LICENSE.md
@@ -49,7 +49,7 @@ External libraries, if used, include their own licenses:
- [D3](https://github.com/mbostock/d3/raw/master/LICENSE)
- [DOUBLE-CONVERSION](https://code.google.com/p/double-conversion/)
- [DSFMT](http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/LICENSE.txt)
-- [FDLIBM](http://www.netlib.org/fdlibm/fdlibm.h)
+- [OPENLIBM](https://github.com/JuliaLang/openlibm/blob/master/LICENSE.md)
- [FEMTOLISP](https://github.com/JeffBezanson/femtolisp)
- [FFTW](http://fftw.org/doc/License-and-Copyright.html)
- [GLPK](http://www.gnu.org/software/glpk)
View
15 Makefile
@@ -4,12 +4,13 @@ include $(JULIAHOME)/Make.inc
all: default
default: release
-DIRS = $(BUILD)/bin $(BUILD)/etc $(BUILD)/lib/julia
+DIRS = $(BUILD)/bin $(BUILD)/etc $(BUILD)/lib/julia $(BUILD)/share/julia
$(foreach dir,$(DIRS),$(eval $(call dir_target,$(dir))))
-$(foreach link,extras base ui,$(eval $(call symlink_target,$(link),$(BUILD)/lib/julia)))
+$(foreach link,extras base ui test,$(eval $(call symlink_target,$(link),$(BUILD)/lib/julia)))
+$(foreach link,doc examples,$(eval $(call symlink_target,$(link),$(BUILD)/share/julia)))
-debug release: | $(DIRS) $(BUILD)/lib/julia/extras $(BUILD)/lib/julia/base $(BUILD)/lib/julia/ui
+debug release: | $(DIRS) $(BUILD)/lib/julia/extras $(BUILD)/lib/julia/base $(BUILD)/lib/julia/ui $(BUILD)/lib/julia/test $(BUILD)/share/julia/doc $(BUILD)/share/julia/examples
@$(MAKE) -s julia-$@
@$(MAKE) JULIA_EXECUTABLE=$(JULIA_EXECUTABLE_$@) -s $(BUILD)/lib/julia/sys.ji
@@ -31,15 +32,19 @@ $(BUILD)/lib/julia/sys.ji: VERSION base/*.jl $(BUILD)/lib/julia/helpdb.jl
PREFIX ?= julia-$(JULIA_COMMIT)
install: release
- mkdir -p $(PREFIX)/{sbin,bin,etc,lib/julia,share/julia}
+ @$(MAKE) -sC test/unicode
+ for subdir in "sbin" "bin" "etc" "lib/julia" "share/julia" ; do \
+ mkdir -p $(PREFIX)/$$subdir ; \
+ done
cp $(BUILD)/bin/*julia* $(PREFIX)/bin
cd $(PREFIX)/bin && ln -s julia-release-$(DEFAULT_REPL) julia
cp -R -L $(BUILD)/lib/julia/* $(PREFIX)/lib/julia
- -cp $(BUILD)/lib/lib{Rmath,amd,amos,arpack,cholmod,colamd,suitesparseconfig,fdm,fftw3,fftw3f,fftw3_threads,fftw3f_threads,glpk,glpk_wrapper,gmp,gmp_wrapper,grisu,history,julia-release,openblas,openlibm,pcre,random,readline,suitesparse_wrapper,umfpack,z}.$(SHLIB_EXT) $(PREFIX)/lib
+ -cp $(BUILD)/lib/lib{Rmath,amd,amos,arpack,cholmod,colamd,suitesparseconfig,fdm,openlibm,fftw3,fftw3f,fftw3_threads,fftw3f_threads,glpk,glpk_wrapper,gmp,gmp_wrapper,grisu,history,julia-release,openblas,pcre,random,readline,suitesparse_wrapper,tk_wrapper,umfpack,z}.$(SHLIB_EXT) $(PREFIX)/lib
# Web-REPL stuff
-cp $(BUILD)/lib/mod* $(PREFIX)/lib
-cp $(BUILD)/sbin/* $(PREFIX)/sbin
-cp $(BUILD)/etc/* $(PREFIX)/etc
+ -cp -R -L $(BUILD)/share/* $(PREFIX)/share
ifeq ($(OS), WINNT)
-cp dist/windows/* $(PREFIX)
ifeq ($(shell uname),MINGW32_NT-6.1)
View
14 README.md
@@ -29,9 +29,11 @@ This is the GitHub repository of Julia source code, including instructions for c
<a name="Currently-Supported-Platforms"/>
## Currently Supported Platforms
-- **GNU/Linux:** x86/64 (64-bit); x86 (32-bit).
-- **Darwin/OS X:** x86/64 (64-bit); x86 (32-bit).
-- **FreeBSD:** x86/64 (64-bit); x86 (32-bit).
+- **GNU/Linux**
+- **Darwin/OS X**
+- **FreeBSD**
+
+All systems are supported with both x86/64 (64-bit) and x86 (32-bit) architectures. [Julia has been ported to Windows](https://github.com/loladiro/julia) as well, and Windows support will be merged into the julia mainline once it stabilizes.
<a name="Source-Download-Compilation"/>
## Source Download & Compilation
@@ -75,8 +77,6 @@ If the build fails trying to compile OpenBLAS, set OPENBLAS_TARGET_ARCH to BARCE
On some Linux distributions you may need to change how the readline library is linked. If you get a build error involving readline, try changing the value of `USE_SYSTEM_READLINE` in `Make.inc` to `1`.
-Chinese users should replace line 798 in `deps/Makefile` with "$(WGET) ftp://ftp.gnu.org/gnu/gmp/gmp-$(GMP_VER)/$@" due to IP block .(original line 798 "$(WGET) ftp://ftp.gmplib.org/pub/gmp-$(GMP_VER)/$@")
-
On Ubuntu systems, you may also need to install the package `libncurses5-dev`.
On CentOS 5 systems, the default compiler (gcc 4.1) is too old to build julia.
@@ -127,7 +127,7 @@ Julia uses the following external libraries, which are automatically downloaded
- **[LLVM]** — compiler infrastructure. Currently, julia requires LLVM 3.1.
- **[FemtoLisp]** — packaged with julia source, and used to implement the compiler front-end.
- **[readline]** — library allowing shell-like line editing in the terminal, with history and familiar key bindings.
-- **[fdlibm]** — a portable implementation of much of the system-dependent libm math library's functionality.
+- **[OpenLibm]** — a portable libm library containing elementary math functions.
- **[DSFMT]** — a fast Mersenne Twister pseudorandom number generator library.
- **[OpenBLAS]** — a fast, open, and maintained [basic linear algebra subprograms (BLAS)](http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms) library, based on [Kazushige Goto's](http://en.wikipedia.org/wiki/Kazushige_Goto) famous [GotoBLAS](http://www.tacc.utexas.edu/tacc-projects/gotoblas2/). The system provided BLAS and LAPACK are used on OS X.
- **[LAPACK]** — a library of linear algebra routines for solving systems of simultaneous linear equations, least-squares solutions of linear systems of equations, eigenvalue problems, and singular value problems.
@@ -153,7 +153,7 @@ Julia uses the following external libraries, which are automatically downloaded
[curl]: http://curl.haxx.se/
[git]: http://git-scm.com/
[perl]: http://www.perl.org/
-[fdlibm]: http://www.netlib.org/fdlibm/readme
+[OpenLibm]: https://github.com/JuliaLang/openlibm
[DSFMT]: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/#dSFMT
[OpenBLAS]: https://github.com/xianyi/OpenBLAS#readme
[LAPACK]: http://www.netlib.org/lapack/
View
62 base/abstractarray.jl
@@ -34,6 +34,16 @@ iscomplex(::AbstractArray) = false
isbool(::AbstractArray{Bool}) = true
isbool(::AbstractArray) = false
+function isassigned(a::AbstractArray, i::Int...)
+ # TODO
+ try
+ a[i...]
+ true
+ catch
+ false
+ end
+end
+
# used to compute "end" for last index
function trailingsize(A, n)
s = 1
@@ -114,21 +124,37 @@ function iround_to{T}(dest::AbstractArray{T}, src)
return dest
end
-int (x::AbstractArray) = iround_to(similar(x,Int) , x)
-int8 (x::AbstractArray) = iround_to(similar(x,Int8) , x)
-uint8 (x::AbstractArray) = iround_to(similar(x,Uint8) , x)
-int16 (x::AbstractArray) = iround_to(similar(x,Int16) , x)
-uint16 (x::AbstractArray) = iround_to(similar(x,Uint16) , x)
-int32 (x::AbstractArray) = iround_to(similar(x,Int32) , x)
-uint32 (x::AbstractArray) = iround_to(similar(x,Uint32) , x)
-int64 (x::AbstractArray) = iround_to(similar(x,Int64) , x)
-uint64 (x::AbstractArray) = iround_to(similar(x,Uint64) , x)
+for (f,t) in ((:char, Char),
+ (:int, Int),
+ (:int8, Int8),
+ (:int16, Int16),
+ (:int32, Int32),
+ (:int64, Int64),
+ (:uint8, Uint8),
+ (:uint16, Uint16),
+ (:uint32, Uint32),
+ (:uint64, Uint64))
+ @eval ($f)(x::AbstractArray{$t}) = x
+ @eval ($f)(x::AbstractArray) = iround_to(similar(x,$t), x)
+end
+
+for (f,t) in ((:float32, Float32),
+ (:float64, Float64),
+ (:complex64, Complex64),
+ (:complex128, Complex128))
+ @eval ($f)(x::AbstractArray{$t}) = x
+ @eval ($f)(x::AbstractArray) = copy_to(similar(x,$t), x)
+end
+
+integer{T<:Integer}(x::AbstractArray{T}) = x
+unsigned{T<:Unsigned}(x::AbstractArray{T}) = x
+float{T<:FloatingPoint}(x::AbstractArray{T}) = x
+complex{T<:Complex}(x::AbstractArray{T}) = x
+
integer (x::AbstractArray) = iround_to(similar(x,typeof(integer(one(eltype(x))))), x)
unsigned(x::AbstractArray) = iround_to(similar(x,typeof(unsigned(one(eltype(x))))), x)
-char (x::AbstractArray) = iround_to(similar(x,Char) , x)
-float32(x::AbstractArray) = copy_to(similar(x,Float32), x)
-float64(x::AbstractArray) = copy_to(similar(x,Float64), x)
-float (x::AbstractArray) = copy_to(similar(x,typeof(float(one(eltype(x))))), x)
+float (x::AbstractArray) = copy_to(similar(x,typeof(float(one(eltype(x))))), x)
+complex (x::AbstractArray) = copy_to(similar(x,typeof(complex(one(eltype(x))))), x)
full(x::AbstractArray) = x
@@ -564,7 +590,12 @@ end
vcat(X...) = cat(1, X...)
hcat(X...) = cat(2, X...)
-function cat(catdim::Integer, A::AbstractArray...)
+cat{T}(catdim::Integer, A::AbstractArray{T}...) = cat_t(catdim, T, A...)
+
+cat(catdim::Integer, A::AbstractArray...) =
+ cat_t(catdim, promote_type(map(eltype, A)...), A...)
+
+function cat_t(catdim::Integer, typeC, A::AbstractArray...)
# ndims of all input arrays should be in [d-1, d]
nargs = length(A)
@@ -610,7 +641,6 @@ function cat(catdim::Integer, A::AbstractArray...)
ndimsC = max(catdim, d_max)
dimsC = ntuple(ndimsC, compute_dims)::(Int...)
- typeC = promote_type(map(eltype, A)...)
C = similar(full(A[1]), typeC, dimsC)
range = 1
@@ -885,7 +915,7 @@ sub2ind{T<:Integer}(dims, I::AbstractVector{T}...) =
[ sub2ind(dims, map(X->X[i], I)...)::Int for i=1:length(I[1]) ]
ind2sub(dims::(Integer...), ind::Integer) = ind2sub(dims, int(ind))
-ind2sub(dims::(), ind::Integer) = throw(BoundsError())
+ind2sub(dims::(), ind::Integer) = ind==1 ? () : throw(BoundsError())
ind2sub(dims::(Integer,), ind::Int) = (ind,)
ind2sub(dims::(Integer,Integer), ind::Int) =
(rem(ind-1,dims[1])+1, div(ind-1,dims[1])+1)
View
34 base/array.jl
@@ -30,6 +30,8 @@ strides{T}(a::Array{T,1}) = (1,)
strides{T}(a::Array{T,2}) = (1, size(a,1))
strides{T}(a::Array{T,3}) = (1, size(a,1), size(a,1)*size(a,2))
+isassigned(a::Array, i::Int...) = isdefined(a, i...)
+
## copy ##
function copy_to{T}(dest::Array{T}, dsto, src::Array{T}, so, N)
@@ -186,23 +188,24 @@ ones(args...) = fill!(Array(Float64, args...), float64(1))
trues(args...) = fill(true, args...)
falses(args...) = fill(false, args...)
-eye(n::Int) = eye(n, n)
-function eye(m::Int, n::Int)
- a = zeros(m,n)
+function eye(T::Type, m::Int, n::Int)
+ a = zeros(T,m,n)
for i = 1:min(m,n)
- a[i,i] = 1
+ a[i,i] = one(T)
end
return a
end
+eye(m::Int, n::Int) = eye(Float64, m, n)
+eye(T::Type, n::Int) = eye(T, n, n)
+eye(n::Int) = eye(Float64, n)
+eye{T}(x::StridedMatrix{T}) = eye(T, size(x, 1), size(x, 2))
function one{T}(x::StridedMatrix{T})
- m, n = size(x)
- a = zeros(T,size(x))
- for i = 1:min(m,n)
- a[i,i] = 1
- end
- return a
+ m,n = size(x)
+ if m != n; error("Multiplicative identity only defined for square matrices!"); end;
+ eye(T, m)
end
+
function linspace(start::Real, stop::Real, n::Integer)
(start, stop) = promote(start, stop)
T = typeof(start)
@@ -301,7 +304,7 @@ end
## Indexing: ref ##
-ref{T}(a::Array{T,0}) = arrayref(a,1)
+ref(a::Array) = arrayref(a,1)
ref(A::Array, i0::Integer) = arrayref(A,int(i0))
ref(A::Array, i0::Integer, i1::Integer) = arrayref(A,int(i0),int(i1))
@@ -968,15 +971,6 @@ function complex{T<:Real}(A::Array{T}, B::Real)
return F
end
-function complex{T<:Real}(A::Array{T})
- z = zero(T)
- F = similar(A, typeof(complex(z,z)))
- for i=1:numel(A)
- F[i] = complex(A[i], z)
- end
- return F
-end
-
## Binary comparison operators ##
for (f,scalarf) in ((:(.==),:(==)), (:.<, :<), (:.!=,:!=), (:.<=,:<=))
View
2 base/ascii.jl
@@ -1,4 +1,4 @@
-## from src/boot.jl:
+## from base/boot.jl:
#
# type ASCIIString <: DirectIndexString
# data::Array{Uint8,1}
View
14 base/base.jl
@@ -81,6 +81,8 @@ uint(x::Uint) = x
names(m::Module, all::Bool) = ccall(:jl_module_names, Array{Symbol,1}, (Any,Int32), m, all)
names(m::Module) = names(m,false)
+module_name(m::Module) = ccall(:jl_module_name, Symbol, (Any,), m)
+module_parent(m::Module) = ccall(:jl_module_parent, Module, (Any,), m)
# index colon
type Colon
@@ -116,18 +118,20 @@ function append_any(xs...)
# used by apply() and quote
# must be a separate function from append(), since apply() needs this
# exact function.
- n = 0
- for x = xs
- n += length(x)
- end
- out = Array(Any, n)
+ out = Array(Any, 4)
+ l = 4
i = 1
for x in xs
for y in x
+ if i > l
+ ccall(:jl_array_grow_end, Void, (Any, Uint), out, 16)
+ l += 16
+ end
arrayset(out, y, i)
i += 1
end
end
+ ccall(:jl_array_del_end, Void, (Any, Uint), out, l-i+1)
out
end
View
15 base/blas.jl
@@ -3,6 +3,21 @@ typealias LapackType Union(Float64,Float32,Complex128,Complex64)
module Blas
import Base.*
+export copy!,
+ dot,
+ nrm2,
+ axpy!,
+ syrk!,
+ syrk,
+ herk!,
+ herk,
+ gbmv!,
+ gbmv,
+ sbmv!,
+ sbmv,
+ gemm!,
+ gemm
+
# SUBROUTINE DCOPY(N,DX,INCX,DY,INCY)
for (fname, elty) in ((:dcopy_,:Float64), (:scopy_,:Float32),
(:zcopy_,:Complex128), (:ccopy_,:Complex64))
View
2 base/bool.jl
@@ -1,6 +1,6 @@
## boolean conversions ##
-convert(::Type{Bool}, x::Number) = (x!=0)
+convert(::Type{Bool}, x::Real) = (x!=0)
# promote Bool to any other numeric type
promote_rule{T<:Number}(::Type{Bool}, ::Type{T}) = T
View
2 base/boot.jl
@@ -133,7 +133,7 @@ export ..., ANY, ASCIIString, AbstractArray, AbstractKind, Any, Array,
# functions
setfield, applicable, apply, apply_type, arraylen, arrayref, arrayset,
arraysize, convert_default, convert_tuple, eval, fieldtype, getfield,
- include, invoke, is, ===, isa, isbound, method_exists,
+ include, invoke, is, ===, isa, isdefined, method_exists,
subtype, throw, tuple, tuplelen, tupleref, typeassert, typeof, yieldto,
# constants
JULIA_HOME, nothing,
View
4 base/client.jl
@@ -190,6 +190,10 @@ function process_options(args::Array{Any,1})
# see repl-readline.c
elseif args[i] == "-f" || args[i] == "--no-startup"
startup = false
+ elseif args[i] == "-F"
+ # load juliarc now before processing any more options
+ try include(strcat(ENV["HOME"],"/.juliarc.jl")) end
+ startup = false
elseif args[i][1]!='-'
# program
repl = false
View
3 base/complex.jl
@@ -37,6 +37,9 @@ end
show(io, z::Complex) = _jl_show(io, z, false)
showcompact(io, z::Complex) = _jl_show(io, z, true)
+convert{T<:Real}(::Type{T}, z::Complex) = (imag(z)==0 ? convert(T,real(z)) :
+ throw(InexactError()))
+
## packed complex float types ##
bitstype 128 Complex128 <: Complex{Float64}
View
23 base/deepcopy.jl
@@ -31,13 +31,8 @@ function _deepcopy_t(x, T::CompositeKind, stackdict::ObjectIdDict)
ret = ccall(:jl_new_struct_uninit, Any, (Any,), T)
stackdict[x] = ret
for f in T.names
- try
+ if isdefined(x,f)
ret.(f) = deepcopy_internal(x.(f), stackdict)
- catch err
- # we ignore undefined references errors
- if !isa(err, UndefRefError)
- throw(err)
- end
end
end
return ret
@@ -57,19 +52,9 @@ _deepcopy_array_t(x, T::BitsKind, stackdict::ObjectIdDict) = copy(x)
function _deepcopy_array_t(x, T, stackdict::ObjectIdDict)
dest = similar(x)
stackdict[x] = dest
- i0 = 1; local i
- while true
- try
- for i=i0:length(x)
- arrayset(dest, deepcopy_internal(x[i], stackdict), i)
- end
- break
- catch err
- # we ignore undefined references errors
- if !isa(err, UndefRefError)
- throw(err)
- end
- i0 = i+1
+ for i=1:length(x)
+ if isdefined(x,i)
+ arrayset(dest, deepcopy_internal(x[i], stackdict), i)
end
end
return dest
View
51 base/dict.jl
@@ -154,11 +154,15 @@ bitmix(a::Union(Int64,Uint64), b::Union(Int64, Uint64)) =
shl_int(unbox(Uint64,b), 32))))
if WORD_SIZE == 64
- _jl_hash64(x::Union(Int64,Uint64,Float64)) =
- ccall(:int64hash, Uint64, (Uint64,), box(Uint64,unbox(Uint64,x)))
+ _jl_hash64(x::Float64) =
+ ccall(:int64hash, Uint64, (Uint64,), box(Uint64,unbox(Float64,x)))
+ _jl_hash64(x::Union(Int64,Uint64)) =
+ ccall(:int64hash, Uint64, (Uint64,), x)
else
- _jl_hash64(x::Union(Int64,Uint64,Float64)) =
- ccall(:int64to32hash, Uint32, (Uint64,), box(Uint64,unbox(Uint64,x)))
+ _jl_hash64(x::Float64) =
+ ccall(:int64to32hash, Uint32, (Uint64,), box(Uint64,unbox(Float64,x)))
+ _jl_hash64(x::Union(Int64,Uint64)) =
+ ccall(:int64to32hash, Uint32, (Uint64,), x)
end
hash(x::Integer) = _jl_hash64(uint64(x))
@@ -228,7 +232,7 @@ type Dict{K,V} <: Associative{K,V}
new(fill!(cell(n), _jl_secret_table_token), Array(V,n),
0, 0, identity)
end
- function Dict(ks::Tuple, vs::Tuple)
+ function Dict(ks, vs)
n = length(ks)
h = Dict{K,V}(n)
for i=1:n
@@ -240,6 +244,14 @@ end
Dict() = Dict(0)
Dict(n::Integer) = Dict{Any,Any}(n)
+Dict{K,V}(ks::AbstractArray{K}, vs::AbstractArray{V}) = Dict{K,V}(ks,vs)
+Dict(ks, vs) = Dict{Any,Any}(ks, vs)
+
+# syntax entry points
+Dict{K,V}(ks::(K...), vs::(V...)) = Dict{K ,V }(ks, vs)
+Dict{K }(ks::(K...), vs::Tuple ) = Dict{K ,Any}(ks, vs)
+Dict{V }(ks::Tuple , vs::(V...)) = Dict{Any,V }(ks, vs)
+
similar{K,V}(d::Dict{K,V}) = Dict{K,V}()
function serialize(s, t::Dict)
@@ -262,26 +274,17 @@ function deserialize{K,V}(s, T::Type{Dict{K,V}})
return t
end
-# syntax entry point
-dict{K,V}(ks::(K...), vs::(V...)) = Dict{K,V} (ks, vs)
-dict{K} (ks::(K...), vs::Tuple ) = Dict{K,Any} (ks, vs)
-dict{V} (ks::Tuple , vs::(V...)) = Dict{Any,V} (ks, vs)
-dict (ks::Tuple , vs::Tuple) = Dict{Any,Any}(ks, vs)
-
hashindex(key, sz) = (int(hash(key)) & (sz-1)) + 1
const _jl_missing_token = :__c782dbf1cf4d6a2e5e3965d7e95634f2e09b5901__
function rehash{K,V}(h::Dict{K,V}, newsz)
- oldk = copy(h.keys)
+ oldk = h.keys
oldv = h.vals
- sz = length(oldk)
newsz = _tablesz(newsz)
- if newsz > sz
- grow(h.keys, newsz-sz)
- end
+ h.keys = fill!(cell(newsz), _jl_secret_table_token)
h.vals = Array(V, newsz)
- del_all(h)
+ h.ndel = h.count = 0
for i = 1:length(oldk)
k = oldk[i]
@@ -295,6 +298,7 @@ end
function del_all{K,V}(h::Dict{K,V})
fill!(h.keys, _jl_secret_table_token)
+ h.vals = Array(V, length(h.keys))
h.ndel = 0
h.count = 0
return h
@@ -305,12 +309,14 @@ function assign{K,V}(h::Dict{K,V}, v, key)
sz = length(h.keys)
- if h.ndel >= ((3*sz)>>2)
- rehash(h, sz)
+ if h.ndel >= ((3*sz)>>2) || h.count*3 > sz*2
+ # > 3/4 deleted or > 2/3 full
+ rehash(h, h.count > 64000 ? h.count*2 : h.count*4)
+ sz = length(h.keys) # rehash may resize the table at this point!
end
iter = 0
- maxprobe = sz>>3
+ maxprobe = max(16, sz>>6)
index = hashindex(key, sz)
orig = index
avail = -1 # an available slot
@@ -355,7 +361,7 @@ function assign{K,V}(h::Dict{K,V}, v, key)
return h
end
- rehash(h, sz*2)
+ rehash(h, h.count > 64000 ? sz*2 : sz*4)
assign(h, v, key)
end
@@ -366,7 +372,7 @@ function ht_keyindex{K,V}(h::Dict{K,V}, key)
sz = length(h.keys)
iter = 0
- maxprobe = sz>>3
+ maxprobe = max(16, sz>>6)
index = hashindex(key, sz)
orig = index
keys = h.keys
@@ -411,6 +417,7 @@ function del(h::Dict, key)
index = ht_keyindex(h, key)
if index > 0
h.keys[index] = _jl_missing_token
+ ccall(:jl_arrayunset, Void, (Any,Uint), h.vals, index-1)
h.ndel += 1
h.count -= 1
end
View
3 base/error.jl
@@ -2,7 +2,8 @@
error(e::Exception) = throw(e)
error{E<:Exception}(::Type{E}) = throw(E())
-error(s...) = throw(ErrorException(string(s...)))
+error(s::String) = throw(ErrorException(s))
+error(s...) = throw(ErrorException(string(s...)))
macro unexpected()
:(error("unexpected branch reached"))
View
20 base/export.jl
@@ -9,6 +9,7 @@ export
Blas,
LibRandom,
RNG,
+ Math,
# Types
AbstractMatrix,
@@ -630,6 +631,8 @@ export
chol,
chold,
chold!,
+ cholpd,
+ cholpd!,
cond,
cross,
ctranspose,
@@ -659,6 +662,8 @@ export
matmul2x2,
matmul3x3,
norm,
+ null,
+ pinv,
qr,
qrd!,
qrd,
@@ -709,7 +714,6 @@ export
del,
del_all,
del_each,
- dict,
elements,
eltype,
get,
@@ -998,6 +1002,8 @@ export
help,
less,
names,
+ module_name,
+ module_parent,
which,
whicht,
whos,
@@ -1167,12 +1173,14 @@ export
file_remove,
file_create,
path_rename,
- dir_create,
- dir_remove,
+ mkdir,
+ rmdir,
tempdir,
- tempfile,
+ tempname,
+ mktemp,
+ mktempdir,
download_file,
- real_path,
+ realpath,
filemode,
filesize,
mtime,
@@ -1262,6 +1270,8 @@ export
@elapsed,
@windows_only,
@unix_only,
+ @osx_only,
+ @linux_only,
@sync,
@spawn,
@spawnlocal,
View
79 base/file.jl
@@ -2,24 +2,24 @@
# These do not examine the filesystem at all, they just work on strings
@unix_only begin
const os_separator = "/"
- const os_separator_match = "/"
+ const os_separator_match = r"/+"
const os_separator_match_chars = "/"
end
@windows_only begin
const os_separator = "\\"
- const os_separator_match = "[/\\\\]" # permit either slash type on Windows
+ const os_separator_match = r"[/\\]" # permit either slash type on Windows
const os_separator_match_chars = "/\\" # to permit further concatenation
end
# Match only the final separator
-const last_separator = Regex(strcat(os_separator_match, "(?!.*", os_separator_match, ")"))
+const last_separator = Regex(strcat(os_separator_match.pattern, "(?!.*", os_separator_match.pattern, ")"))
# Match the "." indicating a file extension. Must satisfy the
# following requirements:
# - It's not followed by a later "." or os_separator
# (handles cases like myfile.txt.gz, or Mail.directory/cur)
# - It's not the first character in a string, nor is it preceded by
# an os_separator (handles cases like .bashrc or /home/fred/.juliarc)
-const extension_separator_match = Regex(strcat("(?<!^)(?<!",
- os_separator_match, ")\\.(?!.*[", os_separator_match_chars, "\.])"))
+const extension_separator_match = Regex(strcat(L"(?<!^|[",
+ os_separator_match_chars, L"])\.[^.", os_separator_match_chars, L"]+$"))
filesep() = os_separator
@@ -77,19 +77,13 @@ function file_path(components...)
join(components, os_separator)
end
-function fullfile(pathname::String, basename::String, ext::String)
- if isempty(pathname)
- return basename * ext
- else
- return pathname * os_separator * basename * ext
- end
-end
+const fullfile = file_path
# Test for an absolute path
function isrooted(path::String)
# Check whether it begins with the os_separator. On Windows, matches
# \\servername syntax, so this is a relevant check for everyone
- m = match(Regex(strcat("^", os_separator_match)), path)
+ m = match(Regex(strcat("^", os_separator_match.pattern)), path)
if m != nothing
return true
end
@@ -158,7 +152,8 @@ end
# Get the full, real path to a file, including dereferencing
# symlinks.
@unix_only begin
-function real_path(fname::String)
+function realpath(fname::String)
+ fname = tilde_expand(fname)
sp = ccall(:realpath, Ptr{Uint8}, (Ptr{Uint8}, Ptr{Uint8}), fname, C_NULL)
if sp == C_NULL
error("Cannot find ", fname)
@@ -171,18 +166,18 @@ end
@windows_only begin
const PATH_MAX=4096
-function real_path(fname::String)
+function realpath(fname::String)
path = Array(Uint8,PATH_MAX)
size = ccall(:GetFullPathNameA,stdcall,Uint32,(Ptr{Uint8},Int32,Ptr{Uint8},Ptr{Uint8}),fname,PATH_MAX,path,0)
if(size == 0)
- error("real_path: Failed to get real path") #TODO: better, unified (with unix) error reporting
+ error("realpath: Failed to get real path") #TODO: better, unified (with unix) error reporting
elseif(size < PATH_MAX)
return convert(ASCIIString,grow(path,size-PATH_MAX)) #Shrink buffer to needed space and convert to ASCIIString
else
grow(path,size-PATH_MAX)
size = ccall(:GetFullPathNameA,stdcall,Uint32,(Ptr{Uint8},Int32,Ptr{Uint8},Ptr{Uint8}),fname,PATH_MAX,path,0)
if(size == 0)
- error("real_path: Failed to get real path (long path)")
+ error("realpath: Failed to get real path (long path)")
end
return convert(ASCIIString,path)
end
@@ -198,7 +193,7 @@ function cwd()
bytestring(p)
end
-cd(dir::String) = system_error("chdir", ccall(:uv_chdir,Int64,(Ptr{Uint8},),real_path(dir)) == -1)
+cd(dir::String) = system_error("chdir", ccall(:uv_chdir,Int64,(Ptr{Uint8},),dir) == -1)
cd() = cd(ENV["HOME"])
# do stuff in a directory, then return to current directory
@@ -236,6 +231,18 @@ end
cd(f::Function) = cd(f, ENV["HOME"])
+function mkdir(path::String, mode::Unsigned)
+ ret = ccall(:mkdir, Int32, (Ptr{Uint8},Uint32), bytestring(path), mode)
+ system_error(:mkdir, ret != 0)
+end
+mkdir(path::String, mode::Signed) = error("mkdir: mode must be an unsigned integer -- perhaps 0o", mode, "?")
+mkdir(path::String) = mkdir(path, 0o777)
+
+function rmdir(path::String)
+ ret = ccall(:rmdir, Int32, (Ptr{Uint8},), bytestring(path))
+ system_error(:rmdir, ret != 0)
+end
+
# The following use Unix command line facilites
# list the contents of a directory
@@ -263,20 +270,40 @@ function path_rename(old_pathname::String, new_pathname::String)
run(`mv $old_pathname $new_pathname`)
end
-function dir_create(directory_name::String)
- run(`mkdir $directory_name`)
+# Obtain a temporary filename.
+tempnam = (OS_NAME == :Windows) ? :_tempnam : :tempnam
+
+function tempname()
+ d = get(ENV, "TMPDIR", C_NULL) # tempnam ignores TMPDIR on darwin
+ p = ccall(tempnam, Ptr{Uint8}, (Ptr{Uint8},Ptr{Uint8}), d, "julia")
+ s = bytestring(p)
+ c_free(p)
+ s
+end
+
+# Obtain a temporary directory's path.
+tempdir() = dirname(tempname())
+
+# Create and return the name of a temporary file along with an IOStream
+@unix_only function mktemp()
+ b = file_path(tempdir(), "tmpXXXXXX")
+ p = ccall(:mkstemp, Int32, (Ptr{Uint8}, ), b)
+ return (b, fdio(p, true))
end
-function dir_remove(directory_name::String)
- run(`rmdir $directory_name`)
+@windows_only function mktemp()
+ error("not yet implemented")
end
-function tempdir()
- chomp(readall(`mktemp -d -t tmp`))
+# Create and return the name of a temporary directory
+@unix_only function mktempdir()
+ b = file_path(tempdir(), "tmpXXXXXX")
+ p = ccall(:mkdtemp, Ptr{Uint8}, (Ptr{Uint8}, ), b)
+ return bytestring(p)
end
-function tempfile()
- chomp(readall(`mktemp -t tmp`))
+@windows_only function mktempdir()
+ error("not yet implemented")
end
function download_file(url::String)
View
2 base/float.jl
@@ -70,7 +70,7 @@ iround(::Type{Uint64}, x::Float64) = box(Uint64,fpuiround64(unbox(Float64,x)))
# TODO: Int128
# this is needed very early because it is used by Range and colon
-floor(x::Float64) = ccall(dlsym(_jl_libfdm,:floor), Float64, (Float64,), x)
+floor(x::Float64) = ccall(dlsym(libopenlibm,:floor), Float64, (Float64,), x)
iceil(x::FloatingPoint) = itrunc(ceil(x)) # TODO: fast primitive for iceil
ifloor(x::FloatingPoint) = itrunc(floor(x)) # TOOD: fast primitive for ifloor
View
64 base/inference.jl
@@ -66,11 +66,11 @@ isconst(m::Module, s::Symbol) =
function _iisconst(s::Symbol)
m = (inference_stack::CallStack).mod
- isbound(m,s) && (ccall(:jl_is_const, Int32, (Any, Any), m, s) != 0)
+ isdefined(m,s) && (ccall(:jl_is_const, Int32, (Any, Any), m, s) != 0)
end
_ieval(x) = eval((inference_stack::CallStack).mod, x)
-_iisbound(x) = isbound((inference_stack::CallStack).mod, x)
+_iisdefined(x) = isdefined((inference_stack::CallStack).mod, x)
_iisconst(s::SymbolNode) = _iisconst(s.name)
_iisconst(s::TopNode) = _iisconst(s.name)
@@ -117,7 +117,7 @@ t_func[eval(Core,:ccall)] =
t_func[is] = (2, 2, cmp_tfunc)
t_func[subtype] = (2, 2, cmp_tfunc)
t_func[isa] = (2, 2, cmp_tfunc)
-t_func[isbound] = (1, 2, (args...)->Bool)
+t_func[isdefined] = (1, 2, (args...)->Bool)
t_func[Union] = (0, Inf,
(args...)->(if allp(isType,args)
Type{Union(map(t->t.parameters[1],args)...)}
@@ -140,6 +140,8 @@ function arraysize_tfunc(a)
end
end
t_func[arraysize] = (1, 2, arraysize_tfunc)
+t_func[Core.pointerref] = (2,2,(a,i)->(subtype(a,Ptr) ? a.parameters[1] : Any))
+t_func[Core.pointerset] = (3, 3, (a,v,i)->a)
function static_convert(to::ANY, from::ANY)
if !isa(to,Tuple) || !isa(from,Tuple)
@@ -190,7 +192,7 @@ t_func[convert_tuple] =
end;
isType(t) ? static_convert(t.parameters[1],x) :
Any))
-typeof_tfunc = function (t)
+const typeof_tfunc = function (t)
if isType(t)
t = t.parameters[1]
if isa(t,TypeVar)
@@ -223,7 +225,7 @@ t_func[typeassert] =
tintersect(v,map(t->t.parameters[1],t)) :
Any))
-tupleref_tfunc = function (A, t, i)
+const tupleref_tfunc = function (A, t, i)
if is(t,())
return None
end
@@ -262,7 +264,7 @@ tupleref_tfunc = function (A, t, i)
end
t_func[tupleref] = (2, 2, tupleref_tfunc)
-getfield_tfunc = function (A, s, name)
+const getfield_tfunc = function (A, s, name)
if isType(s)
s = typeof(s.parameters[1])
if s === TypeVar
@@ -275,7 +277,7 @@ getfield_tfunc = function (A, s, name)
if isa(A[2],QuoteNode) && isa(A[2].value,Symbol)
fld = A[2].value
A1 = A[1]
- if isa(A1,Module) && isbound(A1,fld) && isconst(A1, fld)
+ if isa(A1,Module) && isdefined(A1,fld) && isconst(A1, fld)
return abstract_eval_constant(eval(A1,fld))
end
if s === Module
@@ -293,7 +295,7 @@ getfield_tfunc = function (A, s, name)
end
t_func[getfield] = (2, 2, getfield_tfunc)
t_func[setfield] = (3, 3, (o, f, v)->v)
-fieldtype_tfunc = function (A, s, name)
+const fieldtype_tfunc = function (A, s, name)
if !isa(s,CompositeKind)
return Type
end
@@ -308,7 +310,7 @@ t_func[Expr] = (3, 3, (a,b,c)->Expr)
t_func[Box] = (1, 1, (a,)->Box)
# TODO: handle e.g. apply_type(T, R::Union(Type{Int32},Type{Float64}))
-apply_type_tfunc = function (A, args...)
+const apply_type_tfunc = function (A, args...)
if !isType(args[1])
return Any
end
@@ -399,7 +401,7 @@ function isconstantfunc(f, sv::StaticVarInfo)
end
if isa(f,GetfieldNode) && isa(f.value,Module)
M = f.value; s = f.name
- return isbound(M,s) && isconst(M,s) && f
+ return isdefined(M,s) && isconst(M,s) && f
end
if isa(f,Expr) && (is(f.head,:call) || is(f.head,:call1))
if length(f.args) == 3 && isa(f.args[1], TopNode) &&
@@ -417,7 +419,7 @@ function isconstantfunc(f, sv::StaticVarInfo)
return false
end
end
- return isbound(M,s) && isconst(M,s) && f
+ return isdefined(M,s) && isconst(M,s) && f
end
end
@@ -431,13 +433,13 @@ const isconstantref = isconstantfunc
isvatuple(t::Tuple) = (n = length(t); n > 0 && isseqtype(t[n]))
-limit_tuple_depth(t) = limit_tuple_depth(t,0)
+const limit_tuple_depth = t->limit_tuple_depth_(t,0)
-function limit_tuple_depth(t,d)
+const limit_tuple_depth_ = function (t,d::Int)
if isa(t,UnionKind)
# also limit within Union types.
# may have to recur into other stuff in the future too.
- return Union(limit_tuple_depth(t.types,d)...)
+ return Union(limit_tuple_depth_(t.types,d)...)
end
if !isa(t,Tuple)
return t
@@ -445,10 +447,10 @@ function limit_tuple_depth(t,d)
if d > MAX_TUPLE_DEPTH
return Tuple
end
- map(x->limit_tuple_depth(x,d+1), t)
+ map(x->limit_tuple_depth_(x,d+1), t)
end
-function limit_tuple_type(t)
+const limit_tuple_type = function (t::Tuple)
n = length(t)
if n > MAX_TUPLETYPE_LEN
last = t[n]
@@ -463,6 +465,20 @@ function limit_tuple_type(t)
end
function abstract_call_gf(f, fargs, argtypes, e)
+ if length(argtypes)>1 && isa(argtypes[1],Tuple) && argtypes[2]===Int
+ # allow tuple indexing functions to take advantage of constant
+ # index arguments.
+ if f === Main.Base.ref
+ e.head = :call1
+ return tupleref_tfunc(fargs, argtypes[1], argtypes[2])
+ elseif f === Main.Base.next
+ e.head = :call1
+ return (tupleref_tfunc(fargs, argtypes[1], argtypes[2]), Int)
+ elseif f === Main.Base.indexed_next
+ e.head = :call1
+ return (tupleref_tfunc(fargs, argtypes[1], argtypes[2]), Int)
+ end
+ end
# don't consider more than N methods. this trades off between
# compiler performance and generated code performance.
# typically, considering many methods means spending lots of time
@@ -641,11 +657,9 @@ end
function abstract_eval(e::Expr, vtypes, sv::StaticVarInfo)
# handle:
- # call lambda null isbound static_typeof
+ # call null new & static_typeof
if is(e.head,:call) || is(e.head,:call1)
t = abstract_eval_call(e, vtypes, sv)
- #elseif is(e.head,:isbound)
- # t = Bool
elseif is(e.head,:null)
t = Nothing
elseif is(e.head,:new)
@@ -722,7 +736,7 @@ function abstract_eval_global(s::Symbol)
if _iisconst(s)
return abstract_eval_constant(_ieval(s))
end
- if !_iisbound(s)
+ if !_iisdefined(s)
return Top
end
# TODO: change to Undef if there's a way to clear variables
@@ -956,7 +970,7 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop)
# print("typeinf ", linfo.name, " ", object_id(ast0), "\n")
#end
#print("typeinf ", linfo.name, " ", atypes, "\n")
- # if isbound(:stdout_stream)
+ # if isdefined(:stdout_stream)
# write(stdout_stream, "typeinf ")
# write(stdout_stream, string(linfo.name))
# write(stdout_stream, string(atypes))
@@ -1351,8 +1365,8 @@ function resolves_same(sym, from, to)
return true
end
# todo: better
- return (isconst(from,sym) && isconst(to,sym) && isbound(from,sym) &&
- isbound(to,sym) && is(eval(from,sym),eval(to,sym)))
+ return (isconst(from,sym) && isconst(to,sym) && isdefined(from,sym) &&
+ isdefined(to,sym) && is(eval(from,sym),eval(to,sym)))
end
# annotate symbols with their original module for inlining
@@ -1726,7 +1740,9 @@ function add_variable(ast, name, typ)
end
const some_names = {:_var0, :_var1, :_var2, :_var3, :_var4, :_var5, :_var6,
- :_var7, :_var8, :_var9, :_var10, :_var11, :_var12}
+ :_var7, :_var8, :_var9, :_var10, :_var11, :_var12,
+ :_var13, :_var14, :_var15, :_var16, :_var17, :_var18,
+ :_var19, :_var20, :_var21, :_var22, :_var23, :_var24}
function unique_name(ast)
locllist = ast.args[2][1]::Array{Any,1}
View
317 base/io.jl
@@ -3,6 +3,182 @@
abstract IO
# the first argument to any IO MUST be a POINTER (to a JL_STREAM) or using show on it will cause memory corruption
+# Generic IO functions
+
+## byte-order mark, ntoh & hton ##
+
+const ENDIAN_BOM = reinterpret(Uint32,uint8([1:4]))[1]
+
+if ENDIAN_BOM == 0x01020304
+ ntoh(x) = identity(x)
+ hton(x) = identity(x)
+ ltoh(x) = bswap(x)
+ htol(x) = bswap(x)
+elseif ENDIAN_BOM == 0x04030201
+ ntoh(x) = bswap(x)
+ hton(x) = bswap(x)
+ ltoh(x) = identity(x)
+ htol(x) = identity(x)
+else
+ error("seriously? what is this machine?")
+end
+
+## binary I/O ##
+
+# all subtypes should implement this
+write(s::IO, x::Uint8) = error(typeof(s)," does not support byte I/O")
+
+if ENDIAN_BOM == 0x01020304
+ function write(s, x::Integer)
+ for n = sizeof(x):-1:1
+ write(s, uint8((x>>>((n-1)<<3))))
+ end
+ end
+else
+ function write(s, x::Integer)
+ for n = 1:sizeof(x)
+ write(s, uint8((x>>>((n-1)<<3))))
+ end
+ end
+end
+
+write(s::IO, x::Bool) = write(s, uint8(x))
+write(s::IO, x::Float32) = write(s, box(Int32,unbox(Float32,x)))
+write(s::IO, x::Float64) = write(s, box(Int64,unbox(Float64,x)))
+
+function write(s::IO, a::AbstractArray)
+ for i = 1:numel(a)
+ write(s, a[i])
+ end
+end
+
+function write(s::IO, c::Char)
+ if c < 0x80
+ write(s, uint8(c))
+ return 1
+ elseif c < 0x800
+ write(s, uint8(( c >> 6 ) | 0xC0))
+ write(s, uint8(( c & 0x3F ) | 0x80))
+ return 2
+ elseif c < 0x10000
+ write(s, uint8(( c >> 12 ) | 0xE0))
+ write(s, uint8(((c >> 6) & 0x3F ) | 0x80))
+ write(s, uint8(( c & 0x3F ) | 0x80))
+ return 3
+ elseif c < 0x110000
+ write(s, uint8(( c >> 18 ) | 0xF0))
+ write(s, uint8(((c >> 12) & 0x3F ) | 0x80))
+ write(s, uint8(((c >> 6) & 0x3F ) | 0x80))
+ write(s, uint8(( c & 0x3F ) | 0x80))
+ return 4
+ end
+ error("invalid Unicode code point: U+", hex(c))
+end
+
+# all subtypes should implement this
+read(s::IO, x::Type{Uint8}) = error(typeof(s)," does not support byte I/O")
+
+function read{T <: Integer}(s::IO, ::Type{T})
+ x = zero(T)
+ for n = 1:sizeof(x)
+ x |= (convert(T,read(s,Uint8))<<((n-1)<<3))
+ end
+ return x
+end
+
+read(s::IO, ::Type{Bool}) = (read(s,Uint8)!=0)
+read(s::IO, ::Type{Float32}) = box(Float32,unbox(Int32,read(s,Int32)))
+read(s::IO, ::Type{Float64}) = box(Float64,unbox(Int64,read(s,Int64)))
+
+read{T}(s::IO, t::Type{T}, d1::Int, dims::Int...) =
+ read(s, t, tuple(d1,dims...))
+read{T}(s::IO, t::Type{T}, d1::Integer, dims::Integer...) =
+ read(s, t, map(int,tuple(d1,dims...)))
+
+read{T}(s::IO, ::Type{T}, dims::Dims) = read(s, Array(T, dims))
+
+function read{T}(s::IO, a::Array{T})
+ for i = 1:numel(a)
+ a[i] = read(s, T)
+ end
+ return a
+end
+
+function read(s::IO, ::Type{Char})
+ ch = read(s, Uint8)
+ if ch < 0x80
+ return char(ch)
+ end
+
+ # mimic utf8.next function
+ trailing = Base._jl_utf8_trailing[ch+1]
+ c::Uint32 = 0
+ for j = 1:trailing
+ c += ch
+ c <<= 6
+ ch = read(s, Uint8)
+ end
+ c += ch
+ c -= Base._jl_utf8_offset[trailing+1]
+ char(c)
+end
+
+function readuntil(s::IO, delim)
+ out = memio()
+ while (!eof(s))
+ c = read(s, Char)
+ write(out, c)
+ if c == delim
+ break
+ end
+ end
+ takebuf_string(out)
+end
+
+readline(s::IO) = readuntil(s, '\n')
+
+function readall(s::IO)
+ out = memio()
+ while (!eof(s))
+ a = read(s, Uint8)
+ write(out, a)
+ end
+ takebuf_string(out)
+end
+
+readchomp(x) = chomp(readall(x))
+
+## high-level iterator interfaces ##
+
+type EachLine
+ stream::IO
+end
+each_line(stream::IO) = EachLine(stream)
+
+start(itr::EachLine) = readline(itr.stream)
+function done(itr::EachLine, line)
+ if !isempty(line)
+ return false
+ end
+ close(itr.stream)
+ true
+end
+next(itr::EachLine, this_line) = (this_line, readline(itr.stream))
+
+function readlines(s, fx::Function...)
+ a = {}
+ for l = each_line(s)
+ for f in fx
+ l = f(l)
+ end
+ push(a, l)
+ end
+ return a
+end
+
+
+## IOStream
+
const sizeof_off_t = int(ccall(:jl_sizeof_off_t, Int32, ()))
const sizeof_ios_t = int(ccall(:jl_sizeof_ios_t, Int32, ()))
@@ -45,7 +221,8 @@ close(s::IOStream) = ccall(:ios_close, Void, (Ptr{Void},), s.ios)
flush(s::IOStream) = ccall(:ios_flush, Void, (Ptr{Void},), s.ios)
truncate(s::IOStream, n::Integer) =
- ccall(:ios_trunc, Uint, (Ptr{Void}, Uint), s.ios, n)
+ (ccall(:ios_trunc, Int32, (Ptr{Void}, Uint), s.ios, n)==0 ||
+ error("truncate failed"))
seek(s::IOStream, n::Integer) =
(ccall(:ios_seek, FileOffset, (Ptr{Void}, FileOffset), s.ios, n)==0 ||
@@ -118,82 +295,6 @@ end
memio(x::Integer) = memio(x, true)
memio() = memio(0, true)
-## byte-order mark, ntoh & hton ##
-takebuf_array(s::IOStream) =
- ccall(:jl_takebuf_array, Vector{Uint8}, (Ptr{Void},), s.ios)
-
-const ENDIAN_BOM = reinterpret(Uint32,uint8([1:4]))[1]
-
-if ENDIAN_BOM == 0x01020304
- ntoh(x) = identity(x)
- hton(x) = identity(x)
- ltoh(x) = bswap(x)
- htol(x) = bswap(x)
-elseif ENDIAN_BOM == 0x04030201
- ntoh(x) = bswap(x)
- hton(x) = bswap(x)
- ltoh(x) = identity(x)
- htol(x) = identity(x)
-else
- error("seriously? what is this machine?")
-end
-
-## binary I/O ##
-write(x) = write(OUTPUT_STREAM::IOStream, x)
-write(s, x::Uint8) = error(typeof(s)," does not support byte I/O")
-
-if ENDIAN_BOM == 0x01020304
- function write(s, x::Integer)
- for n = sizeof(x):-1:1
- write(s, uint8((x>>>((n-1)<<3))))
- end
- end
-else
- function write(s, x::Integer)
- for n = 1:sizeof(x)
- write(s, uint8((x>>>((n-1)<<3))))
- end
- end
-end
-
-write(s, x::Bool) = write(s, uint8(x))
-write(s, x::Float32) = write(s, box(Int32,unbox(Float32,x)))
-write(s, x::Float64) = write(s, box(Int64,unbox(Float64,x)))
-
-function write(s, a::AbstractArray)
- for i = 1:numel(a)
- write(s, a[i])
- end
-end
-
-read(s, x::Type{Uint8}) = error(typeof(s)," does not support byte I/O")
-
-function read{T <: Integer}(s, ::Type{T})
- x = zero(T)
- for n = 1:sizeof(x)
- x |= (convert(T,read(s,Uint8))<<((n-1)<<3))
- end
- return x
-end
-
-read(s, ::Type{Bool}) = (read(s,Uint8)!=0)
-read(s, ::Type{Float32}) = box(Float32,unbox(Int32,read(s,Int32)))
-read(s, ::Type{Float64}) = box(Float64,unbox(Int64,read(s,Int64)))
-
-read{T}(s, t::Type{T}, d1::Int, dims::Int...) =
- read(s, t, tuple(d1,dims...))
-read{T}(s, t::Type{T}, d1::Integer, dims::Integer...) =
- read(s, t, map(int,tuple(d1,dims...)))
-
-read{T}(s, ::Type{T}, dims::Dims) = read(s, Array(T, dims))
-
-function read{T}(s, a::Array{T})
- for i = 1:numel(a)
- a[i] = read(s, T)
- end
- return a
-end
-
## low-level calls ##
write(s::IOStream, b::Uint8) = ccall(:jl_putc, Int32, (Int32, Ptr{Void}), b, s.ios)
@@ -212,12 +313,12 @@ function write(s::IOStream, p::Ptr, nb::Integer)
ccall(:jl_write, Uint, (Ptr{Void}, Ptr{Void}, Uint), s.ios, p, nb)
end
-function write{T,N}(s::IOStream, a::SubArray{T,N,Array})
+function write{T,N,A<:Array}(s::IOStream, a::SubArray{T,N,A})
if !isa(T,BitsKind) || stride(a,1)!=1
return invoke(write, (Any, AbstractArray), s, a)
end
colsz = size(a,1)*sizeof(T)
- if N==1
+ if N<=1
write(s, pointer(a, 1), colsz)
else
cartesian_map((idxs...)->write(s, pointer(a, idxs), colsz),
@@ -237,16 +338,12 @@ function read(s::IOStream, ::Type{Uint8})
end
function read{T<:Union(Int8,Uint8,Int16,Uint16,Int32,Uint32,Int64,Uint64,Int128,Uint128,Float32,Float64,Complex64,Complex128)}(s::IOStream, a::Array{T})
- if isa(T,BitsKind)
- nb = numel(a)*sizeof(T)
- if ccall(:ios_readall, Uint,
- (Ptr{Void}, Ptr{Void}, Uint), s.ios, a, nb) < nb
- throw(EOFError())
- end
- a
- else
- invoke(read, (Any, Array), s, a)
+ nb = numel(a)*sizeof(T)
+ if ccall(:ios_readall, Uint,
+ (Ptr{Void}, Ptr{Void}, Uint), s.ios, a, nb) < nb
+ throw(EOFError())
end
+ a
end
## text I/O ##
@@ -297,6 +394,8 @@ function with_output_to_string(thunk)
takebuf_string(m)
end
+write(x) = write(OUTPUT_STREAM::IOStream, x)
+
function readuntil(s::IOStream, delim)
# TODO: faster versions that avoid the encoding check
ccall(:jl_readuntil, ByteString, (Ptr{Void}, Uint8), s.ios, delim)
@@ -309,48 +408,6 @@ function readall(s::IOStream)
end
readall(filename::String) = open(readall, filename)
-readchomp(x) = chomp(readall(x))
-
-readline(s::IOStream) = readuntil(s, '\n')
-
-## high-level iterator interfaces ##
-
-type EachLine
- stream::IOStream
-end
-each_line(stream::IOStream) = EachLine(stream)
-
-start(itr::EachLine) = readline(itr.stream)
-function done(itr::EachLine, line)
- if !isempty(line)
- return false
- end
- close(itr.stream)
- true
-end
-next(itr::EachLine, this_line) = (this_line, readline(itr.stream))
-
-skip(s::IOStream, delta::Integer) =
- (ccall(:ios_skip, FileOffset, (Ptr{Void}, FileOffset), s.ios, delta)==0 ||
- error("skip failed"))
-
-position(s::IOStream) = ccall(:ios_pos, FileOffset, (Ptr{Void},), s.ios)
-
-type IOTally
- nbytes::Int
- IOTally() = new(0)
-end
-function readlines(s, fx::Function...)
- a = {}
- for l = each_line(s)
- for f in fx
- l = f(l)
- end
- push(a, l)
- end
- return a
-end
-
## select interface ##
const sizeof_fd_set = int(ccall(:jl_sizeof_fd_set, Int32, ()))
View
8 base/iterator.jl
@@ -6,12 +6,12 @@ end
enumerate(itr) = Enumerate(itr)
length(e::Enumerate) = length(e.itr)
-start(e::Enumerate) = (start(e.itr), 1)
+start(e::Enumerate) = (1, start(e.itr))
function next(e::Enumerate, state)
- v, s = next(e.itr, state[1])
- (v,state[2]), (s,state[2]+1)
+ v, s = next(e.itr, state[2])
+ (state[1],v), (state[1]+1,s)
end
-done(e::Enumerate, state) = done(e.itr, state[1])
+done(e::Enumerate, state) = done(e.itr, state[2])
# zip
View
122 base/lapack.jl
@@ -372,7 +372,7 @@ for (gels, gesv, getrs, getri, elty) in
end
k = min(m, n)
F = m < n ? tril(A[1:k, 1:k]) : triu(A[1:k, 1:k])
- F, B[1:k,:], [sum(B[(k+1):size(B,1), i].^2) for i=1:size(B,2)]
+ F, isa(B, Vector) ? B[1:k] : B[1:k,:], [sum(B[(k+1):size(B,1), i].^2) for i=1:size(B,2)]
end
# SUBROUTINE DGESV( N, NRHS, A, LDA, IPIV, B, LDB, INFO )
# * .. Scalar Arguments ..
@@ -444,6 +444,93 @@ for (gels, gesv, getrs, getri, elty) in
end
end
end
+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 )
+ # * .. Scalar Arguments ..
+ # INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS, RANK
+ # DOUBLE PRECISION RCOND
+ # * ..
+ # * .. Array Arguments ..
+ # INTEGER IWORK( * )
+ # DOUBLE PRECISION A( LDA, * ), B( LDB, * ), S( * ), WORK( * )
+ function gelsd!(A::StridedMatrix{$elty}, B::StridedVecOrMat{$elty}, rcond)
+ Lapack.chkstride1(A, B)
+ m, n = size(A)
+ if size(B,1) != m; throw(Lapack.LapackDimMisMatch("gelsd!")); end
+ s = Array($elty, min(m, n))
+ rnk = Array(Int32, 1)
+ info = Array(Int32, 1)
+ work = Array($elty, 1)
+ lwork = int32(-1)
+ iwork = Array(Int32, 1)
+ for i in 1:2
+ ccall(dlsym(Base.liblapack, $(string(gelsd))), Void,
+ (Ptr{Int32}, Ptr{Int32}, Ptr{Int32},
+ Ptr{$elty}, Ptr{Int32}, Ptr{$elty}, Ptr{Int32},
+ Ptr{$elty}, Ptr{$elty}, Ptr{Int32}, Ptr{$elty},
+ Ptr{Int32}, Ptr{Int32}, Ptr{Int32}),
+ &m, &n, &size(B,2), A, &max(1,stride(A,2)),
+ B, &max(1,stride(B,2)), s, &rcond, rnk, work, &lwork, iwork, info)
+ if info[1] != 0 throw(LapackException(info[1])) end
+ if lwork < 0
+ lwork = int32(real(work[1]))
+ work = Array($elty, lwork)
+ iwork = Array(Int32, iwork[1])
+ end
+ end
+ isa(B, Vector) ? B[1:n] : B[1:n,:], rnk[1]
+ end
+ gelsd!(A::StridedMatrix{$elty}, B::StridedVecOrMat{$elty}) = gelsd!(A, B, -1.)
+ end
+end
+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 )
+ # * .. Scalar Arguments ..
+ # INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS, RANK
+ # DOUBLE PRECISION RCOND
+ # * ..
+ # * .. Array Arguments ..
+ # INTEGER IWORK( * )
+ # DOUBLE PRECISION RWORK( * ), S( * )
+ # COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( * )
+ function gelsd!(A::StridedMatrix{$elty}, B::StridedVecOrMat{$elty}, rcond)
+ Lapack.chkstride1(A, B)
+ m, n = size(A)
+ if size(B,1) != m; throw(Lapack.LapackDimMisMatch("gelsd!")); end
+ s = Array($elty, min(m, n))
+ rnk = Array(Int32, 1)
+ info = Array(Int32, 1)
+ work = Array($elty, 1)
+ lwork = int32(-1)
+ rwork = Array($relty, 1)
+ iwork = Array(Int32, 1)
+ for i in 1:2
+ ccall(dlsym(Base.liblapack, $(string(gelsd))), Void,
+ (Ptr{Int32}, Ptr{Int32}, Ptr{Int32}, Ptr{$elty},
+ Ptr{Int32}, Ptr{$elty}, Ptr{Int32}, Ptr{$relty},
+ Ptr{$relty}, Ptr{Int32}, Ptr{$elty}, Ptr{Int32},
+ Ptr{$relty}, Ptr{Int32}, Ptr{Int32}),
+ &m, &n, &size(B,2), A, &max(1,stride(A,2)),
+ B, &max(1,stride(B,2)), s, &rcond, rnk, work, &lwork, rwork, iwork, info)
+ if info[1] != 0 throw(LapackException(info[1])) end
+ if lwork < 0
+ lwork = int32(real(work[1]))
+ work = Array($elty, lwork)
+ rwork = Array($relty, int(rwork[1]))
+ iwork = Array(Int32, iwork[1])
+ end
+ end
+ isa(B, Vector) ? B[1:n] : B[1:n,:], rnk[1]
+ end
+ gelsd!(A::StridedMatrix{$elty}, B::StridedVecOrMat{$elty}) = gelsd!(A, B, -1.)
+ end
+end
# (GE) general matrices eigenvalue-eigenvector and singular value decompositions
for (geev, gesvd, gesdd, elty) in
@@ -818,11 +905,11 @@ end
# (PO) positive-definite symmetric matrices,
# Cholesky decomposition, solvers (direct and factored) and inverse.
-for (posv, potrf, potri, potrs, elty) in
- ((:dposv_,:dpotrf_,:dpotri_,:dpotrs_,:Float64),
- (:sposv_,:spotrf_,:spotri_,:spotrs_,:Float32),
- (:zposv_,:zpotrf_,:zpotri_,:zpotrs_,:Complex128),
- (:cposv_,:cpotrf_,:cpotri_,:cpotrs_,:Complex64))
+for (posv, potrf, potri, potrs, pstrf, elty, rtyp) in
+ ((:dposv_,:dpotrf_,:dpotri_,:dpotrs_,:dpstrf_,:Float64,:Float64),
+ (:sposv_,:spotrf_,:spotri_,:spotrs_,:spstrf_,:Float32,:Float32),
+ (:zposv_,:zpotrf_,:zpotri_,:zpotrs_,:zpstrf_,:Complex128,:Float64),
+ (:cposv_,:cpotrf_,:cpotri_,:cpotrs_,:cpstrf_,:Complex64,:Float32))
@eval begin
## Caller should check if returned info[1] is zero,
## positive values indicate indefiniteness
@@ -899,6 +986,29 @@ for (posv, potrf, potri, potrs, elty) in
if info[1] != 0 throw(LapackException(info[1])) end
B
end
+ # SUBROUTINE DPSTRF( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
+ # .. Scalar Arguments ..
+ # DOUBLE PRECISION TOL
+ # INTEGER INFO, LDA, N, RANK
+ # CHARACTER UPLO
+ # .. Array Arguments ..
+ # DOUBLE PRECISION A( LDA, * ), WORK( 2*N )
+ # INTEGER PIV( N )
+ function pstrf!(uplo::LapackChar, A::StridedMatrix{$elty}, tol::Real)
+ chkstride1(A)
+ chksquare(A)
+ n = size(A,1)
+ piv = Array(Int32, n)
+ rank = Array(Int32, 1)
+ work = Array($rtyp, 2n)
+ info = Array(Int32, 1)
+ ccall(dlsym(Base.liblapack, $(string(pstrf))), Void,
+ (Ptr{Uint8}, Ptr{Int32}, Ptr{$elty}, Ptr{Int32}, Ptr{Int32},
+ Ptr{Int32}, Ptr{$rtyp}, Ptr{$rtyp}, Ptr{Int32}),
+ &uplo, &n, A, &stride(A,2), piv, rank, &tol, work, info)
+ if info[1] < 0 throw(LapackException(info[1])) end
+ A, piv, rank[1], info[1]
+ end
end
end
View
4 base/librandom.jl
@@ -174,7 +174,7 @@ end
function randmtzig_fill_randn!(A)
ccall(dlsym(Base.librandom, :randmtzig_fill_randn),
Void,
- (Ptr{Float64}, Uint32),
+ (Ptr{Float64}, Int),
A, numel(A))
return A
end
@@ -188,7 +188,7 @@ end
function randmtzig_fill_exprnd!(A)
ccall(dlsym(Base.librandom, :randmtzig_fill_exprnd),
Void,
- (Ptr{Float64}, Uint32),
+ (Ptr{Float64}, Int),
A, numel(A))
return A
end
View
10 base/linalg.jl
@@ -80,18 +80,14 @@ cond(a::AbstractMatrix) = cond(a, 2)
#istriu(A::AbstractMatrix)
#istril(A::AbstractMatrix)
-function linreg(x::AbstractVector, y::AbstractVector)
- M = [ones(length(x)) x]
- Mt = M'
- ((Mt*M)\Mt)*y
+function linreg{T<:Number}(X::StridedVecOrMat{T}, y::Vector{T})
+ [ones(T, size(X,1)) X] \ y
end
# weighted least squares
function linreg(x::AbstractVector, y::AbstractVector, w::AbstractVector)
w = sqrt(w)
- M = [w w.*x]
- Mt = M'
- ((Mt*M)\Mt)*(w.*y)
+ [w w.*x] \ (w.*y)
end
# multiply by diagonal matrix as vector
View
93 base/linalg_dense.jl
@@ -226,7 +226,7 @@ end
## Destructive matrix exponential using algorithm from Higham, 2008,
## "Functions of Matrices: Theory and Computation", SIAM
-function expm!{T<:Union(Float32,Float64,Complex64,Complex128)}(A::StridedMatrix{T})
+function expm!{T<:LapackType}(A::StridedMatrix{T})
m, n = size(A)
if m != n error("expm!: Matrix A must be square") end
if m < 2 return exp(A) end
@@ -370,7 +370,7 @@ type CholeskyDense{T<:LapackType} <: Factorization{T}
function CholeskyDense(A::Matrix{T}, upper::Bool)
A, info = Lapack.potrf!(upper ? 'U' : 'L' , A)
if info != 0 error("Matrix A not positive-definite") end
- new(upper? triu(A) : tril(A), upper)
+ new(upper? triu!(A) : tril!(A), upper)
end
end
@@ -384,8 +384,8 @@ factors(C::CholeskyDense) = C.LR
function det(C::CholeskyDense)
ff = C.LR
- dd = 0.
- for i in 1:size(ff,1) dd += ff[i,i]^2 end
+ dd = 1.
+ for i in 1:size(ff,1) dd *= abs2(ff[i,i]) end
dd
end
@@ -397,13 +397,61 @@ end
## Should these functions check that the matrix is Hermitian?
chold!{T<:LapackType}(A::Matrix{T}, upper::Bool) = CholeskyDense{T}(A, upper)
+chold!{T<:LapackType}(A::Matrix{T}) = chold!(A, true)
chold{T<:LapackType}(A::Matrix{T}, upper::Bool) = chold!(copy(A), upper)
chold{T<:Number}(A::Matrix{T}, upper::Bool) = chold(float64(A), upper)
chold{T<:Number}(A::Matrix{T}) = chold(A, true)
## Matlab (and R) compatible
chol{T<:Number}(A::Matrix{T}) = factors(chold(A))
-
+
+type CholeskyDensePivoted{T<:LapackType} <: Factorization{T}
+ LR::Matrix{T}
+ upper::Bool
+ piv::Vector{Int32}
+ rank::Int32
+ tol::Real
+ function CholeskyDensePivoted(A::Matrix{T}, upper::Bool, tol::Real)
+ A, piv, rank, info = Lapack.pstrf!(upper ? 'U' : 'L' , A, tol)
+ if info != 0 error("Matrix A not positive-definite") end
+ new(upper? triu!(A) : tril!(A), upper, piv, rank, tol)
+ end
+end
+
+size(C::CholeskyDensePivoted) = size(C.LR)
+size(C::CholeskyDensePivoted,d::Integer) = size(C.LR,d)
+
+factors(C::CholeskyDensePivoted) = C.LR, C.piv
+
+\{T<:LapackType}(C::CholeskyDensePivoted{T}, B::StridedVecOrMat{T}) =
+ Lapack.potrs!(C.upper ? 'U' : 'L', C.LR, copy(B)[C.piv])[invperm(C.piv)]
+
+rank(C::CholeskyDensePivoted) = C.rank
+
+det(C::CholeskyDensePivoted) = prod(abs2(diag(C.LR)))
+
+function inv(C::CholeskyDensePivoted)
+ if C.rank < size(C.LR, 1) error("Matrix singular") end
+ Ci, info = Lapack.potri!(C.upper ? 'U' : 'L', copy(C.LR))
+ if info != 0 error("Matrix singular") end
+ ipiv = invperm(C.piv)
+ (symmetrize!(Ci, C.upper))[ipiv, ipiv]
+end
+
+## Should these functions check that the matrix is Hermitian?
+cholpd!{T<:LapackType}(A::Matrix{T}, upper::Bool, tol::Real) = CholeskyDensePivoted{T}(A, upper, tol)
+cholpd!{T<:LapackType}(A::Matrix{T}, upper::Bool) = cholpd!(A, upper, -1.)
+cholpd!{T<:LapackType}(A::Matrix{T}, tol::Real) = cholpd!(A, true, tol)
+cholpd!{T<:LapackType}(A::Matrix{T}) = cholpd!(A, true, -1.)
+cholpd{T<:Number}(A::Matrix{T}, upper::Bool, tol::Real) = cholpd(float64(A), upper, tol)
+cholpd{T<:Number}(A::Matrix{T}, upper::Bool) = cholpd(float64(A), upper, -1.)
+cholpd{T<:Number}(A::Matrix{T}, tol::Real) = cholpd(float64(A), true, tol)
+cholpd{T<:Number}(A::Matrix{T}) = cholpd(float64(A), true, -1.)
+cholpd{T<:LapackType}(A::Matrix{T}, upper::Bool, tol::Real) = cholpd!(copy(A), upper, tol)
+cholpd{T<:LapackType}(A::Matrix{T}, upper::Bool) = cholpd!(copy(A), upper, -1.)
+cholpd{T<:LapackType}(A::Matrix{T}, tol::Real) = cholpd!(copy(A), true, tol)
+cholpd{T<:LapackType}(A::Matrix{T}) = cholpd!(copy(A), true, -1.)
+
type LUDense{T} <: Factorization{T}
lu::Matrix{T} <