diff --git a/base/docs/basedocs.jl b/base/docs/basedocs.jl index c603487baf5d0..7b2c3885a60b6 100644 --- a/base/docs/basedocs.jl +++ b/base/docs/basedocs.jl @@ -988,7 +988,7 @@ callable with no arguments). The task exits when this function returns. # Examples ```jldoctest -julia> a() = det(rand(1000, 1000)); +julia> a() = sum(i for i in 1:1000); julia> b = Task(a); ``` diff --git a/base/event.jl b/base/event.jl index 8263fdb5e8e49..e9e697860d683 100644 --- a/base/event.jl +++ b/base/event.jl @@ -118,7 +118,7 @@ If a second argument `val` is provided, it will be passed to the task (via the r the woken task. ```jldoctest -julia> a5() = det(rand(1000, 1000)); +julia> a5() = sum(i for i in 1:1000); julia> b = Task(a5); diff --git a/base/number.jl b/base/number.jl index 4e6b010a1d176..d09c3bef74ef3 100644 --- a/base/number.jl +++ b/base/number.jl @@ -171,28 +171,6 @@ copysign(x::Real, y::Real) = ifelse(signbit(x)!=signbit(y), -x, +x) conj(x::Real) = x transpose(x::Number) = x -""" - adjoint(A) - -Lazy adjoint (conjugate transposition) (also postfix `'`). Note that `adjoint` is applied recursively to -elements. - -This operation is intended for linear algebra usage - for general data manipulation see -[`permutedims`](@ref). - -# Examples -```jldoctest -julia> A = [3+2im 9+2im; 8+7im 4+6im] -2×2 Array{Complex{Int64},2}: - 3+2im 9+2im - 8+7im 4+6im - -julia> adjoint(A) -2×2 Adjoint{Complex{Int64},Array{Complex{Int64},2}}: - 3-2im 8-7im - 9-2im 4-6im -``` -""" adjoint(x::Number) = conj(x) angle(z::Real) = atan2(zero(z), z) diff --git a/base/permuteddimsarray.jl b/base/permuteddimsarray.jl index 3c06450edbcc5..4a82f4670bf9d 100644 --- a/base/permuteddimsarray.jl +++ b/base/permuteddimsarray.jl @@ -117,7 +117,8 @@ end permutedims(m::AbstractMatrix) Permute the dimensions of the matrix `m`, by flipping the elements across the diagonal of -the matrix. Differs from [`transpose`](@ref) in that the operation is not recursive. +the matrix. Differs from `LinearAlgebra`'s [`transpose`](@ref) in that the +operation is not recursive. # Examples ```jldoctest @@ -140,7 +141,7 @@ julia> permutedims(X) [5 6; 7 8] [13 14; 15 16] julia> transpose(X) -2×2 Array{Array{Int64,2},2}: +2×2 LinearAlgebra.Transpose{LinearAlgebra.Transpose{Int64,Array{Int64,2}},Array{Array{Int64,2},2}}: [1 3; 2 4] [9 11; 10 12] [5 7; 6 8] [13 15; 14 16] ``` @@ -151,19 +152,16 @@ permutedims(A::AbstractMatrix) = permutedims(A, (2,1)) permutedims(v::AbstractVector) Reshape vector `v` into a `1 × length(v)` row matrix. - Differs from [`transpose`](@ref) in that the operation is not recursive. +Differs from `LinearAlgebra`'s [`transpose`](@ref) in that +the operation is not recursive. # Examples ```jldoctest -julia> permutedims(v) +julia> permutedims([1, 2, 3, 4]) 1×4 Array{Int64,2}: 1 2 3 4 -julia> a = [1 2; 3 4]; - -julia> b = [5 6; 7 8]; - -julia> V = [[a]; [b]] +julia> V = [[[1 2; 3 4]]; [[5 6; 7 8]]] 2-element Array{Array{Int64,2},1}: [1 2; 3 4] [5 6; 7 8] @@ -173,7 +171,7 @@ julia> permutedims(V) [1 2; 3 4] [5 6; 7 8] julia> transpose(V) -1×2 Transpose{Transpose{Int64,Array{Int64,2}},Array{Array{Int64,2},1}}: +1×2 LinearAlgebra.Transpose{LinearAlgebra.Transpose{Int64,Array{Int64,2}},Array{Array{Int64,2},1}}: [1 3; 2 4] [5 7; 6 8] ``` """ diff --git a/base/reflection.jl b/base/reflection.jl index 9548de63fa846..16609f6bd771a 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -9,8 +9,8 @@ Get the name of a `Module` as a `Symbol`. # Examples ```jldoctest -julia> nameof(Base) -:Base +julia> nameof(Base.Broadcast) +:Broadcast ``` """ nameof(m::Module) = ccall(:jl_module_name, Ref{Symbol}, (Any,), m) @@ -25,7 +25,7 @@ Get a module's enclosing `Module`. `Main` is its own parent. julia> parentmodule(Main) Main -julia> parentmodule(Base.Sys) +julia> parentmodule(Base.Broadcast) Base ``` """ @@ -133,10 +133,10 @@ Get an array of the fields of a `DataType`. # Examples ```jldoctest -julia> fieldnames(Hermitian) +julia> fieldnames(Rational) 2-element Array{Symbol,1}: - :data - :uplo + :num + :den ``` """ fieldnames(t::DataType) = Symbol[fieldname(t, n) for n in 1:fieldcount(t)] diff --git a/base/subarray.jl b/base/subarray.jl index d1a2b9bd94b1b..8fae313f45d3d 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -67,17 +67,17 @@ it is not a view. # Examples ```jldoctest -julia> a = [1 2; 3 4] +julia> A = [1 2; 3 4] 2×2 Array{Int64,2}: 1 2 3 4 -julia> s_a = Symmetric(a) -2×2 Symmetric{Int64,Array{Int64,2}}: +julia> V = view(A, 1:2, :) +2×2 view(::Array{Int64,2}, 1:2, :) with eltype Int64: 1 2 - 2 4 + 3 4 -julia> parent(s_a) +julia> parent(V) 2×2 Array{Int64,2}: 1 2 3 4 diff --git a/base/task.jl b/base/task.jl index 41da005e17526..0cb58fcd3910b 100644 --- a/base/task.jl +++ b/base/task.jl @@ -61,7 +61,7 @@ Wrap an expression in a [`Task`](@ref) without executing it, and return the [`Ta creates a task, and does not run it. ```jldoctest -julia> a1() = det(rand(1000, 1000)); +julia> a1() = sum(i for i in 1:1000); julia> b = @task a1(); @@ -93,7 +93,7 @@ current_task() = ccall(:jl_get_current_task, Ref{Task}, ()) Determine whether a task has exited. ```jldoctest -julia> a2() = det(rand(1000, 1000)); +julia> a2() = sum(i for i in 1:1000); julia> b = Task(a2); @@ -116,7 +116,7 @@ istaskdone(t::Task) = ((t.state == :done) | istaskfailed(t)) Determine whether a task has started executing. ```jldoctest -julia> a3() = det(rand(1000, 1000)); +julia> a3() = sum(i for i in 1:1000); julia> b = Task(a3); diff --git a/doc/src/manual/documentation.md b/doc/src/manual/documentation.md index 7bb282bedc3e7..8cf5dd5b26588 100644 --- a/doc/src/manual/documentation.md +++ b/doc/src/manual/documentation.md @@ -616,13 +616,13 @@ the Julia documentation itself. For example: ```julia """ - eigvals!(A,[irange,][vl,][vu]) -> values + accumulate!(op, y, x) -Same as [`eigvals`](@ref), but saves space by overwriting the input `A`, instead of creating a copy. +Cumulative operation `op` on a vector `x`, storing the result in `y`. See also [`accumulate`](@ref). """ ``` -This will create a link in the generated docs to the `eigvals` documentation +This will create a link in the generated docs to the `accumulate` documentation (which has more information about what this function actually does). It's good to include cross references to mutating/non-mutating versions of a function, or to highlight a difference between two similar-seeming functions. diff --git a/doc/src/manual/functions.md b/doc/src/manual/functions.md index c4ce2e98b7ae2..8e92b14cf0607 100644 --- a/doc/src/manual/functions.md +++ b/doc/src/manual/functions.md @@ -164,7 +164,6 @@ A few special expressions correspond to calls to functions with non-obvious name | `[A; B; C; ...]` | [`vcat`](@ref) | | `[A B; C D; ...]` | [`hvcat`](@ref) | | `A'` | [`adjoint`](@ref) | -| `A.'` | [`transpose`](@ref) | | `1:n` | [`colon`](@ref) | | `A[i]` | [`getindex`](@ref) | | `A[i] = x` | [`setindex!`](@ref) | diff --git a/doc/src/manual/interfaces.md b/doc/src/manual/interfaces.md index 89e8c66f306d7..c08b26716658c 100644 --- a/doc/src/manual/interfaces.md +++ b/doc/src/manual/interfaces.md @@ -115,9 +115,12 @@ Now, when we ask Julia to [`collect`](@ref) all the elements into an array it ca of the right size instead of blindly [`push!`](@ref)ing each element into a `Vector{Any}`: ```jldoctest squaretype -julia> collect(Squares(10))' # transposed to save space -1×10 RowVector{Int64,Array{Int64,1}}: - 1 4 9 16 25 36 49 64 81 100 +julia> collect(Squares(4)) +4-element Array{Int64,1}: + 1 + 4 + 9 + 16 ``` While we can rely upon generic implementations, we can also extend specific methods where we know @@ -150,9 +153,12 @@ julia> Base.next(::Iterators.Reverse{Squares}, state) = (state*state, state-1) julia> Base.done(::Iterators.Reverse{Squares}, state) = state < 1 -julia> collect(Iterators.reverse(Squares(10)))' # transposed to save space -1×10 RowVector{Int64,Array{Int64,1}}: - 100 81 64 49 36 25 16 9 4 1 +julia> collect(Iterators.reverse(Squares(4))) +4-element Array{Int64,1}: + 16 + 9 + 4 + 1 ``` ## Indexing @@ -275,28 +281,31 @@ methods are all it takes for `SquaresVector` to be an iterable, indexable, and c array: ```jldoctest squarevectype -julia> s = SquaresVector(7) -7-element SquaresVector: +julia> s = SquaresVector(4) +4-element SquaresVector: 1 4 9 16 - 25 - 36 - 49 -julia> s[s .> 20] -3-element Array{Int64,1}: - 25 - 36 - 49 +julia> s[s .> 8] +2-element Array{Int64,1}: + 9 + 16 -julia> s \ [1 2; 3 4; 5 6; 7 8; 9 10; 11 12; 13 14] -1×2 RowVector{Float64,Array{Float64,1}}: - 0.305389 0.335329 +julia> s + s +4-element Array{Int64,1}: + 2 + 8 + 18 + 32 -julia> s ⋅ s # dot(s, s) -4676 +julia> sin.(s) +4-element Array{Float64,1}: + 0.8414709848078965 + -0.7568024953079282 + 0.4121184852417566 + -0.2879033166650653 ``` As a more complicated example, let's define our own toy N-dimensional sparse-like array type built @@ -382,8 +391,8 @@ julia> A[SquaresVector(3)] 4.0 9.0 -julia> dot(A[:,1],A[:,2]) -32.0 +julia> mean(A) +5.0 ``` If you are defining an array type that allows non-traditional indexing (indices that start at diff --git a/doc/src/manual/parallel-computing.md b/doc/src/manual/parallel-computing.md index af9b586f762fb..514e36d084b13 100644 --- a/doc/src/manual/parallel-computing.md +++ b/doc/src/manual/parallel-computing.md @@ -284,15 +284,12 @@ snippet: ```julia-repl A = rand(10,10) -remotecall_fetch(()->norm(A), 2) +remotecall_fetch(()->sum(A), 2) ``` -In this case [`norm`](@ref) is a function that takes 2D array as a parameter, and MUST be defined in -the remote process. You could use any function other than `norm` as long as it is defined in the remote -process and accepts the appropriate parameter. - +In this case [`sum`](@ref) MUST be defined in the remote process. Note that `A` is a global variable defined in the local workspace. Worker 2 does not have a variable called -`A` under `Main`. The act of shipping the closure `()->norm(A)` to worker 2 results in `Main.A` being defined +`A` under `Main`. The act of shipping the closure `()->sum(A)` to worker 2 results in `Main.A` being defined on 2. `Main.A` continues to exist on worker 2 even after the call `remotecall_fetch` returns. Remote calls with embedded global references (under `Main` module only) manage globals as follows: @@ -306,9 +303,9 @@ with embedded global references (under `Main` module only) manage globals as fol ```julia A = rand(10,10) - remotecall_fetch(()->norm(A), 2) # worker 2 + remotecall_fetch(()->sum(A), 2) # worker 2 A = rand(10,10) - remotecall_fetch(()->norm(A), 3) # worker 3 + remotecall_fetch(()->sum(A), 3) # worker 3 A = nothing ``` diff --git a/stdlib/LinearAlgebra/docs/src/index.md b/stdlib/LinearAlgebra/docs/src/index.md index 4ab2278fd1a06..e48cf840c051b 100644 --- a/stdlib/LinearAlgebra/docs/src/index.md +++ b/stdlib/LinearAlgebra/docs/src/index.md @@ -409,8 +409,6 @@ LinearAlgebra.istril LinearAlgebra.istriu LinearAlgebra.isdiag LinearAlgebra.ishermitian -LinearAlgebra.RowVector -LinearAlgebra.ConjArray Base.transpose LinearAlgebra.transpose! Base.adjoint diff --git a/stdlib/LinearAlgebra/src/adjtrans.jl b/stdlib/LinearAlgebra/src/adjtrans.jl index a31f094d38134..45063f983268a 100644 --- a/stdlib/LinearAlgebra/src/adjtrans.jl +++ b/stdlib/LinearAlgebra/src/adjtrans.jl @@ -48,11 +48,34 @@ Adjoint(A) = Adjoint{Base.promote_op(adjoint,eltype(A)),typeof(A)}(A) Transpose(A) = Transpose{Base.promote_op(transpose,eltype(A)),typeof(A)}(A) # wrapping lowercase quasi-constructors +""" + adjoint(A) + +Lazy adjoint (conjugate transposition) (also postfix `'`). +Note that `adjoint` is applied recursively to elements. + +This operation is intended for linear algebra usage - for general data manipulation see +[`permutedims`](@ref). + +# Examples +```jldoctest +julia> A = [3+2im 9+2im; 8+7im 4+6im] +2×2 Array{Complex{Int64},2}: + 3+2im 9+2im + 8+7im 4+6im + +julia> adjoint(A) +2×2 Adjoint{Complex{Int64},Array{Complex{Int64},2}}: + 3-2im 8-7im + 9-2im 4-6im +``` +""" adjoint(A::AbstractVecOrMat) = Adjoint(A) + """ - transpose(A::AbstractMatrix) + transpose(A) -Lazy matrix transpose. Mutating the returned object should appropriately mutate `A`. Often, +Lazy transpose. Mutating the returned object should appropriately mutate `A`. Often, but not always, yields `Transpose(A)`, where `Transpose` is a lazy transpose wrapper. Note that this operation is recursive. @@ -61,17 +84,15 @@ This operation is intended for linear algebra usage - for general data manipulat # Examples ```jldoctest -julia> A = [1 2 3; 4 5 6; 7 8 9] -3×3 Array{Int64,2}: - 1 2 3 - 4 5 6 - 7 8 9 +julia> A = [3+2im 9+2im; 8+7im 4+6im] +2×2 Array{Complex{Int64},2}: + 3+2im 9+2im + 8+7im 4+6im julia> transpose(A) -3×3 Transpose{Int64,Array{Int64,2}}: - 1 4 7 - 2 5 8 - 3 6 9 +2×2 Transpose{Complex{Int64},Array{Complex{Int64},2}}: + 3+2im 8+7im + 9+2im 4+6im ``` """ transpose(A::AbstractVecOrMat) = Transpose(A) diff --git a/stdlib/LinearAlgebra/src/deprecated.jl b/stdlib/LinearAlgebra/src/deprecated.jl index 34092c9ef3a9f..b19fe1b917785 100644 --- a/stdlib/LinearAlgebra/src/deprecated.jl +++ b/stdlib/LinearAlgebra/src/deprecated.jl @@ -492,22 +492,6 @@ rvtranspose(x) = transpose(x) parent(rowvec::RowVector) = rowvec.vec vec(rowvec::RowVector) = rowvec.vec -""" - conj(v::RowVector) - -Return a [`ConjArray`](@ref) lazy view of the input, where each element is conjugated. - -# Examples -```jldoctest -julia> v = RowVector([1+im, 1-im]) -1×2 RowVector{Complex{Int64},Array{Complex{Int64},1}}: - 1+1im 1-1im - -julia> conj(v) -1×2 RowVector{Complex{Int64},ConjArray{Complex{Int64},1,Array{Complex{Int64},1}}}: - 1-1im 1+1im -``` -""" @inline conj(rowvec::RowVector) = RowVector(_conj(rowvec.vec)) @inline conj(rowvec::RowVector{<:Real}) = rowvec