Skip to content
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
11 changes: 5 additions & 6 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5445,7 +5445,8 @@ julia> deleteat!([6, 5, 4, 3, 2, 1], 1:2:5)

julia> deleteat!([6, 5, 4, 3, 2, 1], (2, 2))
ERROR: ArgumentError: indices must be unique and sorted
in deleteat! at array.jl:543
in deleteat!(::Array{Int64,1}, ::Tuple{Int64,Int64}) at ./array.jl:511
...
```
"""
deleteat!(collection, itr)
Expand Down Expand Up @@ -8104,7 +8105,8 @@ julia> convert(Int, 3.0)

julia> convert(Int, 3.5)
ERROR: InexactError()
in convert at int.jl:209
in convert(::Type{Int64}, ::Float64) at ./int.jl:239
...
```

If `T` is a [`AbstractFloat`](:obj:`AbstractFloat`) or [`Rational`](:obj:`Rational`) type,
Expand Down Expand Up @@ -9120,10 +9122,7 @@ on the `permute` and `scale` keyword arguments. The eigenvectors are returned co
```jldoctest
julia> eig([1.0 0.0 0.0; 0.0 3.0 0.0; 0.0 0.0 18.0])
([1.0,3.0,18.0],
3×3 Array{Float64,2}:
1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0)
[1.0 0.0 0.0; 0.0 1.0 0.0; 0.0 0.0 1.0])
```

`eig` is a wrapper around [`eigfact`](:func:`eigfact`), extracting all parts of the
Expand Down
2 changes: 1 addition & 1 deletion base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ use it in the following manner to summarize information about a struct type:
julia> structinfo(T) = [(fieldoffset(T,i), fieldname(T,i), fieldtype(T,i)) for i = 1:nfields(T)];

julia> structinfo(Base.Filesystem.StatStruct)
12-element Array{Tuple{UInt64,Symbol,Type{_}},1}:
12-element Array{Tuple{UInt64,Union{Int64,Symbol},Type{_}},1}:
(0x0000000000000000,:device,UInt64)
(0x0000000000000008,:inode,UInt64)
(0x0000000000000010,:mode,UInt64)
Expand Down
17 changes: 6 additions & 11 deletions base/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -893,24 +893,19 @@ julia> typeof(f(1,2,3))
Int64

julia> @code_warntype f(1,2,3)
Variables:
#self#::#f
a::Int64
b::Int64
c::Int64

...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is Variables output no longer being included in @code_warntype intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was intentional. I can add it back if it is preferred. The blank line was being an issue and I felt that the variable listing didn't add anything to the example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right I see the ... now, I guess it's alright to leave it out

Body:
begin # REPL[2], line 1:
unless (Base.slt_int)(1,b::Int64)::Bool goto 4
begin
unless (Base.slt_int)(1,b::Int64)::Bool goto 3
return 1
4:
3:
return 1.0
end::Union{Float64,Int64}
end::UNION{FLOAT64,INT64}

julia> @inferred f(1,2,3)
ERROR: return type Int64 does not match inferred return type Union{Float64,Int64}
in error(::String) at ./error.jl:21
in eval(::Module, ::Any) at ./boot.jl:226
...

julia> @inferred max(1,2)
2
Expand Down
11 changes: 8 additions & 3 deletions doc/devdocs/reflection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ the macro will be evaluated and the result will be passed instead!). For example
.. doctest::

julia> macroexpand( :(@edit println("")) )
:(Base.edit(println,(Base.typesof)("")))
:((Base.edit)(println,(Base.typesof)("")))

The functions :func:`Base.Meta.show_sexpr` and :func:`dump` are used to display S-expr style views
and depth-nested detail views for any expression.
Expand All @@ -104,9 +104,14 @@ variable assignments:
.. doctest::

julia> expand( :(f() = 1) )
:($(Expr(:method, :f, :((top(svec))((top(apply_type))(Tuple),(top(svec))())), AST(:($(Expr(:lambda, Any[], Any[Any[],Any[],0,Any[]], :(begin # none, line 1:
:(begin
$(Expr(:method, :f))
$(Expr(:method, :f, :((Core.svec)((Core.apply_type)(Tuple,(Core.Typeof)(f)),(Core.svec)())), Toplevel LambdaInfo thunk
:(begin # none, line 1:
return 1
end))))), false)))
end), false))
return f
end)

