Skip to content

Commit

Permalink
Merge branch 'master' of github.com:JuliaLang/julia
Browse files Browse the repository at this point in the history
Conflicts:
	doc/manual/types.rst
  • Loading branch information
JeffBezanson committed Jun 26, 2013
2 parents 1d1a235 + 5ddb88f commit b0a45c4
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 87 deletions.
10 changes: 5 additions & 5 deletions base/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ big(x::MathConst) = convert(BigFloat,x)

## specific mathematical constants

@math_const π 3.14159265358979323846 pi
@math_const e 2.71828182845904523536 exp(big(1))
@math_const γ 0.57721566490153286061 euler
@math_const catalan 0.91596559417721901505 catalan
@math_const φ 1.61803398874989484820 (1+sqrt(big(5)))/2
@math_const π 3.14159265358979323846 pi
@math_const e 2.71828182845904523536 exp(big(1))
@math_const γ 0.57721566490153286061 euler
@math_const catalan 0.91596559417721901505 catalan
@math_const φ 1.61803398874989484820 (1+sqrt(big(5)))/2

# aliases
const pi = π
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,12 @@ function factorize!{T}(A::Matrix{T})
return Diagonal(A)
end
if utri1
return lufact!(Bidiagonal(diag(A), diag(A, -1), false))
return Bidiagonal(diag(A), diag(A, -1), false)
end
return Triangular(A, :L)
end
if utri
return lufact!(Bidiagonal(diag(A), diag(A, 1), true))
return Bidiagonal(diag(A), diag(A, 1), true)
end
if utri1
if (herm & (T <: Complex)) | sym
Expand Down
13 changes: 6 additions & 7 deletions base/pkg2/cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ path(pkg::String) = abspath(".cache", pkg)
origin(pkg::String) = Git.readchomp(`config remote.origin.url`, dir=path(pkg))

function prefetch(pkg::String, url::String, vers::Dict{String,VersionNumber})
cache = path(pkg)
isdir(".cache") || mkdir(".cache")
cache = path(pkg)
if !isdir(cache)
from = ispath(pkg,".git") ? abspath(pkg) : url
info("Cloning $pkg from $from...")
try Git.run(`clone --bare $from $cache`)
info("Cloning $pkg from $url")
try Git.run(`clone -q --mirror $url $cache`)
catch
run(`rm -rf $cache`)
rethrow()
end
elseif ispath(pkg,".git")
Git.run(`fetch -q $pkg`, dir=cache)
else
Git.run(`config remote.origin.url $url`, dir=cache)
end
Git.run(`config remote.origin.url $url`, dir=cache)
# ensure that desired versions exist
sha1s = collect(keys(vers))
all(sha1->Git.iscommit(sha1, dir=cache), sha1s) && return
Git.run(`fetch -q $url`, dir=cache)
Expand Down
24 changes: 14 additions & 10 deletions base/pkg2/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ function isfixed(pkg::String, avail::Dict=available(pkg))
Git.dirty(dir=pkg) && return true
Git.attached(dir=pkg) && return true
cache = Cache.path(pkg)
isdir(cache) || return true
cache_exists = isdir(cache)
head = Git.head(dir=pkg)
for (ver,info) in avail
if Git.iscommit(info.sha1, dir=cache)
if cache_exists && Git.iscommit(info.sha1, dir=cache)
Git.is_ancestor_of(head, info.sha1, dir=cache) && return false
elseif Git.iscommit(info.sha1, dir=pkg)
Git.is_ancestor_of(head, info.sha1, dir=pkg) && return false
else
Base.warn_once("unknown $pkg commit $(info.sha1[1:8]), metadata may be ahead of package cache")
end
Expand All @@ -57,15 +59,17 @@ function installed_version(pkg::String, avail::Dict=available(pkg))
hi = typemin(VersionNumber)
for (ver,info) in avail
head == info.sha1 && return ver
if Git.iscommit(info.sha1, dir=cache)
base = Git.readchomp(`merge-base $head $(info.sha1)`, dir=cache)
if base == head # Git.is_ancestor_of(head, info.sha1)
lo = max(lo,ver)
elseif base == info.sha1 # Git.is_ancestor_of(info.sha1, head)
hi = max(hi,ver)
end
else
base =
Git.iscommit(info.sha1, dir=cache) ?
Git.readchomp(`merge-base $head $(info.sha1)`, dir=cache) :
Git.iscommit(info.sha1, dir=pkg) ?
Git.readchomp(`merge-base $head $(info.sha1)`, dir=pkg) :
Base.warn_once("unknown $pkg commit $(info.sha1[1:8]), metadata may be ahead of package cache")

if base == head # Git.is_ancestor_of(head, info.sha1)
lo = max(lo,ver)
elseif base == info.sha1 # Git.is_ancestor_of(info.sha1, head)
hi = max(hi,ver)
end
end
typemin(VersionNumber) < lo ?
Expand Down
4 changes: 2 additions & 2 deletions doc/helpdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,12 @@
"),

