Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove LinearAlgebra things from the base manual #25723

Merged
merged 1 commit into from
Jan 29, 2018
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
2 changes: 1 addition & 1 deletion base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```
Expand Down
2 changes: 1 addition & 1 deletion base/event.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
22 changes: 0 additions & 22 deletions base/number.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
18 changes: 8 additions & 10 deletions base/permuteddimsarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}}:
Copy link
Member

Choose a reason for hiding this comment

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

Will this doctest pass without a using LinearAlgebra prior to this call?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, at least for now, since transpose is Base.transpose and LinearAlgebra is required in sysimg.jl. But I am not sure how informative this example actually is and would be happy to remove the showcasing of transpose from the permutedims examples. Would you, or anyone else, object to such a removal?

Copy link
Member

Choose a reason for hiding this comment

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

I am more or less ambivalent :). Perhaps seek additional parties' opinions?

Copy link
Member Author

Choose a reason for hiding this comment

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

Lets keep this for now then.

[1 3; 2 4] [9 11; 10 12]
[5 7; 6 8] [13 15; 14 16]
```
Expand All @@ -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]
Expand All @@ -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}}:
Copy link
Member

Choose a reason for hiding this comment

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

Same question here :).

[1 3; 2 4] [5 7; 6 8]
```
"""
Expand Down
12 changes: 6 additions & 6 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
```
"""
Expand Down Expand Up @@ -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)]
Expand Down
10 changes: 5 additions & 5 deletions base/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions doc/src/manual/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion doc/src/manual/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
55 changes: 32 additions & 23 deletions doc/src/manual/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions doc/src/manual/parallel-computing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
```

Expand Down
2 changes: 0 additions & 2 deletions stdlib/LinearAlgebra/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,6 @@ LinearAlgebra.istril
LinearAlgebra.istriu
LinearAlgebra.isdiag
LinearAlgebra.ishermitian
LinearAlgebra.RowVector
LinearAlgebra.ConjArray
Base.transpose
LinearAlgebra.transpose!
Base.adjoint
Expand Down
43 changes: 32 additions & 11 deletions stdlib/LinearAlgebra/src/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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)
Expand Down
Loading