.. rubric:: Intermediate and compiled representations

Expand Down
87 changes: 43 additions & 44 deletions doc/devdocs/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Let's look at these types a little more closely:
Array{T,N}

julia> dump(Array)
Array{T,N}::DataType <: DenseArray{T,N}
Array{T,N} <: DenseArray{T,N}

This indicates that :obj:`Array` is a shorthand for ``Array{T,N}``. If
you type this at the REPL prompt---on its own, not while defining
Expand All @@ -108,7 +108,7 @@ parameters:
TypeVar
name: Symbol T
lb: Union{}
ub: Any::DataType <: Any
ub: Any
bound: Bool false

A :obj:`TypeVar` is one of Julia's built-in types---it's defined in
Expand All @@ -130,17 +130,17 @@ one can extract the underlying :obj:`TypeVar`:
.. testcode:: s

g{S<:Integer}(x::S) = 0
m = start(methods(g))
m = first(methods(g))
p = m.sig.parameters
tv = p[1]
tv = p[2]
dump(tv)

.. testoutput:: s

TypeVar
name: Symbol S
lb: Union{}
ub: Integer::DataType <: Real
ub: Integer <: Real
bound: Bool true

Here ``ub`` is ``Integer``, as specified in the function definition.
Expand All @@ -160,27 +160,27 @@ parameters. For example:
julia> h3{T<:Real}(A::Array{T}, b::T) = 1
h3 (generic function with 1 method)

