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

More doctests and cleanup for intfuncs #22515

Merged
merged 10 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Doctests for DAYS
  • Loading branch information
kshyatt committed Jun 25, 2017
commit ba4fc8ca4ab0eff589acbb3fa868b6a07bca08bc
2 changes: 1 addition & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ A[iter] = 0

If you supply more than one `AbstractArray` argument, `eachindex` will create an
iterable object that is fast for all arguments (a `UnitRange`
if all inputs have fast linear indexing, a `CartesianRange`
if all inputs have fast linear indexing, a [`CartesianRange`](@ref)
otherwise).
If the arrays have different sizes and/or dimensionalities, `eachindex` returns an
iterable that spans the largest range along each dimension.
Expand Down
3 changes: 3 additions & 0 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ end

Performs a bitwise not operation on `B`. See [`~`](@ref).

# Example
```jldoctest
julia> A = trues(2,2)
2×2 BitArray{2}:
Expand Down Expand Up @@ -1497,6 +1498,7 @@ Performs a left rotation operation, returning a new `BitVector`.
`i` controls how far to rotate the bits.
See also [`rol!`](@ref).

# Examples
```jldoctest
julia> A = BitArray([true, true, false, false, true])
5-element BitArray{1}:
Expand Down Expand Up @@ -1566,6 +1568,7 @@ Performs a right rotation operation on `B`, returning a new `BitVector`.
`i` controls how far to rotate the bits.
See also [`ror!`](@ref).

# Examples
```jldoctest
julia> A = BitArray([true, true, false, false, true])
5-element BitArray{1}:
Expand Down
84 changes: 81 additions & 3 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,23 @@ Returns the range of indices of `a` which compare as equal to `x` (using binary
according to the order specified by the `by`, `lt` and `rev` keywords, assuming that `a`
is already sorted in that order. Returns an empty range located at the insertion point
if `a` does not contain values equal to `x`.

# Examples

Copy link
Member

Choose a reason for hiding this comment

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

Extra empty line?

```jldoctest
julia> a = [4, 3, 2, 1]
4-element Array{Int64,1}:
4
3
2
1

julia> searchsorted(a, 4)
5:4

julia> searchsorted(a, 4, rev=true)
1:1
```
"""
searchsorted

Expand Down Expand Up @@ -638,7 +655,7 @@ julia> 4 & 12
"""
select(v, k, [by=<transform>,] [lt=<comparison>,] [rev=false])

Variant of `select!` which copies `v` before partially sorting it, thereby returning the
Variant of [`select!`](@ref) which copies `v` before partially sorting it, thereby returning the
same thing as `select!` but leaving `v` unmodified.
"""
select
Expand Down Expand Up @@ -842,6 +859,48 @@ at the position where it would appear if the array were fully sorted via a non-s
algorithm. If `k` is a single index, that value is returned; if `k` is a range, an array of
values at those indices is returned. Note that `select!` does not fully sort the input
array.

# Examples

Copy link
Member

Choose a reason for hiding this comment

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

Extra empty line here as well? (Have we a convention for absence/presence of an extra empty line following # Example[s]? Remarked here and above for consistency with the absence earlier in this PR, but have no preference.)

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 pick and standardize - personally I lean towards leaving out the empty line, assuming it should render the same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree but I think we should a) pick one and b) have one mega-PR to fix it everywhere (much like @StefanKarpinski did with the @test_approx_eq macro).

Copy link
Member

@Sacha0 Sacha0 Jun 26, 2017

Choose a reason for hiding this comment

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

Sounds good! :) (Small PRs are nice though!)

```jldoctest
julia> a = [1, 2, 4, 3, 4]
5-element Array{Int64,1}:
1
2
4
3
4

julia> select!(a, 4)
4

julia> a
5-element Array{Int64,1}:
1
2
3
4
4

julia> a = [1, 2, 4, 3, 4]
5-element Array{Int64,1}:
1
2
4
3
4

julia> select!(a, 4, rev=true)
2

julia> a
5-element Array{Int64,1}:
4
4
3
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.

Perhaps an example illustrating the partial sorting behavior would be worthwhile? The examples above yield fully sorted results.

"""
select!

Expand All @@ -851,6 +910,15 @@ select!
Create a random ASCII string of length `len`, consisting of upper- and
lower-case letters and the digits 0-9. The optional `rng` argument
specifies a random number generator, see [Random Numbers](@ref).

# Example

Copy link
Member

Choose a reason for hiding this comment

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

See extra empty line question above :).

```jldoctest
julia> rng = MersenneTwister(1234);

julia> randstring(rng, 4)
"mbDd"
```
"""
randstring