("Generic Functions","Base","|","|(x, f)
("Generic Functions","Base","|>","|>(x, f)
Applies a function to the preceding argument which allows for easy
function chaining.
**Example**: \"[1:5] | x->x.^2 | sum | inv\"
**Example**: \"[1:5] |> x->x.^2 |> sum |> inv\"
"),

Expand Down
8 changes: 4 additions & 4 deletions doc/manual/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -571,23 +571,23 @@ reference.
| ``dense(S)`` | ``sparse(A)`` | Interconverts between dense |
| ``full(S)`` | | and sparse formats. |
+-----------------------+-------------------+----------------------------------------+
| ``sprand(m,n,d)`` | ``rand(m,n)`` | Creates a *n*-by-*n* random matrix (of |
| ``sprand(m,n,d)`` | ``rand(m,n)`` | Creates a *m*-by-*n* random matrix (of |
| | | density *d*) with iid non-zero elements|
| | | distributed uniformly on the |
| | | interval [0, 1]. |
+-----------------------+-------------------+----------------------------------------+
| ``sprandn(m,n,d)`` | ``randn(m,n)`` | Creates a *n*-by-*n* random matrix (of |
| ``sprandn(m,n,d)`` | ``randn(m,n)`` | Creates a *m*-by-*n* random matrix (of |
| | | density *d*) with iid non-zero elements|
| | | distributed according to the standard |
| | | normal (Gaussian) distribution. |
+-----------------------+-------------------+----------------------------------------+
| ``sprandn(m,n,d,X)`` | ``randn(m,n,X)`` | Creates a *n*-by-*n* random matrix (of |
| ``sprandn(m,n,d,X)`` | ``randn(m,n,X)`` | Creates a *m*-by-*n* random matrix (of |
| | | density *d*) with iid non-zero elements|
| | | distributed according to the *X* |
| | | distribution. (Requires the |
| | | ``Distributions`` package.) |
+-----------------------+-------------------+----------------------------------------+
| ``sprandbool(m,n,d)`` | ``randbool(m,n)`` | Creates a *n*-by-*n* random matrix (of |
| ``sprandbool(m,n,d)`` | ``randbool(m,n)`` | Creates a *m*-by-*n* random matrix (of |
| | | density *d*) with non-zero ``Bool`` |
| | | elements with probability *d* (*d* =0.5|
| | | for ``randbool``.) |
Expand Down
26 changes: 8 additions & 18 deletions doc/manual/running-external-programs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Here's a simple example of actually running an external program::

julia> run(`echo hello`)
hello
true

The ``hello`` is the output of the ``echo`` command, sent to stdout.
The run method itself returns ``Nothing``, and throws an ``ErrorException``
Expand Down Expand Up @@ -184,7 +183,6 @@ Julia::
1
2
3
true

julia> first = "A"; second = "B";

Expand All @@ -194,7 +192,6 @@ Julia::
julia> run(ans)
1: A
2: B
true

The results are identical, and Julia's interpolation behavior mimics the
shell's with some improvements due to the fact that Julia supports
Expand All @@ -213,30 +210,27 @@ backticks, a pipe is always just a pipe::

julia> run(`echo hello | sort`)
hello | sort
true

This expression invokes the ``echo`` command with three words as
arguments: "hello", "\|", and "sort". The result is that a single line
is printed: "hello \| sort". Inside of backticks, a "\|" is just a
literal pipe character. How, then, does one construct a pipeline?
Instead of using "\|" inside of backticks, one uses Julia's ``|``
Instead of using "\|" inside of backticks, one uses Julia's ``|>``
operator between ``Cmd`` objects::

julia> run(`echo hello` | `sort`)
julia> run(`echo hello` |> `sort`)
hello
true

This pipes the output of the ``echo`` command to the ``sort`` command.
Of course, this isn't terribly interesting since there's only one line
to sort, but we can certainly do much more interesting things::

julia> run(`cut -d: -f3 /etc/passwd` | `sort -n` | `tail -n5`)
julia> run(`cut -d: -f3 /etc/passwd` |> `sort -n` |> `tail -n5`)
210
211
212
213
214
true

This prints the highest five user IDs on a UNIX system. The ``cut``,
``sort`` and ``tail`` commands are all spawned as immediate children of
Expand All @@ -250,18 +244,16 @@ Julia can run multiple commands in parallel::
julia> run(`echo hello` & `echo world`)
world
hello
true

The order of the output here is non-deterministic because the two
``echo`` processes are started nearly simultaneously, and race to make
the first write to the ``stdout`` descriptor they share with each other
and the ``julia`` parent process. Julia lets you pipe the output from
both of these processes to another program::

julia> run(`echo world` & `echo hello` | `sort`)
julia> run(`echo world` & `echo hello` |> `sort`)
hello
world
true

In terms of UNIX plumbing, what's happening here is that a single UNIX
pipe object is created and written to by both ``echo`` processes, and
Expand All @@ -275,7 +267,7 @@ apologies for the excessive use of Perl one-liners::

julia> prefixer(prefix, sleep) = `perl -nle '$|=1; print "'$prefix' ", $_; sleep '$sleep';'`

julia> run(`perl -le '$|=1; for(0..9){ print; sleep 1 }'` | prefixer("A",2) & prefixer("B",2))
julia> run(`perl -le '$|=1; for(0..9){ print; sleep 1 }'` |> prefixer("A",2) & prefixer("B",2))
A 0
B 1
A 2
Expand All @@ -286,7 +278,6 @@ apologies for the excessive use of Perl one-liners::
B 7
A 8
B 9
true

This is a classic example of a single producer feeding two concurrent
consumers: one ``perl`` process generates lines with the numbers 0
Expand All @@ -301,8 +292,8 @@ once, to be read by just one consumer process.)

Here is an even more complex multi-stage producer-consumer example::

julia> run(`perl -le '$|=1; for(0..9){ print; sleep 1 }'` |
prefixer("X",3) & prefixer("Y",3) & prefixer("Z",3) |
julia> run(`perl -le '$|=1; for(0..9){ print; sleep 1 }'` |>
prefixer("X",3) & prefixer("Y",3) & prefixer("Z",3) |>
prefixer("A",2) & prefixer("B",2))
B Y 0
A Z 1
Expand All @@ -314,7 +305,6 @@ Here is an even more complex multi-stage producer-consumer example::
A Z 7
B X 8
A Y 9
true

This example is similar to the previous one, except there are two stages
of consumers, and the stages have different latency so they use a
Expand All @@ -329,7 +319,7 @@ itself::
julia> dup = `perl -ne '$|=1; warn $_; print ".$_"; sleep 1'`
`perl -ne '$|=1; warn $_; print ".$_"; sleep 1'`

julia> run(gen | dup | dup)
julia> run(gen |> dup |> dup)
0
.0
1
Expand Down
10 changes: 5 additions & 5 deletions doc/manual/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ subtype of the abstract type. If the type assertion is not true, an
exception is thrown, otherwise, the left-hand value is returned::

julia> (1+2)::FloatingPoint
type error: typeassert: expected FloatingPoint, got Int64
ERROR: type: typeassert: expected FloatingPoint, got Int64

julia> (1+2)::Int
3
Expand Down Expand Up @@ -461,13 +461,13 @@ Accordingly, a tuple of types can be used anywhere a type is expected::
(1,"foo",2.5)

julia> (1,"foo",2.5) :: (Int64,String,Float32)
type error: typeassert: expected (Int64,String,Float32), got (Int64,ASCIIString,Float64)
ERROR: type: typeassert: expected (Int64,String,Float32), got (Int64,ASCIIString,Float64)

If one of the components of the tuple is not a type, however, you will
get an error::

julia> (1,"foo",2.5) :: (Int64,String,3)
type error: typeassert: expected Type{T}, got (DataType,DataType,Int64)
ERROR: type: typeassert: expected Type{T<:Top}, got (DataType,DataType,Int64)

Note that the empty tuple ``()`` is its own type::

Expand Down Expand Up @@ -794,10 +794,10 @@ subtypes of ``Real``::
Pointy{Real}

julia> Pointy{String}
type error: Pointy: in T, expected Real, got Type{String}
ERROR: type: Pointy: in T, expected Real, got Type{String}

julia> Pointy{1}
type error: Pointy: in T, expected Real, got Int64
ERROR: type: Pointy: in T, expected Real, got Int64

Type parameters for parametric composite types can be restricted in the
same manner::
Expand Down
3 changes: 1 addition & 2 deletions doc/manual/variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ They can even be given Unicode names:
Julia will even let you redefine built-in constants and functions if needed::

julia> pi
3.141592653589793
π = 3.1415926535897...
julia> pi = 3
Warning: imported binding for pi overwritten in module Main
Expand Down
4 changes: 2 additions & 2 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ Generic Functions

Invoke a method for the given generic function matching the specified types (as a tuple), on the specified arguments. The arguments must be compatible with the specified types. This allows invoking a method other than the most specific matching method, which is useful when the behavior of a more general definition is explicitly needed (often as part of the implementation of a more specific method of the same function).

.. function:: |(x, f)
.. function:: |>(x, f)

Applies a function to the preceding argument which allows for easy function chaining.

**Example**: ``[1:5] | x->x.^2 | sum | inv``
**Example**: ``[1:5] |> x->x.^2 |> sum |> inv``

Iteration
---------
Expand Down
Loading

0 comments on commit b0a45c4

Please sign in to comment.