julia> p1 = start(methods(h1)).sig.parameters
svec(Array{T,N},Real)
julia> p1 = first(methods(h1)).sig.parameters
svec(#h1,Array{T,N},Real)

julia> p2 = start(methods(h2)).sig.parameters
svec(Array{T,N},T<:Real)
julia> p2 = first(methods(h2)).sig.parameters
svec(#h2,Array{T,N},T<:Real)

julia> p3 = start(methods(h3)).sig.parameters
svec(Array{T<:Real,N},T<:Real)
julia> p3 = first(methods(h3)).sig.parameters
svec(#h3,Array{T<:Real,N},T<:Real)

julia> dump(p1[1].parameters[1])
julia> dump(p1[2].parameters[1])
TypeVar
name: Symbol T
lb: Union{}
ub: Any::DataType <: Any
ub: Any
bound: Bool false

julia> dump(p3[1].parameters[1])
julia> dump(p3[2].parameters[1])
TypeVar
name: Symbol T
lb: Union{}
ub: Real::DataType <: Number
ub: Real <: Number
bound: Bool true

Note that ``p2`` shows two objects called ``T``, but only one of them
Expand Down Expand Up @@ -215,20 +215,21 @@ a lot about how Julia does dispatch:

julia> methods(candid)
# 1 method for generic function "candid":
candid{T}(A::Array{T,N}, x::T) at none:1
candid{T}(A::Array{T,N<:Any}, x::T) at none:1

julia> methods(sneaky)
# 1 method for generic function "sneaky":
sneaky{T}(A::Array{T,N}, x::T) at none:1
sneaky{T}(A::Array{T,N<:Any}, x::T<:Any) at none:1

These therefore print identically, but they have very different behavior:

.. doctest::

julia> candid([1],3.2)
ERROR: MethodError: `candid` has no method matching candid(::Array{Int64,1}, ::Float64)
ERROR: MethodError: no method matching candid(::Array{Int64,1}, ::Float64)
Closest candidates are:
candid{T}(::Array{T,N}, !Matched::T)
...

julia> sneaky([1],3.2)
1
Expand All @@ -244,11 +245,11 @@ bound :obj:`TypeVar` objects with a hash (``#T`` instead of ``T``):

.. doctest::

julia> jl_(start(methods(candid)))
Method(sig=Tuple{Array{#T<:Any, N<:Any}, #T<:Any}, va=false, isstaged=false, tvars=#T<:Any, func=#<function>, invokes=nothing, next=nothing)
julia> jl_(first(methods(candid)))
Method(sig=Tuple{Main.#candid, Array{#T<:Any, N<:Any}, #T<:Any}, va=false, isstaged=false, tvars=#T<:Any, func=Main.candid(?), invokes=nothing, next=nothing)

julia> jl_(start(methods(sneaky)))
Method(sig=Tuple{Array{#T<:Any, N<:Any}, T<:Any}, va=false, isstaged=false, tvars=#T<:Any, func=#<function>, invokes=nothing, next=nothing)
julia> jl_(first(methods(sneaky)))
Method(sig=Tuple{Main.#sneaky, Array{#T<:Any, N<:Any}, T<:Any}, va=false, isstaged=false, tvars=#T<:Any, func=Main.sneaky(?), invokes=nothing, next=nothing)

Even though both print as ``T``, in ``sneaky`` the second ``T`` is
not bound, and hence it isn't constrained to be the same type as the
Expand Down Expand Up @@ -314,14 +315,22 @@ the type, which is an object of type :obj:`TypeName`:
TypeName
name: Symbol Array
module: Module Core
names: SimpleVector
length: Int64 0
primary: Array{T,N}::DataType <: DenseArray{T,N}
names: empty SimpleVector
primary: Array{T,N} <: DenseArray{T,N}
cache: SimpleVector
length: Int64 135
...
linearcache: SimpleVector
length: Int64 18
uid: Int64 37
...
uid: Int64 47
mt: MethodTable
name: Symbol Array
defs: Void nothing
cache: Void nothing
max_args: Int64 0
kwsorter: #undef
module: Module Core
: Int64 0
: Int64 0

In this case, the relevant field is ``primary``, which holds a
reference to the "primary" instance of the type::
Expand Down Expand Up @@ -357,20 +366,10 @@ type:
MyType{Float32,5}

julia> MyType.name.cache
svec(MyType{Float32,5},MyType{Int64,2},Evaluation succeeded, but an error occurred while showing value of type SimpleVector:
ERROR: UndefRefError: access to undefined reference
in getindex at ./essentials.jl:211
in show_delim_array at show.jl:229
in show at show.jl:257
in anonymous at show.jl:1278
in with_output_limit at ./show.jl:1255
in showlimited at show.jl:1277
in display at multimedia.jl:120
[inlined code] from multimedia.jl:151
in display at multimedia.jl:162

(The error is triggered because the cache is pre-allocated to have
length 8, but only the first two entries are populated.)
svec(MyType{Float32,5},MyType{Int64,2},#undef,#undef,#undef,#undef,#undef,#undef)

(The cache is pre-allocated to have length 8, but only the first two entries
are populated.)
Consequently, when you instantiate a parametric type, each concrete
type gets saved in a type-cache. However, instances with :obj:`TypeVar`
parameters are not cached.
Expand All @@ -388,15 +387,15 @@ able to accommodate any tuple. Let's check the parameters:
Tuple

julia> Tuple.parameters
svec(Vararg{Any})
svec(Vararg{Any,N})

It's worth noting that the parameter is a type, ``Any``, rather than a
``TypeVar T<:Any``: compare

.. doctest::

julia> jl_(Tuple.parameters)
svec(Vararg{Any})
svec(Vararg{Any, N<:Any})

julia> jl_(Array.parameters)
svec(T<:Any, N<:Any)
Expand Down
26 changes: 13 additions & 13 deletions doc/manual/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ Example:
.. doctest::

julia> x = reshape(1:16, 4, 4)
4×4 Array{Int64,2}:
4×4 Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}}:
1 5 9 13
2 6 10 14
3 7 11 15
Expand All @@ -327,7 +327,7 @@ Example:
16

julia> x[1, [2 3; 4 1]]
2x2 Array{Int64,2}:
2×2 Array{Int64,2}:
5 9
13 1

Expand Down Expand Up @@ -376,7 +376,7 @@ Example:

.. doctest::

julia> x = reshape(1:9, 3, 3)
julia> x = collect(reshape(1:9, 3, 3))
3×3 Array{Int64,2}:
1 4 7
2 5 8
Expand Down Expand Up @@ -411,7 +411,7 @@ The first construct is used when you need the value, but not index, of each elem
type with fast linear indexing; otherwise, it will be a ``CartesianIndex``::

A = rand(4,3)
B = sub(A, 1:3, 2:3)
B = view(A, 1:3, 2:3)
julia> for i in eachindex(B)
@show i
end
Expand Down Expand Up @@ -497,9 +497,9 @@ the name of the function to vectorize. Here is a simple example:

julia> methods(square)
# 4 methods for generic function "square":
square{T<:Number}(::AbstractArray{T<:Number,1}) at operators.jl:374
square{T<:Number}(::AbstractArray{T<:Number,2}) at operators.jl:375
square{T<:Number}(::AbstractArray{T<:Number,N}) at operators.jl:377
square{T<:Number}(x::AbstractArray{T,1}) at operators.jl:...
square{T<:Number}(x::AbstractArray{T,2}) at operators.jl:...
square{T<:Number}(x::AbstractArray{T,N<:Any}) at operators.jl:...
square(x) at none:1

julia> square([1 2 4; 5 6 7])
Expand Down Expand Up @@ -599,10 +599,10 @@ library can be implemented in a generic manner.

:obj:`SubArray` is a specialization of :obj:`AbstractArray` that performs
indexing by reference rather than by copying. A :obj:`SubArray` is created
with the :func:`sub` function, which is called the same way as :func:`getindex` (with
an array and a series of index arguments). The result of :func:`sub` looks
with the :func:`view` function, which is called the same way as :func:`getindex`
(with an array and a series of index arguments). The result of :func:`view` looks
the same as the result of :func:`getindex`, except the data is left in place.
:func:`sub` stores the input index vectors in a :obj:`SubArray` object, which
:func:`view` stores the input index vectors in a :obj:`SubArray` object, which
can later be used to index the original array indirectly.

:obj:`StridedVector` and :obj:`StridedMatrix` are convenient aliases defined
Expand Down Expand Up @@ -630,8 +630,8 @@ stride parameters.
0.890947 0.168877 0.32002 0.486136 0.096078 0.172048 0.77672
0.507762 0.573567 0.220124 0.165816 0.211049 0.433277 0.539476

julia> b = sub(a, 2:2:8,2:2:4)
4×2 SubArray{Float64,2,Array{Float64,2},Tuple{StepRange{Int64,Int64},StepRange{Int64,Int64}},1}:
julia> b = view(a, 2:2:8,2:2:4)
4×2 SubArray{Float64,2,Array{Float64,2},Tuple{StepRange{Int64,Int64},StepRange{Int64,Int64}},false}:
0.537192 0.996234
0.736979 0.228787
0.991511 0.74485
Expand Down Expand Up @@ -716,7 +716,7 @@ you can use the same names with an ``sp`` prefix:
.. doctest::

julia> spzeros(3,5)
3×5 sparse matrix with 0 Float64 nonzero entries:
3×5 sparse matrix with 0 Float64 nonzero entries

julia> speye(3,5)
3×5 sparse matrix with 3 Float64 nonzero entries:
Expand Down
4 changes: 3 additions & 1 deletion doc/manual/complex-and-rational-numbers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ versus ``-1 + 0im`` even though ``-1 == -1 + 0im``:
julia> sqrt(-1)
ERROR: DomainError:
sqrt will only return a complex result if called with a complex argument. Try sqrt(complex(x)).
in sqrt at math.jl:146
in sqrt(::Int64) at ./math.jl:149
...

julia> sqrt(-1 + 0im)
0.0 + 1.0im
Expand Down Expand Up @@ -305,6 +306,7 @@ Trying to construct a :const:`NaN` rational value, however, is not:
ERROR: ArgumentError: invalid rational: zero(Int64)//zero(Int64)
in Rational{Int64}(::Int64, ::Int64) at ./rational.jl:8
in //(::Int64, ::Int64) at ./rational.jl:22
...

As usual, the promotion system makes interactions with other numeric
types effortless:
Expand Down
Loading