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

Move docs inline from helpdb and add a couple doctests #22651

Merged
merged 1 commit into from
Jul 11, 2017
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
12 changes: 12 additions & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,12 @@ Represents the array `y` as an array having the same indices type as `x`.
"""
of_indices(x, y) = similar(dims->y, oftype(indices(x), indices(y)))


"""
full(F)

Reconstruct the matrix `A` from the factorization `F=factorize(A)`.
"""
Copy link
Member

Choose a reason for hiding this comment

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

(Tangent: This docstring for full only captures one of the various meanings of full. Perhaps we should flesh out this docstring? Or not worry about it in anticipation of complete excision of full in this release cycle?)

Copy link
Member

Choose a reason for hiding this comment

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

If it were me I'd just leave it as-is, since that's a larger task than simply relocating the docstring.

full(x::AbstractArray) = x

## range conversions ##
Expand Down Expand Up @@ -1265,6 +1271,7 @@ end

Concatenate along dimension 1.

# Examples
```jldoctest
julia> a = [1 2 3 4 5]
1×5 Array{Int64,2}:
Expand Down Expand Up @@ -1296,6 +1303,7 @@ vcat(X...) = cat(Val{1}, X...)

Concatenate along dimension 2.

# Examples
```jldoctest
julia> a = [1; 2; 3; 4; 5]
5-element Array{Int64,1}:
Expand Down Expand Up @@ -1372,6 +1380,7 @@ Horizontal and vertical concatenation in one call. This function is called for b
syntax. The first argument specifies the number of arguments to concatenate in each block
row.

# Examples
```jldoctest
julia> a, b, c, d, e, f = 1, 2, 3, 4, 5, 6
(1, 2, 3, 4, 5, 6)
Expand Down Expand Up @@ -1577,6 +1586,7 @@ end

Returns a tuple of subscripts into array `a` corresponding to the linear index `index`.

# Examples
```jldoctest
julia> A = ones(5,6,7);

Expand Down Expand Up @@ -1604,6 +1614,7 @@ sub2ind(::Tuple{}, I::Integer...) = (@_inline_meta; _sub2ind((), 1, 1, I...))

The inverse of [`ind2sub`](@ref), returns the linear index corresponding to the provided subscripts.

# Examples
```jldoctest
julia> sub2ind((5,6,7),1,2,3)
66
Expand Down Expand Up @@ -1653,6 +1664,7 @@ i, j, ... = ind2sub(size(A), indmax(A))

provides the indices of the maximum element.

# Examples
```jldoctest
julia> ind2sub((3,4),2)
(2, 1)
Expand Down
40 changes: 0 additions & 40 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2055,29 +2055,6 @@ x` is converted by the compiler to `(setindex!(a, x, i, j, ...); x)`.
"""
setindex!(collection,value,key...)

"""
signif(x, digits, [base])

Rounds (in the sense of [`round`](@ref)) `x` so that there are `digits` significant digits, under a
base `base` representation, default 10. E.g., `signif(123.456, 2)` is `120.0`, and
`signif(357.913, 4, 2)` is `352.0`.
"""
signif

"""
full(F)

Reconstruct the matrix `A` from the factorization `F=factorize(A)`.
"""
full(F)

"""
throw(e)

Throw an object as an exception.
"""
throw

"""
zeros([A::AbstractArray,] [T=eltype(A)::Type,] [dims=size(A)::Tuple])

Expand Down Expand Up @@ -2145,23 +2122,6 @@ Values for `String` can be of that type, or `Vector{UInt8}`.
"""
isvalid(T,value)

"""
reverseind(v, i)

Given an index `i` in `reverse(v)`, return the corresponding index in `v` so that
`v[reverseind(v,i)] == reverse(v)[i]`. (This can be nontrivial in the case where `v` is a
Unicode string.)
"""
reverseind

"""
exit([code])

Quit (or control-D at the prompt). The default exit code is zero, indicating that the
processes completed successfully.
"""
exit

"""
skipchars(stream, predicate; linecomment::Char)

Expand Down
7 changes: 7 additions & 0 deletions base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
# rethrow(val)
# end

"""
throw(e)

