From b24347787f88d5fe9a85e284ff76170d4f69b47d Mon Sep 17 00:00:00 2001 From: WooKyoung Noh Date: Mon, 27 Nov 2017 18:21:52 +0900 Subject: [PATCH 1/4] =?UTF-8?q?codex=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20Julia=20Commit=2031995428f8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codex/devdocs/llvm.md | 2 +- codex/devdocs/offset-arrays.md | 4 +- codex/devdocs/subarrays.md | 2 +- codex/index.md | 1 + codex/manual/arrays.md | 40 ++--- codex/manual/constructors.md | 2 +- codex/manual/faq.md | 13 +- codex/manual/interfaces.md | 203 ++++++++++++++++++++++++- codex/manual/linear-algebra.md | 1 - codex/manual/methods.md | 2 +- codex/manual/modules.md | 2 +- codex/manual/noteworthy-differences.md | 2 +- codex/manual/parallel-computing.md | 13 +- codex/manual/performance-tips.md | 6 +- codex/manual/style-guide.md | 4 +- codex/manual/variables-and-scoping.md | 6 +- codex/stdlib/.gitignore | 1 + codex/stdlib/arrays.md | 15 +- codex/stdlib/base.md | 3 +- codex/stdlib/index.md | 1 + codex/stdlib/iterativeeigensolvers.md | 7 + codex/stdlib/linalg.md | 3 - codex/stdlib/strings.md | 1 + src/devdocs/llvm.md | 2 +- src/devdocs/offset-arrays.md | 4 +- src/devdocs/subarrays.md | 2 +- src/index.md | 1 + src/manual/arrays.md | 40 ++--- src/manual/constructors.md | 2 +- src/manual/faq.md | 13 +- src/manual/interfaces.md | 203 ++++++++++++++++++++++++- src/manual/linear-algebra.md | 1 - src/manual/methods.md | 2 +- src/manual/modules.md | 2 +- src/manual/noteworthy-differences.md | 2 +- src/manual/parallel-computing.md | 13 +- src/manual/performance-tips.md | 6 +- src/manual/style-guide.md | 4 +- src/manual/variables-and-scoping.md | 6 +- src/stdlib/.gitignore | 10 ++ src/stdlib/arrays.md | 15 +- src/stdlib/base.md | 3 +- src/stdlib/index.md | 1 + src/stdlib/iterativeeigensolvers.md | 7 + src/stdlib/linalg.md | 3 - src/stdlib/strings.md | 1 + 46 files changed, 565 insertions(+), 112 deletions(-) create mode 100644 codex/stdlib/iterativeeigensolvers.md create mode 100644 src/stdlib/.gitignore create mode 100644 src/stdlib/iterativeeigensolvers.md diff --git a/codex/devdocs/llvm.md b/codex/devdocs/llvm.md index de176ea..0300373 100644 --- a/codex/devdocs/llvm.md +++ b/codex/devdocs/llvm.md @@ -5,7 +5,7 @@ LLVM for Julia. ## Overview of Julia to LLVM Interface -Julia statically links in LLVM by default. Build with `USE_LLVM_SHLIB=1` to link dynamically. +Julia dynamically links against LLVM by default. Build with `USE_LLVM_SHLIB=0` to link statically. The code for lowering Julia AST to LLVM IR or interpreting it directly is in directory `src/`. diff --git a/codex/devdocs/offset-arrays.md b/codex/devdocs/offset-arrays.md index e369986..7ad1dfb 100644 --- a/codex/devdocs/offset-arrays.md +++ b/codex/devdocs/offset-arrays.md @@ -97,7 +97,7 @@ end ### Allocating storage using generalizations of `similar` -Storage is often allocated with `Array{Int}(dims)` or `similar(A, args...)`. When the result needs +Storage is often allocated with `Array{Int}(uninitialized, dims)` or `similar(A, args...)`. When the result needs to match the indices of some other array, this may not always suffice. The generic replacement for such patterns is to use `similar(storagetype, shape)`. `storagetype` indicates the kind of underlying "conventional" behavior you'd like, e.g., `Array{Int}` or `BitArray` or even `dims->zeros(Float32, dims)` @@ -109,7 +109,7 @@ Let's walk through a couple of explicit examples. First, if `A` has conventional `similar(Array{Int}, indices(A))` would end up calling `Array{Int}(size(A))`, and thus return an array. If `A` is an `AbstractArray` type with unconventional indexing, then `similar(Array{Int}, indices(A))` should return something that "behaves like" an `Array{Int}` but with a shape (including indices) -that matches `A`. (The most obvious implementation is to allocate an `Array{Int}(size(A))` and +that matches `A`. (The most obvious implementation is to allocate an `Array{Int}(uninitialized, size(A))` and then "wrap" it in a type that shifts the indices.) Note also that `similar(Array{Int}, (indices(A, 2),))` would allocate an `AbstractVector{Int}` diff --git a/codex/devdocs/subarrays.md b/codex/devdocs/subarrays.md index 5c87b62..71d6f33 100644 --- a/codex/devdocs/subarrays.md +++ b/codex/devdocs/subarrays.md @@ -108,7 +108,7 @@ of the parent array, whereas for `S2` one needs to apply them to the second and approach to indexing would be to do the type-analysis at runtime: ```julia -parentindexes = Array{Any}(0) +parentindexes = Vector{Any}() for thisindex in S.indexes ... if isa(thisindex, Int) diff --git a/codex/index.md b/codex/index.md index 2c7fa3a..abb6f6e 100644 --- a/codex/index.md +++ b/codex/index.md @@ -71,6 +71,7 @@ * [Shared Arrays](@ref) * [Base64](@ref) * [File Events](@ref lib-filewatching) + * [Iterative Eigensolvers](@ref lib-itereigen) ## Developer Documentation diff --git a/codex/manual/arrays.md b/codex/manual/arrays.md index 92fbc72..39d4614 100644 --- a/codex/manual/arrays.md +++ b/codex/manual/arrays.md @@ -50,26 +50,26 @@ omitted it will default to [`Float64`](@ref). | Function | Description | |:---------------------------------- |:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [`Array{T}(dims...)`](@ref) | an uninitialized dense [`Array`](@ref) | -| [`zeros(T, dims...)`](@ref) | an `Array` of all zeros | -| [`zeros(A)`](@ref) | an array of all zeros with the same type, element type and shape as `A` | -| [`ones(T, dims...)`](@ref) | an `Array` of all ones | -| [`ones(A)`](@ref) | an array of all ones with the same type, element type and shape as `A` | -| [`trues(dims...)`](@ref) | a [`BitArray`](@ref) with all values `true` | -| [`trues(A)`](@ref) | a `BitArray` with all values `true` and the same shape as `A` | -| [`falses(dims...)`](@ref) | a `BitArray` with all values `false` | -| [`falses(A)`](@ref) | a `BitArray` with all values `false` and the same shape as `A` | -| [`reshape(A, dims...)`](@ref) | an array containing the same data as `A`, but with different dimensions | -| [`copy(A)`](@ref) | copy `A` | -| [`deepcopy(A)`](@ref) | copy `A`, recursively copying its elements | -| [`similar(A, T, dims...)`](@ref) | an uninitialized array of the same type as `A` (dense, sparse, etc.), but with the specified element type and dimensions. The second and third arguments are both optional, defaulting to the element type and dimensions of `A` if omitted. | -| [`reinterpret(T, A)`](@ref) | an array with the same binary data as `A`, but with element type `T` | -| [`rand(T, dims...)`](@ref) | an `Array` with random, iid [^1] and uniformly distributed values in the half-open interval ``[0, 1)`` | -| [`randn(T, dims...)`](@ref) | an `Array` with random, iid and standard normally distributed values | -| [`Matrix{T}(I, m, n)`](@ref) | `m`-by-`n` identity matrix | -| [`linspace(start, stop, n)`](@ref) | range of `n` linearly spaced elements from `start` to `stop` | -| [`fill!(A, x)`](@ref) | fill the array `A` with the value `x` | -| [`fill(x, dims...)`](@ref) | an `Array` filled with the value `x` | +| [`Array{T}(uninitialized, dims...)`](@ref) | an uninitialized dense [`Array`](@ref) | +| [`zeros(T, dims...)`](@ref) | an `Array` of all zeros | +| [`zeros(A)`](@ref) | an array of all zeros with the same type, element type and shape as `A` | +| [`ones(T, dims...)`](@ref) | an `Array` of all ones | +| [`ones(A)`](@ref) | an array of all ones with the same type, element type and shape as `A` | +| [`trues(dims...)`](@ref) | a [`BitArray`](@ref) with all values `true` | +| [`trues(A)`](@ref) | a `BitArray` with all values `true` and the same shape as `A` | +| [`falses(dims...)`](@ref) | a `BitArray` with all values `false` | +| [`falses(A)`](@ref) | a `BitArray` with all values `false` and the same shape as `A` | +| [`reshape(A, dims...)`](@ref) | an array containing the same data as `A`, but with different dimensions | +| [`copy(A)`](@ref) | copy `A` | +| [`deepcopy(A)`](@ref) | copy `A`, recursively copying its elements | +| [`similar(A, T, dims...)`](@ref) | an uninitialized array of the same type as `A` (dense, sparse, etc.), but with the specified element type and dimensions. The second and third arguments are both optional, defaulting to the element type and dimensions of `A` if omitted. | +| [`reinterpret(T, A)`](@ref) | an array with the same binary data as `A`, but with element type `T` | +| [`rand(T, dims...)`](@ref) | an `Array` with random, iid [^1] and uniformly distributed values in the half-open interval ``[0, 1)`` | +| [`randn(T, dims...)`](@ref) | an `Array` with random, iid and standard normally distributed values | +| [`Matrix{T}(I, m, n)`](@ref) | `m`-by-`n` identity matrix | +| [`linspace(start, stop, n)`](@ref) | range of `n` linearly spaced elements from `start` to `stop` | +| [`fill!(A, x)`](@ref) | fill the array `A` with the value `x` | +| [`fill(x, dims...)`](@ref) | an `Array` filled with the value `x` | [^1]: *iid*, independently and identically distributed. diff --git a/codex/manual/constructors.md b/codex/manual/constructors.md index cfc879c..330ed28 100644 --- a/codex/manual/constructors.md +++ b/codex/manual/constructors.md @@ -524,7 +524,7 @@ one type to another, you should probably define a `convert` method instead. On the other hand, if your constructor does not represent a lossless conversion, or doesn't represent "conversion" at all, it is better to leave it as a constructor rather than a `convert` method. -For example, the `Array{Int}()` constructor creates a zero-dimensional `Array` of the type `Int`, +For example, the `Array{Int,0}(uninitialized)` constructor creates a zero-dimensional `Array` of the type `Int`, but is not really a "conversion" from `Int` to an `Array`. ## Outer-only constructors diff --git a/codex/manual/faq.md b/codex/manual/faq.md index 745c8f2..eea3827 100644 --- a/codex/manual/faq.md +++ b/codex/manual/faq.md @@ -566,12 +566,13 @@ julia> gvar_self = "Node1" julia> remotecall_fetch(()->gvar_self, 2) "Node1" -julia> remotecall_fetch(whos, 2) - From worker 2: Base 41762 KB Module - From worker 2: Core 27337 KB Module - From worker 2: Foo 2477 bytes Module - From worker 2: Main 46191 KB Module - From worker 2: gvar_self 13 bytes String +julia> remotecall_fetch(varinfo, 2) +name size summary +––––––––– –––––––– ––––––– +Base Module +Core Module +Main Module +gvar_self 13 bytes String ``` This does not apply to `function` or `type` declarations. However, anonymous functions bound to global diff --git a/codex/manual/interfaces.md b/codex/manual/interfaces.md index 7e19c25..1cb9454 100644 --- a/codex/manual/interfaces.md +++ b/codex/manual/interfaces.md @@ -226,7 +226,7 @@ ourselves, we can officially define it as a subtype of an [`AbstractArray`](@ref | `similar(A)` | `similar(A, eltype(A), size(A))` | Return a mutable array with the same shape and element type | | `similar(A, ::Type{S})` | `similar(A, S, size(A))` | Return a mutable array with the same shape and the specified element type | | `similar(A, dims::NTuple{Int})` | `similar(A, eltype(A), dims)` | Return a mutable array with the same element type and size *dims* | -| `similar(A, ::Type{S}, dims::NTuple{Int})` | `Array{S}(dims)` | Return a mutable array with the specified element type and size | +| `similar(A, ::Type{S}, dims::NTuple{Int})` | `Array{S}(uninitialized, dims)` | Return a mutable array with the specified element type and size | | **Non-traditional indices** | **Default definition** | **Brief description** | | `indices(A)` | `map(OneTo, size(A))` | Return the `AbstractUnitRange` of valid indices | | `Base.similar(A, ::Type{S}, inds::NTuple{Ind})` | `similar(A, S, Base.to_shape(inds))` | Return a mutable array with the specified indices `inds` (see below) | @@ -390,3 +390,204 @@ If you are defining an array type that allows non-traditional indexing (indices something other than 1), you should specialize `indices`. You should also specialize [`similar`](@ref) so that the `dims` argument (ordinarily a `Dims` size-tuple) can accept `AbstractUnitRange` objects, perhaps range-types `Ind` of your own design. For more information, see [Arrays with custom indices](@ref). + +## [Broadcasting](@id man-interfaces-broadcasting) + +| Methods to implement | Brief description | +|:-------------------- |:----------------- | +| `Base.BroadcastStyle(::Type{SrcType}) = SrcStyle()` | Broadcasting behavior of `SrcType` | +| `Base.broadcast_similar(f, ::DestStyle, ::Type{ElType}, inds, As...)` | Allocation of output container | +| **Optional methods** | | | +| `Base.BroadcastStyle(::Style1, ::Style2) = Style12()` | Precedence rules for mixing styles | +| `Base.broadcast_indices(::StyleA, A)` | Declaration of the indices of `A` for broadcasting purposes (for AbstractArrays, defaults to `indices(A)`) | +| **Bypassing default machinery** | | +| `broadcast(f, As...)` | Complete bypass of broadcasting machinery | +| `broadcast(f, ::DestStyle, ::Void, ::Void, As...)` | Bypass after container type is computed | +| `broadcast(f, ::DestStyle, ::Type{ElType}, inds::Tuple, As...)` | Bypass after container type, eltype, and indices are computed | + +[Broadcasting](@ref) is triggered by an explicit call to `broadcast` or `broadcast!`, or implicitly by +"dot" operations like `A .+ b`. Any `AbstractArray` type supports broadcasting, +but the default result (output) type is `Array`. To specialize the result for specific input type(s), +the main task is the allocation of an appropriate result object. +(This is not an issue for `broadcast!`, where +the result object is passed as an argument.) This process is split into two stages: computation +of the behavior and type from the arguments ([`Base.BroadcastStyle`](@ref)), and allocation of the object +given the resulting type with [`Base.broadcast_similar`](@ref). + +`Base.BroadcastStyle` is an abstract type from which all styles are +derived. When used as a function it has two possible forms, +unary (single-argument) and binary. +The unary variant states that you intend to +implement specific broadcasting behavior and/or output type, +and do not wish to rely on the default fallback ([`Broadcast.Scalar`](@ref) or [`Broadcast.DefaultArrayStyle`](@ref)). +To achieve this, you can define a custom `BroadcastStyle` for your object: + +```julia +struct MyStyle <: Broadcast.BroadcastStyle end +Base.BroadcastStyle(::Type{<:MyType}) = MyStyle() +``` + +In some cases it might be convenient not to have to define `MyStyle`, in which case you can +leverage one of the general broadcast wrappers: + + - `Base.BroadcastStyle(::Type{<:MyType}) = Broadcast.Style{MyType}()` can be + used for arbitrary types. + - `Base.BroadcastStyle(::Type{<:MyType}) = Broadcast.ArrayStyle{MyType}()` is preferred + if `MyType` is an `AbstractArray`. + - For `AbstractArrays` that only support a certain dimensionality, create a subtype of `Broadcast.AbstractArrayStyle{N}` (see below). + +When your broadcast operation involves several arguments, individual argument styles get +combined to determine a single `DestStyle` that controls the type of the output container. +For more detail, see [below](@ref writing-binary-broadcasting-rules). + +The actual allocation of the result array is handled by `Base.broadcast_similar`: + +```julia +Base.broadcast_similar(f, ::DestStyle, ::Type{ElType}, inds, As...) +``` + +`f` is the operation being performed and `DestStyle` signals the final result from +combining the input styles. +`As...` is the list of input objects. You may not need to use `f` or `As...` +unless they help you build the appropriate object; the fallback definition is + +```julia +broadcast_similar(f, ::DefaultArrayStyle{N}, ::Type{ElType}, inds::Indices{N}, As...) where {N,ElType} = + similar(Array{ElType}, inds) +``` + +However, if needed you can specialize on any or all of these arguments. + +For a complete example, let's say you have created a type, `ArrayAndChar`, that stores an +array and a single character: + +```jldoctest +struct ArrayAndChar{T,N} <: AbstractArray{T,N} + data::Array{T,N} + char::Char +end +Base.size(A::ArrayAndChar) = size(A.data) +Base.getindex(A::ArrayAndChar{T,N}, inds::Vararg{Int,N}) where {T,N} = A.data[inds...] +Base.setindex!(A::ArrayAndChar{T,N}, val, inds::Vararg{Int,N}) where {T,N} = A.data[inds...] = val +Base.showarg(io::IO, A::ArrayAndChar, toplevel) = print(io, typeof(A), " with char '", A.char, "'") +``` + +You might want broadcasting to preserve the `char` "metadata." First we define + +```jldoctest +Base.BroadcastStyle(::Type{<:ArrayAndChar}) = Broadcast.ArrayStyle{ArrayAndChar}() +``` + +This forces us to also define a `broadcast_similar` method: +```jldoctest +function Base.broadcast_similar(f, ::Broadcast.ArrayStyle{ArrayAndChar}, ::Type{ElType}, inds, As...) where ElType + # Scan the inputs for the ArrayAndChar: + A = find_aac(As...) + # Use the char field of A to create the output + ArrayAndChar(similar(Array{ElType}, inds), A.char) +end + +"`A = find_aac(As...)` returns the first ArrayAndChar among the arguments." +find_aac(A::ArrayAndChar, B...) = A +find_aac(A, B...) = find_aac(B...) +``` + +From these definitions, one obtains the following behavior: +```jldoctest +julia> a = ArrayAndChar([1 2; 3 4], 'x') +2×2 ArrayAndChar{Int64,2} with char 'x': + 1 2 + 3 4 + +julia> a .+ 1 +2×2 ArrayAndChar{Int64,2} with char 'x': + 2 3 + 4 5 + +julia> a .+ [5,10] +2×2 ArrayAndChar{Int64,2} with char 'x': + 6 7 + 13 14 +``` + +Finally, it's worth noting that sometimes it's easier simply to bypass the machinery for +computing result types and container sizes, and just do everything manually. For example, +you can convert a `UnitRange{Int}` `r` to a `UnitRange{BigInt}` with `big.(r)`; the definition +of this method is approximately + +```julia +Broadcast.broadcast(::typeof(big), r::UnitRange) = big(first(r)):big(last(r)) +``` + +This exploits Julia's ability to dispatch on a particular function type. (This kind of +explicit definition can indeed be necessary if the output container does not support `setindex!`.) +You can optionally choose to implement the actual broadcasting yourself, but allow +the internal machinery to compute the container type, element type, and indices by specializing + +```julia +Broadcast.broadcast(::typeof(somefunction), ::MyStyle, ::Type{ElType}, inds, As...) +``` + +### [Writing binary broadcasting rules](@id writing-binary-broadcasting-rules) + +The precedence rules are defined by binary `BroadcastStyle` calls: + +```julia +Base.BroadcastStyle(::Style1, ::Style2) = Style12() +``` + +where `Style12` is the `BroadcastStyle` you want to choose for outputs involving +arguments of `Style1` and `Style2`. For example, + +```julia +Base.BroadcastStyle(::Broadcast.Style{Tuple}, ::Broadcast.Scalar) = Broadcast.Style{Tuple}() +``` + +indicates that `Tuple` "wins" over scalars (the output container will be a tuple). +It is worth noting that you do not need to (and should not) define both argument orders +of this call; defining one is sufficient no matter what order the user supplies the arguments in. + +For `AbstractArray` types, defining a `BroadcastStyle` supersedes the fallback choice, +[`Broadcast.DefaultArrayStyle`](@ref). `DefaultArrayStyle` and the abstract supertype, `AbstractArrayStyle`, store the dimensionality as a type parameter to support specialized +array types that have fixed dimensionality requirements. + +`DefaultArrayStyle` "loses" to any other +`AbstractArrayStyle` that has been defined because of the following methods: + +```julia +BroadcastStyle(a::AbstractArrayStyle{Any}, ::DefaultArrayStyle) = a +BroadcastStyle(a::AbstractArrayStyle{N}, ::DefaultArrayStyle{N}) where N = a +BroadcastStyle(a::AbstractArrayStyle{M}, ::DefaultArrayStyle{N}) where {M,N} = + typeof(a)(_max(Val(M),Val(N))) +``` + +You do not need to write binary `BroadcastStyle` +rules unless you want to establish precedence for +two or more non-`DefaultArrayStyle` types. + +If your array type does have fixed dimensionality requirements, then you should +subtype `AbstractArrayStyle`. For example, the sparse array code has the following definitions: + +```julia +struct SparseVecStyle <: Broadcast.AbstractArrayStyle{1} end +struct SparseMatStyle <: Broadcast.AbstractArrayStyle{2} end +Base.BroadcastStyle(::Type{<:SparseVector}) = SparseVecStyle() +Base.BroadcastStyle(::Type{<:SparseMatrixCSC}) = SparseMatStyle() +``` + +Whenever you subtype `AbstractArrayStyle`, you also need to define rules for combining +dimensionalities, by creating a constructor for your style that takes a `Val(N)` argument. +For example: + +```julia +SparseVecStyle(::Val{0}) = SparseVecStyle() +SparseVecStyle(::Val{1}) = SparseVecStyle() +SparseVecStyle(::Val{2}) = SparseMatStyle() +SparseVecStyle(::Val{N}) where N = Broadcast.DefaultArrayStyle{N}() +``` + +These rules indicate that the combination of a `SparseVecStyle` with 0- or 1-dimensional arrays +yields another `SparseVecStyle`, that its combination with a 2-dimensional array +yields a `SparseMatStyle`, and anything of higher dimensionality falls back to the dense arbitrary-dimensional framework. +These rules allow broadcasting to keep the sparse representation for operations that result +in one or two dimensional outputs, but produce an `Array` for any other dimensionality. diff --git a/codex/manual/linear-algebra.md b/codex/manual/linear-algebra.md index 3a5cefc..8d8d4c2 100644 --- a/codex/manual/linear-algebra.md +++ b/codex/manual/linear-algebra.md @@ -275,7 +275,6 @@ of the standard library documentation. | `CholeskyPivoted` | [Pivoted](https://en.wikipedia.org/wiki/Pivot_element) Cholesky factorization | | `LU` | [LU factorization](https://en.wikipedia.org/wiki/LU_decomposition) | | `LUTridiagonal` | LU factorization for [`Tridiagonal`](@ref) matrices | -| `UmfpackLU` | LU factorization for sparse matrices (computed by UMFPack) | | `QR` | [QR factorization](https://en.wikipedia.org/wiki/QR_decomposition) | | `QRCompactWY` | Compact WY form of the QR factorization | | `QRPivoted` | Pivoted [QR factorization](https://en.wikipedia.org/wiki/QR_decomposition) | diff --git a/codex/manual/methods.md b/codex/manual/methods.md index 6b143ef..9e50c81 100644 --- a/codex/manual/methods.md +++ b/codex/manual/methods.md @@ -717,7 +717,7 @@ function matmul(a::AbstractMatrix, b::AbstractMatrix) # this is wrong, since depending on the return value # of type-inference is very brittle (as well as not being optimizable): - # R = return_types(op, (eltype(a), eltype(b))) + # R = Base.return_types(op, (eltype(a), eltype(b))) ## but, finally, this works: R = promote_op(op, eltype(a), eltype(b)) diff --git a/codex/manual/modules.md b/codex/manual/modules.md index 1baf633..e8bf887 100644 --- a/codex/manual/modules.md +++ b/codex/manual/modules.md @@ -119,7 +119,7 @@ end There are three important standard modules: Main, Core, and Base. Main is the top-level module, and Julia starts with Main set as the current module. Variables -defined at the prompt go in Main, and `whos()` lists variables in Main. +defined at the prompt go in Main, and `varinfo()` lists variables in Main. Core contains all identifiers considered "built in" to the language, i.e. part of the core language and not libraries. Every module implicitly specifies `using Core`, since you can't do anything diff --git a/codex/manual/noteworthy-differences.md b/codex/manual/noteworthy-differences.md index efcf3ea..26954d1 100644 --- a/codex/manual/noteworthy-differences.md +++ b/codex/manual/noteworthy-differences.md @@ -121,7 +121,7 @@ For users coming to Julia from R, these are some noteworthy differences: of the form `if cond; statement; end`, `cond && statement` and `!cond || statement`. Assignment statements in the latter two syntaxes must be explicitly wrapped in parentheses, e.g. `cond && (x = value)`. * In Julia, `<-`, `<<-` and `->` are not assignment operators. - * Julia's `->` creates an anonymous function, like Python. + * Julia's `->` creates an anonymous function. * Julia constructs vectors using brackets. Julia's `[1, 2, 3]` is the equivalent of R's `c(1, 2, 3)`. * Julia's [`*`](@ref) operator can perform matrix multiplication, unlike in R. If `A` and `B` are matrices, then `A * B` denotes a matrix multiplication in Julia, equivalent to R's `A %*% B`. diff --git a/codex/manual/parallel-computing.md b/codex/manual/parallel-computing.md index 8e58a29..b032767 100644 --- a/codex/manual/parallel-computing.md +++ b/codex/manual/parallel-computing.md @@ -312,12 +312,13 @@ julia> let B = B remotecall_fetch(()->B, 2) end; -julia> @spawnat 2 whos(); - -julia> From worker 2: A 800 bytes 10×10 Array{Float64,2} - From worker 2: Base Module - From worker 2: Core Module - From worker 2: Main Module +julia> @fetchfrom 2 varinfo() +name size summary +––––––––– ––––––––– –––––––––––––––––––––– +A 800 bytes 10×10 Array{Float64,2} +Base Module +Core Module +Main Module ``` As can be seen, global variable `A` is defined on worker 2, but `B` is captured as a local variable diff --git a/codex/manual/performance-tips.md b/codex/manual/performance-tips.md index 1217129..1b30724 100644 --- a/codex/manual/performance-tips.md +++ b/codex/manual/performance-tips.md @@ -646,7 +646,7 @@ julia> function fill_twos!(a) fill_twos! (generic function with 1 method) julia> function strange_twos(n) - a = Array{rand(Bool) ? Int64 : Float64}(n) + a = Vector{rand(Bool) ? Int64 : Float64}(uninitialized, n) fill_twos!(a) return a end @@ -933,7 +933,7 @@ function xinc!(ret::AbstractVector{T}, x::T) where T end function loopinc_prealloc() - ret = Array{Int}(3) + ret = Vector{Int}(uninitialized, 3) y = 0 for i = 1:10^7 xinc!(ret, i) @@ -1284,7 +1284,7 @@ end function main() n = 2000 - u = Array{Float64}(n) + u = Vector{Float64}(uninitialized, n) init!(u) du = similar(u) diff --git a/codex/manual/style-guide.md b/codex/manual/style-guide.md index 07defae..e586df2 100644 --- a/codex/manual/style-guide.md +++ b/codex/manual/style-guide.md @@ -147,10 +147,10 @@ some alternatives to consider: It is usually not much help to construct arrays like the following: ```julia -a = Array{Union{Int,AbstractString,Tuple,Array}}(n) +a = Vector{Union{Int,AbstractString,Tuple,Array}}(uninitialized, n) ``` -In this case `Array{Any}(n)` is better. It is also more helpful to the compiler to annotate specific +In this case `Vector{Any}(uninitialized, n)` is better. It is also more helpful to the compiler to annotate specific uses (e.g. `a[i]::Int`) than to try to pack many alternatives into one type. ## Use naming conventions consistent with Julia's `base/` diff --git a/codex/manual/variables-and-scoping.md b/codex/manual/variables-and-scoping.md index e21229c..ab9f0a9 100644 --- a/codex/manual/variables-and-scoping.md +++ b/codex/manual/variables-and-scoping.md @@ -359,7 +359,7 @@ something like `let x = x` since the two `x` variables are distinct and have sep Here is an example where the behavior of `let` is needed: ```jldoctest -julia> Fs = Array{Any}(2); i = 1; +julia> Fs = Vector{Any}(uninitialized, 2); i = 1; julia> while i <= 2 Fs[i] = ()->i @@ -378,7 +378,7 @@ variable `i`, so the two closures behave identically. We can use `let` to create for `i`: ```jldoctest -julia> Fs = Array{Any}(2); i = 1; +julia> Fs = Vector{Any}(uninitialized, 2); i = 1; julia> while i <= 2 let i = i @@ -418,7 +418,7 @@ introduced in their body scopes are freshly allocated for each loop iteration, a were surrounded by a `let` block: ```jldoctest -julia> Fs = Array{Any}(2); +julia> Fs = Vector{Any}(uninitialized, 2); julia> for j = 1:2 Fs[j] = ()->j diff --git a/codex/stdlib/.gitignore b/codex/stdlib/.gitignore index 46adf75..e04ac81 100644 --- a/codex/stdlib/.gitignore +++ b/codex/stdlib/.gitignore @@ -6,4 +6,5 @@ profile.md base64.md filewatching.md crc32c.md +dates.md diff --git a/codex/stdlib/arrays.md b/codex/stdlib/arrays.md index 383b886..6d97c07 100644 --- a/codex/stdlib/arrays.md +++ b/codex/stdlib/arrays.md @@ -8,12 +8,14 @@ Base.AbstractVector Base.AbstractMatrix Core.Array Core.Array(::Any) +Core.Array(::Any, ::Any) Core.Uninitialized Core.uninitialized Base.Vector Base.Vector(::Any) +Base.Vector(::Any, ::Any) Base.Matrix -Base.Matrix(::Any, ::Any) +Base.Matrix(::Any, ::Any, ::Any) Base.getindex(::Type, ::Any...) Base.zeros Base.ones @@ -66,6 +68,17 @@ Base.Broadcast.broadcast_getindex Base.Broadcast.broadcast_setindex! ``` +For specializing broadcast on custom types, see +```@docs +Base.BroadcastStyle +Base.broadcast_similar +Base.broadcast_indices +Base.Broadcast.Scalar +Base.Broadcast.AbstractArrayStyle +Base.Broadcast.ArrayStyle +Base.Broadcast.DefaultArrayStyle +``` + ## Indexing and assignment ```@docs diff --git a/codex/stdlib/base.md b/codex/stdlib/base.md index c65875e..d29a4e5 100644 --- a/codex/stdlib/base.md +++ b/codex/stdlib/base.md @@ -23,7 +23,7 @@ Base.quit Base.atexit Base.atreplinit Base.isinteractive -Base.whos +Base.varinfo Base.summarysize Base.edit(::AbstractString, ::Integer) Base.edit(::Any) @@ -89,7 +89,6 @@ primitive type ## Base Modules ```@docs Base.BLAS -Base.Dates Base.Distributed Base.Docs Base.Iterators diff --git a/codex/stdlib/index.md b/codex/stdlib/index.md index be772c5..5b7ef9b 100644 --- a/codex/stdlib/index.md +++ b/codex/stdlib/index.md @@ -29,3 +29,4 @@ * [Shared Arrays](@ref) * [Base64](@ref) * [File Events](@ref lib-filewatching) + * [Iterative Eigensolvers](@ref lib-itereigen) diff --git a/codex/stdlib/iterativeeigensolvers.md b/codex/stdlib/iterativeeigensolvers.md new file mode 100644 index 0000000..ea5c50c --- /dev/null +++ b/codex/stdlib/iterativeeigensolvers.md @@ -0,0 +1,7 @@ +# [Iterative Eigensolvers](@id lib-itereigen) + +```@docs +IterativeEigenSolvers.eigs(::Any) +IterativeEigenSolvers.eigs(::Any, ::Any) +IterativeEigenSolvers.svds +``` diff --git a/codex/stdlib/linalg.md b/codex/stdlib/linalg.md index cb2aa82..b8c9fb1 100644 --- a/codex/stdlib/linalg.md +++ b/codex/stdlib/linalg.md @@ -136,9 +136,6 @@ Base.transpose Base.transpose! Base.adjoint Base.adjoint! -Base.LinAlg.eigs(::Any) -Base.LinAlg.eigs(::Any, ::Any) -Base.LinAlg.svds Base.LinAlg.peakflops Base.LinAlg.stride1 ``` diff --git a/codex/stdlib/strings.md b/codex/stdlib/strings.md index dca748e..36ed901 100644 --- a/codex/stdlib/strings.md +++ b/codex/stdlib/strings.md @@ -60,6 +60,7 @@ Base.chop Base.chomp Base.ind2chr Base.chr2ind +Base.thisind Base.nextind Base.prevind Base.Random.randstring diff --git a/src/devdocs/llvm.md b/src/devdocs/llvm.md index de176ea..0300373 100644 --- a/src/devdocs/llvm.md +++ b/src/devdocs/llvm.md @@ -5,7 +5,7 @@ LLVM for Julia. ## Overview of Julia to LLVM Interface -Julia statically links in LLVM by default. Build with `USE_LLVM_SHLIB=1` to link dynamically. +Julia dynamically links against LLVM by default. Build with `USE_LLVM_SHLIB=0` to link statically. The code for lowering Julia AST to LLVM IR or interpreting it directly is in directory `src/`. diff --git a/src/devdocs/offset-arrays.md b/src/devdocs/offset-arrays.md index e369986..7ad1dfb 100644 --- a/src/devdocs/offset-arrays.md +++ b/src/devdocs/offset-arrays.md @@ -97,7 +97,7 @@ end ### Allocating storage using generalizations of `similar` -Storage is often allocated with `Array{Int}(dims)` or `similar(A, args...)`. When the result needs +Storage is often allocated with `Array{Int}(uninitialized, dims)` or `similar(A, args...)`. When the result needs to match the indices of some other array, this may not always suffice. The generic replacement for such patterns is to use `similar(storagetype, shape)`. `storagetype` indicates the kind of underlying "conventional" behavior you'd like, e.g., `Array{Int}` or `BitArray` or even `dims->zeros(Float32, dims)` @@ -109,7 +109,7 @@ Let's walk through a couple of explicit examples. First, if `A` has conventional `similar(Array{Int}, indices(A))` would end up calling `Array{Int}(size(A))`, and thus return an array. If `A` is an `AbstractArray` type with unconventional indexing, then `similar(Array{Int}, indices(A))` should return something that "behaves like" an `Array{Int}` but with a shape (including indices) -that matches `A`. (The most obvious implementation is to allocate an `Array{Int}(size(A))` and +that matches `A`. (The most obvious implementation is to allocate an `Array{Int}(uninitialized, size(A))` and then "wrap" it in a type that shifts the indices.) Note also that `similar(Array{Int}, (indices(A, 2),))` would allocate an `AbstractVector{Int}` diff --git a/src/devdocs/subarrays.md b/src/devdocs/subarrays.md index 5c87b62..71d6f33 100644 --- a/src/devdocs/subarrays.md +++ b/src/devdocs/subarrays.md @@ -108,7 +108,7 @@ of the parent array, whereas for `S2` one needs to apply them to the second and approach to indexing would be to do the type-analysis at runtime: ```julia -parentindexes = Array{Any}(0) +parentindexes = Vector{Any}() for thisindex in S.indexes ... if isa(thisindex, Int) diff --git a/src/index.md b/src/index.md index cdbf031..9a17dc9 100644 --- a/src/index.md +++ b/src/index.md @@ -71,6 +71,7 @@ * [Shared Arrays](@ref) * [Base64](@ref) * [File Events](@ref lib-filewatching) + * [Iterative Eigensolvers](@ref lib-itereigen) ## Developer Documentation diff --git a/src/manual/arrays.md b/src/manual/arrays.md index 92fbc72..39d4614 100644 --- a/src/manual/arrays.md +++ b/src/manual/arrays.md @@ -50,26 +50,26 @@ omitted it will default to [`Float64`](@ref). | Function | Description | |:---------------------------------- |:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [`Array{T}(dims...)`](@ref) | an uninitialized dense [`Array`](@ref) | -| [`zeros(T, dims...)`](@ref) | an `Array` of all zeros | -| [`zeros(A)`](@ref) | an array of all zeros with the same type, element type and shape as `A` | -| [`ones(T, dims...)`](@ref) | an `Array` of all ones | -| [`ones(A)`](@ref) | an array of all ones with the same type, element type and shape as `A` | -| [`trues(dims...)`](@ref) | a [`BitArray`](@ref) with all values `true` | -| [`trues(A)`](@ref) | a `BitArray` with all values `true` and the same shape as `A` | -| [`falses(dims...)`](@ref) | a `BitArray` with all values `false` | -| [`falses(A)`](@ref) | a `BitArray` with all values `false` and the same shape as `A` | -| [`reshape(A, dims...)`](@ref) | an array containing the same data as `A`, but with different dimensions | -| [`copy(A)`](@ref) | copy `A` | -| [`deepcopy(A)`](@ref) | copy `A`, recursively copying its elements | -| [`similar(A, T, dims...)`](@ref) | an uninitialized array of the same type as `A` (dense, sparse, etc.), but with the specified element type and dimensions. The second and third arguments are both optional, defaulting to the element type and dimensions of `A` if omitted. | -| [`reinterpret(T, A)`](@ref) | an array with the same binary data as `A`, but with element type `T` | -| [`rand(T, dims...)`](@ref) | an `Array` with random, iid [^1] and uniformly distributed values in the half-open interval ``[0, 1)`` | -| [`randn(T, dims...)`](@ref) | an `Array` with random, iid and standard normally distributed values | -| [`Matrix{T}(I, m, n)`](@ref) | `m`-by-`n` identity matrix | -| [`linspace(start, stop, n)`](@ref) | range of `n` linearly spaced elements from `start` to `stop` | -| [`fill!(A, x)`](@ref) | fill the array `A` with the value `x` | -| [`fill(x, dims...)`](@ref) | an `Array` filled with the value `x` | +| [`Array{T}(uninitialized, dims...)`](@ref) | an uninitialized dense [`Array`](@ref) | +| [`zeros(T, dims...)`](@ref) | an `Array` of all zeros | +| [`zeros(A)`](@ref) | an array of all zeros with the same type, element type and shape as `A` | +| [`ones(T, dims...)`](@ref) | an `Array` of all ones | +| [`ones(A)`](@ref) | an array of all ones with the same type, element type and shape as `A` | +| [`trues(dims...)`](@ref) | a [`BitArray`](@ref) with all values `true` | +| [`trues(A)`](@ref) | a `BitArray` with all values `true` and the same shape as `A` | +| [`falses(dims...)`](@ref) | a `BitArray` with all values `false` | +| [`falses(A)`](@ref) | a `BitArray` with all values `false` and the same shape as `A` | +| [`reshape(A, dims...)`](@ref) | an array containing the same data as `A`, but with different dimensions | +| [`copy(A)`](@ref) | copy `A` | +| [`deepcopy(A)`](@ref) | copy `A`, recursively copying its elements | +| [`similar(A, T, dims...)`](@ref) | an uninitialized array of the same type as `A` (dense, sparse, etc.), but with the specified element type and dimensions. The second and third arguments are both optional, defaulting to the element type and dimensions of `A` if omitted. | +| [`reinterpret(T, A)`](@ref) | an array with the same binary data as `A`, but with element type `T` | +| [`rand(T, dims...)`](@ref) | an `Array` with random, iid [^1] and uniformly distributed values in the half-open interval ``[0, 1)`` | +| [`randn(T, dims...)`](@ref) | an `Array` with random, iid and standard normally distributed values | +| [`Matrix{T}(I, m, n)`](@ref) | `m`-by-`n` identity matrix | +| [`linspace(start, stop, n)`](@ref) | range of `n` linearly spaced elements from `start` to `stop` | +| [`fill!(A, x)`](@ref) | fill the array `A` with the value `x` | +| [`fill(x, dims...)`](@ref) | an `Array` filled with the value `x` | [^1]: *iid*, independently and identically distributed. diff --git a/src/manual/constructors.md b/src/manual/constructors.md index cfc879c..330ed28 100644 --- a/src/manual/constructors.md +++ b/src/manual/constructors.md @@ -524,7 +524,7 @@ one type to another, you should probably define a `convert` method instead. On the other hand, if your constructor does not represent a lossless conversion, or doesn't represent "conversion" at all, it is better to leave it as a constructor rather than a `convert` method. -For example, the `Array{Int}()` constructor creates a zero-dimensional `Array` of the type `Int`, +For example, the `Array{Int,0}(uninitialized)` constructor creates a zero-dimensional `Array` of the type `Int`, but is not really a "conversion" from `Int` to an `Array`. ## Outer-only constructors diff --git a/src/manual/faq.md b/src/manual/faq.md index 745c8f2..eea3827 100644 --- a/src/manual/faq.md +++ b/src/manual/faq.md @@ -566,12 +566,13 @@ julia> gvar_self = "Node1" julia> remotecall_fetch(()->gvar_self, 2) "Node1" -julia> remotecall_fetch(whos, 2) - From worker 2: Base 41762 KB Module - From worker 2: Core 27337 KB Module - From worker 2: Foo 2477 bytes Module - From worker 2: Main 46191 KB Module - From worker 2: gvar_self 13 bytes String +julia> remotecall_fetch(varinfo, 2) +name size summary +––––––––– –––––––– ––––––– +Base Module +Core Module +Main Module +gvar_self 13 bytes String ``` This does not apply to `function` or `type` declarations. However, anonymous functions bound to global diff --git a/src/manual/interfaces.md b/src/manual/interfaces.md index 7e19c25..1cb9454 100644 --- a/src/manual/interfaces.md +++ b/src/manual/interfaces.md @@ -226,7 +226,7 @@ ourselves, we can officially define it as a subtype of an [`AbstractArray`](@ref | `similar(A)` | `similar(A, eltype(A), size(A))` | Return a mutable array with the same shape and element type | | `similar(A, ::Type{S})` | `similar(A, S, size(A))` | Return a mutable array with the same shape and the specified element type | | `similar(A, dims::NTuple{Int})` | `similar(A, eltype(A), dims)` | Return a mutable array with the same element type and size *dims* | -| `similar(A, ::Type{S}, dims::NTuple{Int})` | `Array{S}(dims)` | Return a mutable array with the specified element type and size | +| `similar(A, ::Type{S}, dims::NTuple{Int})` | `Array{S}(uninitialized, dims)` | Return a mutable array with the specified element type and size | | **Non-traditional indices** | **Default definition** | **Brief description** | | `indices(A)` | `map(OneTo, size(A))` | Return the `AbstractUnitRange` of valid indices | | `Base.similar(A, ::Type{S}, inds::NTuple{Ind})` | `similar(A, S, Base.to_shape(inds))` | Return a mutable array with the specified indices `inds` (see below) | @@ -390,3 +390,204 @@ If you are defining an array type that allows non-traditional indexing (indices something other than 1), you should specialize `indices`. You should also specialize [`similar`](@ref) so that the `dims` argument (ordinarily a `Dims` size-tuple) can accept `AbstractUnitRange` objects, perhaps range-types `Ind` of your own design. For more information, see [Arrays with custom indices](@ref). + +## [Broadcasting](@id man-interfaces-broadcasting) + +| Methods to implement | Brief description | +|:-------------------- |:----------------- | +| `Base.BroadcastStyle(::Type{SrcType}) = SrcStyle()` | Broadcasting behavior of `SrcType` | +| `Base.broadcast_similar(f, ::DestStyle, ::Type{ElType}, inds, As...)` | Allocation of output container | +| **Optional methods** | | | +| `Base.BroadcastStyle(::Style1, ::Style2) = Style12()` | Precedence rules for mixing styles | +| `Base.broadcast_indices(::StyleA, A)` | Declaration of the indices of `A` for broadcasting purposes (for AbstractArrays, defaults to `indices(A)`) | +| **Bypassing default machinery** | | +| `broadcast(f, As...)` | Complete bypass of broadcasting machinery | +| `broadcast(f, ::DestStyle, ::Void, ::Void, As...)` | Bypass after container type is computed | +| `broadcast(f, ::DestStyle, ::Type{ElType}, inds::Tuple, As...)` | Bypass after container type, eltype, and indices are computed | + +[Broadcasting](@ref) is triggered by an explicit call to `broadcast` or `broadcast!`, or implicitly by +"dot" operations like `A .+ b`. Any `AbstractArray` type supports broadcasting, +but the default result (output) type is `Array`. To specialize the result for specific input type(s), +the main task is the allocation of an appropriate result object. +(This is not an issue for `broadcast!`, where +the result object is passed as an argument.) This process is split into two stages: computation +of the behavior and type from the arguments ([`Base.BroadcastStyle`](@ref)), and allocation of the object +given the resulting type with [`Base.broadcast_similar`](@ref). + +`Base.BroadcastStyle` is an abstract type from which all styles are +derived. When used as a function it has two possible forms, +unary (single-argument) and binary. +The unary variant states that you intend to +implement specific broadcasting behavior and/or output type, +and do not wish to rely on the default fallback ([`Broadcast.Scalar`](@ref) or [`Broadcast.DefaultArrayStyle`](@ref)). +To achieve this, you can define a custom `BroadcastStyle` for your object: + +```julia +struct MyStyle <: Broadcast.BroadcastStyle end +Base.BroadcastStyle(::Type{<:MyType}) = MyStyle() +``` + +In some cases it might be convenient not to have to define `MyStyle`, in which case you can +leverage one of the general broadcast wrappers: + + - `Base.BroadcastStyle(::Type{<:MyType}) = Broadcast.Style{MyType}()` can be + used for arbitrary types. + - `Base.BroadcastStyle(::Type{<:MyType}) = Broadcast.ArrayStyle{MyType}()` is preferred + if `MyType` is an `AbstractArray`. + - For `AbstractArrays` that only support a certain dimensionality, create a subtype of `Broadcast.AbstractArrayStyle{N}` (see below). + +When your broadcast operation involves several arguments, individual argument styles get +combined to determine a single `DestStyle` that controls the type of the output container. +For more detail, see [below](@ref writing-binary-broadcasting-rules). + +The actual allocation of the result array is handled by `Base.broadcast_similar`: + +```julia +Base.broadcast_similar(f, ::DestStyle, ::Type{ElType}, inds, As...) +``` + +`f` is the operation being performed and `DestStyle` signals the final result from +combining the input styles. +`As...` is the list of input objects. You may not need to use `f` or `As...` +unless they help you build the appropriate object; the fallback definition is + +```julia +broadcast_similar(f, ::DefaultArrayStyle{N}, ::Type{ElType}, inds::Indices{N}, As...) where {N,ElType} = + similar(Array{ElType}, inds) +``` + +However, if needed you can specialize on any or all of these arguments. + +For a complete example, let's say you have created a type, `ArrayAndChar`, that stores an +array and a single character: + +```jldoctest +struct ArrayAndChar{T,N} <: AbstractArray{T,N} + data::Array{T,N} + char::Char +end +Base.size(A::ArrayAndChar) = size(A.data) +Base.getindex(A::ArrayAndChar{T,N}, inds::Vararg{Int,N}) where {T,N} = A.data[inds...] +Base.setindex!(A::ArrayAndChar{T,N}, val, inds::Vararg{Int,N}) where {T,N} = A.data[inds...] = val +Base.showarg(io::IO, A::ArrayAndChar, toplevel) = print(io, typeof(A), " with char '", A.char, "'") +``` + +You might want broadcasting to preserve the `char` "metadata." First we define + +```jldoctest +Base.BroadcastStyle(::Type{<:ArrayAndChar}) = Broadcast.ArrayStyle{ArrayAndChar}() +``` + +This forces us to also define a `broadcast_similar` method: +```jldoctest +function Base.broadcast_similar(f, ::Broadcast.ArrayStyle{ArrayAndChar}, ::Type{ElType}, inds, As...) where ElType + # Scan the inputs for the ArrayAndChar: + A = find_aac(As...) + # Use the char field of A to create the output + ArrayAndChar(similar(Array{ElType}, inds), A.char) +end + +"`A = find_aac(As...)` returns the first ArrayAndChar among the arguments." +find_aac(A::ArrayAndChar, B...) = A +find_aac(A, B...) = find_aac(B...) +``` + +From these definitions, one obtains the following behavior: +```jldoctest +julia> a = ArrayAndChar([1 2; 3 4], 'x') +2×2 ArrayAndChar{Int64,2} with char 'x': + 1 2 + 3 4 + +julia> a .+ 1 +2×2 ArrayAndChar{Int64,2} with char 'x': + 2 3 + 4 5 + +julia> a .+ [5,10] +2×2 ArrayAndChar{Int64,2} with char 'x': + 6 7 + 13 14 +``` + +Finally, it's worth noting that sometimes it's easier simply to bypass the machinery for +computing result types and container sizes, and just do everything manually. For example, +you can convert a `UnitRange{Int}` `r` to a `UnitRange{BigInt}` with `big.(r)`; the definition +of this method is approximately + +```julia +Broadcast.broadcast(::typeof(big), r::UnitRange) = big(first(r)):big(last(r)) +``` + +This exploits Julia's ability to dispatch on a particular function type. (This kind of +explicit definition can indeed be necessary if the output container does not support `setindex!`.) +You can optionally choose to implement the actual broadcasting yourself, but allow +the internal machinery to compute the container type, element type, and indices by specializing + +```julia +Broadcast.broadcast(::typeof(somefunction), ::MyStyle, ::Type{ElType}, inds, As...) +``` + +### [Writing binary broadcasting rules](@id writing-binary-broadcasting-rules) + +The precedence rules are defined by binary `BroadcastStyle` calls: + +```julia +Base.BroadcastStyle(::Style1, ::Style2) = Style12() +``` + +where `Style12` is the `BroadcastStyle` you want to choose for outputs involving +arguments of `Style1` and `Style2`. For example, + +```julia +Base.BroadcastStyle(::Broadcast.Style{Tuple}, ::Broadcast.Scalar) = Broadcast.Style{Tuple}() +``` + +indicates that `Tuple` "wins" over scalars (the output container will be a tuple). +It is worth noting that you do not need to (and should not) define both argument orders +of this call; defining one is sufficient no matter what order the user supplies the arguments in. + +For `AbstractArray` types, defining a `BroadcastStyle` supersedes the fallback choice, +[`Broadcast.DefaultArrayStyle`](@ref). `DefaultArrayStyle` and the abstract supertype, `AbstractArrayStyle`, store the dimensionality as a type parameter to support specialized +array types that have fixed dimensionality requirements. + +`DefaultArrayStyle` "loses" to any other +`AbstractArrayStyle` that has been defined because of the following methods: + +```julia +BroadcastStyle(a::AbstractArrayStyle{Any}, ::DefaultArrayStyle) = a +BroadcastStyle(a::AbstractArrayStyle{N}, ::DefaultArrayStyle{N}) where N = a +BroadcastStyle(a::AbstractArrayStyle{M}, ::DefaultArrayStyle{N}) where {M,N} = + typeof(a)(_max(Val(M),Val(N))) +``` + +You do not need to write binary `BroadcastStyle` +rules unless you want to establish precedence for +two or more non-`DefaultArrayStyle` types. + +If your array type does have fixed dimensionality requirements, then you should +subtype `AbstractArrayStyle`. For example, the sparse array code has the following definitions: + +```julia +struct SparseVecStyle <: Broadcast.AbstractArrayStyle{1} end +struct SparseMatStyle <: Broadcast.AbstractArrayStyle{2} end +Base.BroadcastStyle(::Type{<:SparseVector}) = SparseVecStyle() +Base.BroadcastStyle(::Type{<:SparseMatrixCSC}) = SparseMatStyle() +``` + +Whenever you subtype `AbstractArrayStyle`, you also need to define rules for combining +dimensionalities, by creating a constructor for your style that takes a `Val(N)` argument. +For example: + +```julia +SparseVecStyle(::Val{0}) = SparseVecStyle() +SparseVecStyle(::Val{1}) = SparseVecStyle() +SparseVecStyle(::Val{2}) = SparseMatStyle() +SparseVecStyle(::Val{N}) where N = Broadcast.DefaultArrayStyle{N}() +``` + +These rules indicate that the combination of a `SparseVecStyle` with 0- or 1-dimensional arrays +yields another `SparseVecStyle`, that its combination with a 2-dimensional array +yields a `SparseMatStyle`, and anything of higher dimensionality falls back to the dense arbitrary-dimensional framework. +These rules allow broadcasting to keep the sparse representation for operations that result +in one or two dimensional outputs, but produce an `Array` for any other dimensionality. diff --git a/src/manual/linear-algebra.md b/src/manual/linear-algebra.md index 3a5cefc..8d8d4c2 100644 --- a/src/manual/linear-algebra.md +++ b/src/manual/linear-algebra.md @@ -275,7 +275,6 @@ of the standard library documentation. | `CholeskyPivoted` | [Pivoted](https://en.wikipedia.org/wiki/Pivot_element) Cholesky factorization | | `LU` | [LU factorization](https://en.wikipedia.org/wiki/LU_decomposition) | | `LUTridiagonal` | LU factorization for [`Tridiagonal`](@ref) matrices | -| `UmfpackLU` | LU factorization for sparse matrices (computed by UMFPack) | | `QR` | [QR factorization](https://en.wikipedia.org/wiki/QR_decomposition) | | `QRCompactWY` | Compact WY form of the QR factorization | | `QRPivoted` | Pivoted [QR factorization](https://en.wikipedia.org/wiki/QR_decomposition) | diff --git a/src/manual/methods.md b/src/manual/methods.md index 7a71751..6455722 100644 --- a/src/manual/methods.md +++ b/src/manual/methods.md @@ -601,7 +601,7 @@ function matmul(a::AbstractMatrix, b::AbstractMatrix) # R = promote_type(ai, bi) # 타입 추론의 반환 값에 따라 매우 취약하기 때문에 잘못되었습니다.(최적화가 불가능할뿐만 아니라): - # R = return_types(op, (eltype(a), eltype(b))) + # R = Base.return_types(op, (eltype(a), eltype(b))) ## 그래서 결국 이렇습니다.: R = promote_op(op, eltype(a), eltype(b)) diff --git a/src/manual/modules.md b/src/manual/modules.md index 1baf633..e8bf887 100644 --- a/src/manual/modules.md +++ b/src/manual/modules.md @@ -119,7 +119,7 @@ end There are three important standard modules: Main, Core, and Base. Main is the top-level module, and Julia starts with Main set as the current module. Variables -defined at the prompt go in Main, and `whos()` lists variables in Main. +defined at the prompt go in Main, and `varinfo()` lists variables in Main. Core contains all identifiers considered "built in" to the language, i.e. part of the core language and not libraries. Every module implicitly specifies `using Core`, since you can't do anything diff --git a/src/manual/noteworthy-differences.md b/src/manual/noteworthy-differences.md index efcf3ea..26954d1 100644 --- a/src/manual/noteworthy-differences.md +++ b/src/manual/noteworthy-differences.md @@ -121,7 +121,7 @@ For users coming to Julia from R, these are some noteworthy differences: of the form `if cond; statement; end`, `cond && statement` and `!cond || statement`. Assignment statements in the latter two syntaxes must be explicitly wrapped in parentheses, e.g. `cond && (x = value)`. * In Julia, `<-`, `<<-` and `->` are not assignment operators. - * Julia's `->` creates an anonymous function, like Python. + * Julia's `->` creates an anonymous function. * Julia constructs vectors using brackets. Julia's `[1, 2, 3]` is the equivalent of R's `c(1, 2, 3)`. * Julia's [`*`](@ref) operator can perform matrix multiplication, unlike in R. If `A` and `B` are matrices, then `A * B` denotes a matrix multiplication in Julia, equivalent to R's `A %*% B`. diff --git a/src/manual/parallel-computing.md b/src/manual/parallel-computing.md index 8e58a29..b032767 100644 --- a/src/manual/parallel-computing.md +++ b/src/manual/parallel-computing.md @@ -312,12 +312,13 @@ julia> let B = B remotecall_fetch(()->B, 2) end; -julia> @spawnat 2 whos(); - -julia> From worker 2: A 800 bytes 10×10 Array{Float64,2} - From worker 2: Base Module - From worker 2: Core Module - From worker 2: Main Module +julia> @fetchfrom 2 varinfo() +name size summary +––––––––– ––––––––– –––––––––––––––––––––– +A 800 bytes 10×10 Array{Float64,2} +Base Module +Core Module +Main Module ``` As can be seen, global variable `A` is defined on worker 2, but `B` is captured as a local variable diff --git a/src/manual/performance-tips.md b/src/manual/performance-tips.md index 1217129..1b30724 100644 --- a/src/manual/performance-tips.md +++ b/src/manual/performance-tips.md @@ -646,7 +646,7 @@ julia> function fill_twos!(a) fill_twos! (generic function with 1 method) julia> function strange_twos(n) - a = Array{rand(Bool) ? Int64 : Float64}(n) + a = Vector{rand(Bool) ? Int64 : Float64}(uninitialized, n) fill_twos!(a) return a end @@ -933,7 +933,7 @@ function xinc!(ret::AbstractVector{T}, x::T) where T end function loopinc_prealloc() - ret = Array{Int}(3) + ret = Vector{Int}(uninitialized, 3) y = 0 for i = 1:10^7 xinc!(ret, i) @@ -1284,7 +1284,7 @@ end function main() n = 2000 - u = Array{Float64}(n) + u = Vector{Float64}(uninitialized, n) init!(u) du = similar(u) diff --git a/src/manual/style-guide.md b/src/manual/style-guide.md index 07defae..e586df2 100644 --- a/src/manual/style-guide.md +++ b/src/manual/style-guide.md @@ -147,10 +147,10 @@ some alternatives to consider: It is usually not much help to construct arrays like the following: ```julia -a = Array{Union{Int,AbstractString,Tuple,Array}}(n) +a = Vector{Union{Int,AbstractString,Tuple,Array}}(uninitialized, n) ``` -In this case `Array{Any}(n)` is better. It is also more helpful to the compiler to annotate specific +In this case `Vector{Any}(uninitialized, n)` is better. It is also more helpful to the compiler to annotate specific uses (e.g. `a[i]::Int`) than to try to pack many alternatives into one type. ## Use naming conventions consistent with Julia's `base/` diff --git a/src/manual/variables-and-scoping.md b/src/manual/variables-and-scoping.md index e21229c..ab9f0a9 100644 --- a/src/manual/variables-and-scoping.md +++ b/src/manual/variables-and-scoping.md @@ -359,7 +359,7 @@ something like `let x = x` since the two `x` variables are distinct and have sep Here is an example where the behavior of `let` is needed: ```jldoctest -julia> Fs = Array{Any}(2); i = 1; +julia> Fs = Vector{Any}(uninitialized, 2); i = 1; julia> while i <= 2 Fs[i] = ()->i @@ -378,7 +378,7 @@ variable `i`, so the two closures behave identically. We can use `let` to create for `i`: ```jldoctest -julia> Fs = Array{Any}(2); i = 1; +julia> Fs = Vector{Any}(uninitialized, 2); i = 1; julia> while i <= 2 let i = i @@ -418,7 +418,7 @@ introduced in their body scopes are freshly allocated for each loop iteration, a were surrounded by a `let` block: ```jldoctest -julia> Fs = Array{Any}(2); +julia> Fs = Vector{Any}(uninitialized, 2); julia> for j = 1:2 Fs[j] = ()->j diff --git a/src/stdlib/.gitignore b/src/stdlib/.gitignore new file mode 100644 index 0000000..e04ac81 --- /dev/null +++ b/src/stdlib/.gitignore @@ -0,0 +1,10 @@ +delimitedfiles.md +test.md +mmap.md +sharedarrays.md +profile.md +base64.md +filewatching.md +crc32c.md +dates.md + diff --git a/src/stdlib/arrays.md b/src/stdlib/arrays.md index 383b886..6d97c07 100644 --- a/src/stdlib/arrays.md +++ b/src/stdlib/arrays.md @@ -8,12 +8,14 @@ Base.AbstractVector Base.AbstractMatrix Core.Array Core.Array(::Any) +Core.Array(::Any, ::Any) Core.Uninitialized Core.uninitialized Base.Vector Base.Vector(::Any) +Base.Vector(::Any, ::Any) Base.Matrix -Base.Matrix(::Any, ::Any) +Base.Matrix(::Any, ::Any, ::Any) Base.getindex(::Type, ::Any...) Base.zeros Base.ones @@ -66,6 +68,17 @@ Base.Broadcast.broadcast_getindex Base.Broadcast.broadcast_setindex! ``` +For specializing broadcast on custom types, see +```@docs +Base.BroadcastStyle +Base.broadcast_similar +Base.broadcast_indices +Base.Broadcast.Scalar +Base.Broadcast.AbstractArrayStyle +Base.Broadcast.ArrayStyle +Base.Broadcast.DefaultArrayStyle +``` + ## Indexing and assignment ```@docs diff --git a/src/stdlib/base.md b/src/stdlib/base.md index c65875e..d29a4e5 100644 --- a/src/stdlib/base.md +++ b/src/stdlib/base.md @@ -23,7 +23,7 @@ Base.quit Base.atexit Base.atreplinit Base.isinteractive -Base.whos +Base.varinfo Base.summarysize Base.edit(::AbstractString, ::Integer) Base.edit(::Any) @@ -89,7 +89,6 @@ primitive type ## Base Modules ```@docs Base.BLAS -Base.Dates Base.Distributed Base.Docs Base.Iterators diff --git a/src/stdlib/index.md b/src/stdlib/index.md index be772c5..5b7ef9b 100644 --- a/src/stdlib/index.md +++ b/src/stdlib/index.md @@ -29,3 +29,4 @@ * [Shared Arrays](@ref) * [Base64](@ref) * [File Events](@ref lib-filewatching) + * [Iterative Eigensolvers](@ref lib-itereigen) diff --git a/src/stdlib/iterativeeigensolvers.md b/src/stdlib/iterativeeigensolvers.md new file mode 100644 index 0000000..ea5c50c --- /dev/null +++ b/src/stdlib/iterativeeigensolvers.md @@ -0,0 +1,7 @@ +# [Iterative Eigensolvers](@id lib-itereigen) + +```@docs +IterativeEigenSolvers.eigs(::Any) +IterativeEigenSolvers.eigs(::Any, ::Any) +IterativeEigenSolvers.svds +``` diff --git a/src/stdlib/linalg.md b/src/stdlib/linalg.md index cb2aa82..b8c9fb1 100644 --- a/src/stdlib/linalg.md +++ b/src/stdlib/linalg.md @@ -136,9 +136,6 @@ Base.transpose Base.transpose! Base.adjoint Base.adjoint! -Base.LinAlg.eigs(::Any) -Base.LinAlg.eigs(::Any, ::Any) -Base.LinAlg.svds Base.LinAlg.peakflops Base.LinAlg.stride1 ``` diff --git a/src/stdlib/strings.md b/src/stdlib/strings.md index dca748e..36ed901 100644 --- a/src/stdlib/strings.md +++ b/src/stdlib/strings.md @@ -60,6 +60,7 @@ Base.chop Base.chomp Base.ind2chr Base.chr2ind +Base.thisind Base.nextind Base.prevind Base.Random.randstring From 24eebc4203a617f49518f06be42f25915b06daac Mon Sep 17 00:00:00 2001 From: WooKyoung Noh Date: Mon, 27 Nov 2017 18:27:04 +0900 Subject: [PATCH 2/4] =?UTF-8?q?stdlib/iterativeeigensolvers.md=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- make.jl | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/make.jl b/make.jl index a4faa67..864692a 100644 --- a/make.jl +++ b/make.jl @@ -17,33 +17,6 @@ baremodule GenStdLib end include(joinpath(@__DIR__, "contrib", "build_sysimg.jl")) end -#= -# Documenter Setup. - -symlink_q(tgt, link) = isfile(link) || symlink(tgt, link) -cp_q(src, dest) = isfile(dest) || cp(src, dest) - -# make links for stdlib package docs -if Sys.iswindows() - cp_q("../stdlib/DelimitedFiles/docs/src/index.md", "src/stdlib/delimitedfiles.md") - cp_q("../stdlib/Test/docs/src/index.md", "src/stdlib/test.md") - cp_q("../stdlib/Mmap/docs/src/index.md", "src/stdlib/mmap.md") - cp_q("../stdlib/SharedArrays/docs/src/index.md", "src/stdlib/sharedarrays.md") - cp_q("../stdlib/Profile/docs/src/index.md", "src/stdlib/profile.md") - cp_q("../stdlib/Base64/docs/src/index.md", "src/stdlib/base64.md") - cp_q("../stdlib/FileWatching/docs/src/index.md", "src/stdlib/filewatching.md") - cp_q("../stdlib/CRC32c/docs/src/index.md", "src/stdlib/crc32c.md") -else - symlink_q("../../../stdlib/DelimitedFiles/docs/src/index.md", "src/stdlib/delimitedfiles.md") - symlink_q("../../../stdlib/Test/docs/src/index.md", "src/stdlib/test.md") - symlink_q("../../../stdlib/Mmap/docs/src/index.md", "src/stdlib/mmap.md") - symlink_q("../../../stdlib/SharedArrays/docs/src/index.md", "src/stdlib/sharedarrays.md") - symlink_q("../../../stdlib/Profile/docs/src/index.md", "src/stdlib/profile.md") - symlink_q("../../../stdlib/Base64/docs/src/index.md", "src/stdlib/base64.md") - symlink_q("../../../stdlib/FileWatching/docs/src/index.md", "src/stdlib/filewatching.md") - symlink_q("../../../stdlib/CRC32c/docs/src/index.md", "src/stdlib/crc32c.md") -end -=# const PAGES = [ "Home" => "index.md", @@ -117,6 +90,7 @@ const PAGES = [ "stdlib/sharedarrays.md", "stdlib/filewatching.md", "stdlib/crc32c.md", + "stdlib/iterativeeigensolvers.md", ], "Developer Documentation" => [ "devdocs/reflection.md", From b39d79506bc519858ea15275326dc11d644aea10 Mon Sep 17 00:00:00 2001 From: WooKyoung Noh Date: Wed, 29 Nov 2017 12:50:28 +0900 Subject: [PATCH 3/4] update Julia Commit 2316bb58cf --- codex/manual/dates.md | 4 ++-- codex/manual/interacting-with-julia.md | 10 ++++++++-- src/manual/dates.md | 4 ++-- src/manual/interacting-with-julia.md | 10 ++++++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/codex/manual/dates.md b/codex/manual/dates.md index 7764fdb..5496eb7 100644 --- a/codex/manual/dates.md +++ b/codex/manual/dates.md @@ -125,7 +125,7 @@ julia> for i = 1:10^5 end ``` -A full suite of parsing and formatting tests and examples is available in [`tests/dates/io.jl`](https://github.com/JuliaLang/julia/blob/master/test/dates/io.jl). +A full suite of parsing and formatting tests and examples is available in [`stdlib/Dates/test/io.jl`](https://github.com/JuliaLang/julia/blob/master/stdlib/Dates/test/io.jl). ## Durations/Comparisons @@ -503,7 +503,7 @@ julia> filter(dr) do x 2014-11-11 ``` -Additional examples and tests are available in [`test/dates/adjusters.jl`](https://github.com/JuliaLang/julia/blob/master/test/dates/adjusters.jl). +Additional examples and tests are available in [`stdlib/Dates/test/adjusters.jl`](https://github.com/JuliaLang/julia/blob/master/stdlib/Dates/test/adjusters.jl). ## Period Types diff --git a/codex/manual/interacting-with-julia.md b/codex/manual/interacting-with-julia.md index bda8643..b9cd313 100644 --- a/codex/manual/interacting-with-julia.md +++ b/codex/manual/interacting-with-julia.md @@ -161,11 +161,14 @@ to do so). | End, `^E` | Move to end of line | | Up arrow, `^P` | Move up one line (or change to the previous history entry that matches the text before the cursor) | | Down arrow, `^N` | Move down one line (or change to the next history entry that matches the text before the cursor) | +| Shift-Arrow Key | Move cursor according to the direction of the Arrow key, while activating the region ("shift selection") | | Page-up, `meta-P` | Change to the previous history entry | | Page-down, `meta-N` | Change to the next history entry | | `meta-<` | Change to the first history entry (of the current session if it is before the current position in history) | | `meta->` | Change to the last history entry | -| `^-Space` | Set the "mark" in the editing region | +| `^-Space` | Set the "mark" in the editing region (and de-activate the region if it's active) | +| `^-Space ^-Space` | Set the "mark" in the editing region and make the region "active", i.e. highlighted | +| `^G` | De-activate the region (i.e. make it not highlighted) | | `^X^X` | Exchange the current position with the mark | | **Editing** |   | | Backspace, `^H` | Delete the previous character | @@ -179,12 +182,15 @@ to do so). | `^Y` | "Yank" insert the text from the kill ring | | `meta-y` | Replace a previously yanked text with an older entry from the kill ring | | `^T` | Transpose the characters about the cursor | +| `meta-Up arrow` | Transpose current line with line above | +| `meta-Down arrow` | Transpose current line with line below | | `meta-u` | Change the next word to uppercase | | `meta-c` | Change the next word to titlecase | | `meta-l` | Change the next word to lowercase | | `^/`, `^_` | Undo previous editing action | | `^Q` | Write a number in REPL and press `^Q` to open editor at corresponding stackframe or method | - +| `meta-Left Arrow` | indent the current line on the left | +| `meta-Right Arrow` | indent the current line on the right | ### Customizing keybindings diff --git a/src/manual/dates.md b/src/manual/dates.md index 7764fdb..5496eb7 100644 --- a/src/manual/dates.md +++ b/src/manual/dates.md @@ -125,7 +125,7 @@ julia> for i = 1:10^5 end ``` -A full suite of parsing and formatting tests and examples is available in [`tests/dates/io.jl`](https://github.com/JuliaLang/julia/blob/master/test/dates/io.jl). +A full suite of parsing and formatting tests and examples is available in [`stdlib/Dates/test/io.jl`](https://github.com/JuliaLang/julia/blob/master/stdlib/Dates/test/io.jl). ## Durations/Comparisons @@ -503,7 +503,7 @@ julia> filter(dr) do x 2014-11-11 ``` -Additional examples and tests are available in [`test/dates/adjusters.jl`](https://github.com/JuliaLang/julia/blob/master/test/dates/adjusters.jl). +Additional examples and tests are available in [`stdlib/Dates/test/adjusters.jl`](https://github.com/JuliaLang/julia/blob/master/stdlib/Dates/test/adjusters.jl). ## Period Types diff --git a/src/manual/interacting-with-julia.md b/src/manual/interacting-with-julia.md index bda8643..b9cd313 100644 --- a/src/manual/interacting-with-julia.md +++ b/src/manual/interacting-with-julia.md @@ -161,11 +161,14 @@ to do so). | End, `^E` | Move to end of line | | Up arrow, `^P` | Move up one line (or change to the previous history entry that matches the text before the cursor) | | Down arrow, `^N` | Move down one line (or change to the next history entry that matches the text before the cursor) | +| Shift-Arrow Key | Move cursor according to the direction of the Arrow key, while activating the region ("shift selection") | | Page-up, `meta-P` | Change to the previous history entry | | Page-down, `meta-N` | Change to the next history entry | | `meta-<` | Change to the first history entry (of the current session if it is before the current position in history) | | `meta->` | Change to the last history entry | -| `^-Space` | Set the "mark" in the editing region | +| `^-Space` | Set the "mark" in the editing region (and de-activate the region if it's active) | +| `^-Space ^-Space` | Set the "mark" in the editing region and make the region "active", i.e. highlighted | +| `^G` | De-activate the region (i.e. make it not highlighted) | | `^X^X` | Exchange the current position with the mark | | **Editing** |   | | Backspace, `^H` | Delete the previous character | @@ -179,12 +182,15 @@ to do so). | `^Y` | "Yank" insert the text from the kill ring | | `meta-y` | Replace a previously yanked text with an older entry from the kill ring | | `^T` | Transpose the characters about the cursor | +| `meta-Up arrow` | Transpose current line with line above | +| `meta-Down arrow` | Transpose current line with line below | | `meta-u` | Change the next word to uppercase | | `meta-c` | Change the next word to titlecase | | `meta-l` | Change the next word to lowercase | | `^/`, `^_` | Undo previous editing action | | `^Q` | Write a number in REPL and press `^Q` to open editor at corresponding stackframe or method | - +| `meta-Left Arrow` | indent the current line on the left | +| `meta-Right Arrow` | indent the current line on the right | ### Customizing keybindings From 3fc96db64ef7769401fdbb8879c9c9000be27736 Mon Sep 17 00:00:00 2001 From: WooKyoung Noh Date: Thu, 30 Nov 2017 15:24:21 +0900 Subject: [PATCH 4/4] update Julia Commit 171005cf35 --- codex/stdlib/arrays.md | 2 +- codex/stdlib/io-network.md | 4 ++-- codex/stdlib/linalg.md | 1 + src/stdlib/arrays.md | 2 +- src/stdlib/io-network.md | 4 ++-- src/stdlib/linalg.md | 1 + 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/codex/stdlib/arrays.md b/codex/stdlib/arrays.md index 6d97c07..9ec8c58 100644 --- a/codex/stdlib/arrays.md +++ b/codex/stdlib/arrays.md @@ -20,7 +20,7 @@ Base.getindex(::Type, ::Any...) Base.zeros Base.ones Base.BitArray -Base.BitArray(::Integer...) +Base.BitArray(::Uninitialized, ::Integer...) Base.BitArray(::Any) Base.trues Base.falses diff --git a/codex/stdlib/io-network.md b/codex/stdlib/io-network.md index 060baec..50e90e2 100644 --- a/codex/stdlib/io-network.md +++ b/codex/stdlib/io-network.md @@ -89,7 +89,7 @@ output (such as images, formatted text, or even audio and video), consisting of `x` (with a plain-text fallback). * Overloading [`show`](@ref) allows one to indicate arbitrary multimedia representations (keyed by standard MIME types) of user-defined types. - * Multimedia-capable display backends may be registered by subclassing a generic `Display` type + * Multimedia-capable display backends may be registered by subclassing a generic `AbstractDisplay` type and pushing them onto a stack of display backends via [`pushdisplay`](@ref). The base Julia runtime provides only plain-text display, but richer displays may be enabled by @@ -111,7 +111,7 @@ PNG images in a window can register this capability with Julia, so that calling types with PNG representations will automatically display the image using the module's window. In order to define a new display backend, one should first create a subtype `D` of the abstract -class `Display`. Then, for each MIME type (`mime` string) that can be displayed on `D`, one should +class `AbstractDisplay`. Then, for each MIME type (`mime` string) that can be displayed on `D`, one should define a function `display(d::D, ::MIME"mime", x) = ...` that displays `x` as that MIME type, usually by calling [`reprmime(mime, x)`](@ref). A `MethodError` should be thrown if `x` cannot be displayed as that MIME type; this is automatic if one calls [`reprmime`](@ref). Finally, one should define a function diff --git a/codex/stdlib/linalg.md b/codex/stdlib/linalg.md index b8c9fb1..977b5f6 100644 --- a/codex/stdlib/linalg.md +++ b/codex/stdlib/linalg.md @@ -64,6 +64,7 @@ Base.LinAlg.svdfact Base.LinAlg.svdfact! Base.LinAlg.svd Base.LinAlg.svdvals +Base.LinAlg.svdvals! Base.LinAlg.Givens Base.LinAlg.givens Base.LinAlg.triu diff --git a/src/stdlib/arrays.md b/src/stdlib/arrays.md index 6d97c07..9ec8c58 100644 --- a/src/stdlib/arrays.md +++ b/src/stdlib/arrays.md @@ -20,7 +20,7 @@ Base.getindex(::Type, ::Any...) Base.zeros Base.ones Base.BitArray -Base.BitArray(::Integer...) +Base.BitArray(::Uninitialized, ::Integer...) Base.BitArray(::Any) Base.trues Base.falses diff --git a/src/stdlib/io-network.md b/src/stdlib/io-network.md index 060baec..50e90e2 100644 --- a/src/stdlib/io-network.md +++ b/src/stdlib/io-network.md @@ -89,7 +89,7 @@ output (such as images, formatted text, or even audio and video), consisting of `x` (with a plain-text fallback). * Overloading [`show`](@ref) allows one to indicate arbitrary multimedia representations (keyed by standard MIME types) of user-defined types. - * Multimedia-capable display backends may be registered by subclassing a generic `Display` type + * Multimedia-capable display backends may be registered by subclassing a generic `AbstractDisplay` type and pushing them onto a stack of display backends via [`pushdisplay`](@ref). The base Julia runtime provides only plain-text display, but richer displays may be enabled by @@ -111,7 +111,7 @@ PNG images in a window can register this capability with Julia, so that calling types with PNG representations will automatically display the image using the module's window. In order to define a new display backend, one should first create a subtype `D` of the abstract -class `Display`. Then, for each MIME type (`mime` string) that can be displayed on `D`, one should +class `AbstractDisplay`. Then, for each MIME type (`mime` string) that can be displayed on `D`, one should define a function `display(d::D, ::MIME"mime", x) = ...` that displays `x` as that MIME type, usually by calling [`reprmime(mime, x)`](@ref). A `MethodError` should be thrown if `x` cannot be displayed as that MIME type; this is automatic if one calls [`reprmime`](@ref). Finally, one should define a function diff --git a/src/stdlib/linalg.md b/src/stdlib/linalg.md index b8c9fb1..977b5f6 100644 --- a/src/stdlib/linalg.md +++ b/src/stdlib/linalg.md @@ -64,6 +64,7 @@ Base.LinAlg.svdfact Base.LinAlg.svdfact! Base.LinAlg.svd Base.LinAlg.svdvals +Base.LinAlg.svdvals! Base.LinAlg.Givens Base.LinAlg.givens Base.LinAlg.triu