Skip to content

Commit

Permalink
Move docs inline from helpdb and add a couple doctests (JuliaLang#22651)
Browse files Browse the repository at this point in the history
  • Loading branch information
xorJane authored and jeffwong committed Jul 24, 2017
1 parent 30595fd commit 3c4761e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 40 deletions.
12 changes: 12 additions & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,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)`.
"""
full(x::AbstractArray) = x

## range conversions ##
Expand Down Expand Up @@ -1267,6 +1273,7 @@ end
Concatenate along dimension 1.
# Examples
```jldoctest
julia> a = [1 2 3 4 5]
1×5 Array{Int64,2}:
Expand Down Expand Up @@ -1298,6 +1305,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 @@ -1374,6 +1382,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 @@ -1579,6 +1588,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 @@ -1606,6 +1616,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 @@ -1655,6 +1666,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 @@ -2045,29 +2045,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 @@ -2135,23 +2112,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 @@ -49,6 +49,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 @@ -69,6 +70,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 @@ -83,6 +85,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 @@ -132,6 +135,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 @@ -190,6 +208,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.
"""
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

0 comments on commit 3c4761e

Please sign in to comment.