Expand Down Expand Up @@ -1168,7 +1236,7 @@ Return a partial permutation of the vector `v`, according to the order specified
if `k` is a range) values of a fully sorted version of `v`. If `k` is a single index
(Integer), an array of the first `k` indices is returned; if `k` is a range, an array of
those indices is returned. Note that the handling of integer values for `k` is different
from `select` in that it returns a vector of `k` elements instead of just the `k` th
from [`select`](@ref) in that it returns a vector of `k` elements instead of just the `k` th
element. Also note that this is equivalent to, but more efficient than, calling
`sortperm(...)[k]`.
"""
Expand Down Expand Up @@ -1279,12 +1347,16 @@ Returns the index of the first value in `a` greater than or equal to `x`, accord
specified order. Returns `length(a)+1` if `x` is greater than all values in `a`.

# Examples

Copy link
Member

Choose a reason for hiding this comment

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

See question above re. empty lines :).

```jldoctest
julia> searchsortedfirst([1, 2, 4, 5, 4], 4)
3

julia> searchsortedfirst([1, 2, 4, 5, 4], 4, rev=true)
1

julia> searchsortedfirst([1, 2, 4, 5, 4], 6)
6
```
"""
searchsortedfirst
Expand Down Expand Up @@ -1315,7 +1387,7 @@ typejoin
"""
selectperm!(ix, v, k, [alg=<algorithm>,] [by=<transform>,] [lt=<comparison>,] [rev=false,] [initialized=false])

Like `selectperm`, but accepts a preallocated index vector `ix`. If `initialized` is `false`
Like [`selectperm`](@ref), but accepts a preallocated index vector `ix`. If `initialized` is `false`
(the default), ix is initialized to contain the values `1:length(ix)`.
"""
selectperm!
Expand All @@ -1342,6 +1414,8 @@ key is present.

# Examples
```jldoctest
julia> d = Dict("a"=>1, "b"=>2)

julia> get(d, "a", 3)
Copy link
Contributor

Choose a reason for hiding this comment

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

does this pass? where does d come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops, forgot to copy paste

1

Expand Down Expand Up @@ -1946,12 +2020,16 @@ Returns the index of the last value in `a` less than or equal to `x`, according
specified order. Returns `0` if `x` is less than all values in `a`.

# Examples

```jldoctest
julia> searchsortedlast([1, 2, 4, 5, 4], 4)
Copy link
Contributor

Choose a reason for hiding this comment

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

examples for this function should use sorted inputs, that's what it's designed for

3

julia> searchsortedlast([1, 2, 4, 5, 4], 4, rev=true)
5

julia> searchsortedlast([1, 2, 4, 5, 4], -1)
0
```
"""
searchsortedlast
Expand Down
29 changes: 22 additions & 7 deletions base/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,21 @@ values of `M` have magnitude greater than `tol`.
By default, the value of `tol` is the largest
dimension of `M` multiplied by the [`eps`](@ref)
of the [`eltype`](@ref) of `M`.

# Example
```jldoctest
julia> rank(eye(3))
3

julia> rank(diagm([1, 0, 2]))
2

julia> rank(diagm([1, 0.001, 2]), 0.1)
2

julia> rank(diagm([1, 0.001, 2]), 0.00001)
3
```
"""
rank(A::AbstractMatrix, tol::Real) = mapreduce(x -> x > tol, +, 0, svdvals(A))
function rank(A::AbstractMatrix)
Expand Down Expand Up @@ -854,7 +869,7 @@ issymmetric(A::AbstractMatrix{<:Real}) = ishermitian(A)

Test whether a matrix is symmetric.

# Example
# Examples

```jldoctest
julia> a = [1 2; 2 -1]
Expand Down Expand Up @@ -894,7 +909,7 @@ issymmetric(x::Number) = x == x

Test whether a matrix is Hermitian.

# Example
# Examples

```jldoctest
julia> a = [1 2; 2 -1]
Expand Down Expand Up @@ -934,7 +949,7 @@ ishermitian(x::Number) = (x == conj(x))

Test whether a matrix is upper triangular.

# Example
# Examples

```jldoctest
julia> a = [1 2; 2 -1]
Expand Down Expand Up @@ -969,7 +984,7 @@ end

Test whether a matrix is lower triangular.

# Example
# Examples

```jldoctest
julia> a = [1 2; 2 -1]
Expand Down Expand Up @@ -1004,7 +1019,7 @@ end

Test whether a matrix is diagonal.

# Example
# Examples

```jldoctest
julia> a = [1 2; 2 -1]
Expand Down Expand Up @@ -1226,7 +1241,7 @@ logabsdet(A::AbstractMatrix) = logabsdet(lufact(A))
Log of matrix determinant. Equivalent to `log(det(M))`, but may provide
increased accuracy and/or speed.

# Example
# Examples

```jldoctest
julia> M = [1 0; 2 2]
Expand Down Expand Up @@ -1324,7 +1339,7 @@ Normalize the vector `v` so that its `p`-norm equals unity,
i.e. `norm(v, p) == vecnorm(v, p) == 1`.
See also [`normalize!`](@ref) and [`vecnorm`](@ref).

# Example
# Examples

```jldoctest
julia> a = [1,2,4];
Expand Down
Loading