Throw an object as an exception.
"""
throw

## native julia error handling ##

error(s::AbstractString) = throw(ErrorException(s))
Expand Down
19 changes: 19 additions & 0 deletions base/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ specifying a rounding mode the global mode will be used
([`RoundNearest`](@ref) mode), with ties (fractional values of 0.5) being
rounded to the nearest even integer.

# Examples
```jldoctest
julia> round(1.7)
2.0
Expand All @@ -68,6 +69,7 @@ rounded.
`round(x, digits)` rounds to the specified number of digits after the decimal place (or
before if negative). `round(x, digits, base)` rounds using a base other than 10.

# Examples
```jldoctest
julia> round(pi, 2)
3.14
Expand All @@ -82,6 +84,7 @@ julia> round(pi, 3, 2)
value represented by `1.15` is actually *less* than 1.15, yet will be
rounded to 1.2.

# Examples
```jldoctest
julia> x = 1.15
1.15
Expand Down Expand Up @@ -131,6 +134,21 @@ function _signif_og(x, digits, base)
return og, e
end

"""
signif(x, digits, [base])

Rounds (in the sense of [`round`](@ref)) `x` so that there are `digits` significant digits, under a
base `base` representation, default 10.

# Examples
```jldoctest
julia> signif(123.456, 2)
120.0

julia> signif(357.913, 4, 2)
352.0
```
"""
function signif(x::Real, digits::Integer, base::Integer=10)
digits < 1 && throw(DomainError())

Expand Down Expand Up @@ -189,6 +207,7 @@ approximately equal component-wise.
The binary operator `≈` is equivalent to `isapprox` with the default arguments, and `x ≉ y`
is equivalent to `!isapprox(x,y)`.

# Examples
```jldoctest
julia> 0.1 ≈ (0.1 - 1e-10)
true
Expand Down
6 changes: 6 additions & 0 deletions base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ An array of the command line arguments passed to Julia, as strings.
"""
const ARGS = String[]

"""
exit([code])
Quit (or control-D at the prompt). The default exit code is zero, indicating that the
processes completed successfully.
Copy link
Contributor

Choose a reason for hiding this comment

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

does processes being plural here sound redundant / a little off to anyone else?

Copy link
Member

Choose a reason for hiding this comment

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

Sounded a little off on first read, yes. Technically more correct than a singular equivalent though I suppose.

On that note, the "control-D at the prompt" snippet strikes me as out of place as well. Perhaps could be listed as a synonym instead? Also could use a ref to the quit() docstring.

Copy link
Contributor

Choose a reason for hiding this comment

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

we should maybe note these as future todo cleanups somewhere

Copy link
Member

Choose a reason for hiding this comment

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

Captured in an intro issue: #22765. Best!

"""
exit(n) = ccall(:jl_exit, Void, (Int32,), n)
exit() = exit(0)
quit() = exit()
Expand Down
20 changes: 20 additions & 0 deletions base/strings/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ end
reverse(s::AbstractString) -> AbstractString

Reverses a string.
# Examples
```jldoctest
julia> reverse("JuliaLang")
"gnaLailuJ"
Expand All @@ -127,6 +128,24 @@ reverse(s::RevString) = s.string

## reverse an index i so that reverse(s)[i] == s[reverseind(s,i)]

"""
reverseind(v, i)

Given an index `i` in `reverse(v)`, return the corresponding index in `v` so that
`v[reverseind(v,i)] == reverse(v)[i]`. (This can be nontrivial in the case where `v` is a
Unicode string.)

# Examples
```jldoctest
julia> r = reverse("Julia")
"ailuJ"

julia> for i in 1:length(r)
print(r[reverseind("Julia", i)])
end
Julia
```
"""
reverseind(s::AbstractString, i) = chr2ind(s, length(s) + 1 - ind2chr(reverse(s), i))
reverseind(s::Union{DirectIndexString,SubString{DirectIndexString}}, i::Integer) = length(s) + 1 - i
reverseind(s::RevString, i::Integer) = endof(s) - i + 1
Expand All @@ -146,6 +165,7 @@ end
Repeat `n` times the string `s`.
The [`repeat`](@ref) function is an alias to this operator.

# Examples
```jldoctest
julia> "Test "^3
"Test Test Test "
Expand Down