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

Make falses(A) and trues(A) not change their argument #15827

Merged
merged 1 commit into from
Apr 18, 2016
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
29 changes: 27 additions & 2 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,33 @@ function fill!(B::BitArray, x)
return B
end

falses(args...) = fill!(BitArray(args...), false)
trues(args...) = fill!(BitArray(args...), true)
"""
falses(dims)

Create a `BitArray` with all values set to `false`.
"""
falses(dims::Dims) = fill!(BitArray(dims), false)
falses(dims::Integer...) = falses(dims)
"""
falses(A)

Create a `BitArray` with all values set to `false` of the same shape as `A`.
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

may as well separate the docstrings for the separate signatures, I think

Copy link
Member Author

Choose a reason for hiding this comment

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

Um, yes, just tried to, but then genstdlib.jl does not include the docs for the second signature in its output. Any idea what I'm doing wrong? The REPL output with "?" looks the same as before.

Copy link
Contributor

Choose a reason for hiding this comment

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

You need to manually add the first line with the signature into the rst for genstdlib to match it and populate the rest

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, yes, thanks.

falses(A::AbstractArray) = falses(size(A))

"""
trues(dims)

Create a `BitArray` with all values set to `true`.
"""
trues(dims::Dims) = fill!(BitArray(dims), true)
trues(dims::Integer...) = trues(dims)
"""
trues(A)

Create a `BitArray` with all values set to `true` of the same shape as `A`.
"""
trues(A::AbstractArray) = trues(size(A))

function one(x::BitMatrix)
m, n = size(x)
Expand Down
14 changes: 0 additions & 14 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1124,13 +1124,6 @@ results to `r`.
"""
any!

"""
falses(dims)

Create a `BitArray` with all values set to `false`.
"""
falses

"""
filter!(function, collection)

Expand Down Expand Up @@ -7825,13 +7818,6 @@ x == fld(x,y)*y + mod(x,y)
"""
mod

"""
trues(dims)

Create a `BitArray` with all values set to `true`.
"""
trues

"""
qr(A [,pivot=Val{false}][;thin=true]) -> Q, R, [p]

Expand Down
2 changes: 2 additions & 0 deletions doc/manual/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ Function Description
``type`` not specified
:func:`ones(A) <ones>` an array of all ones of same element type and shape of ``A``
:func:`trues(dims...) <trues>` a ``Bool`` array with all values ``true``
:func:`trues(A) <trues>` a ``Bool`` array with all values ``true`` and the shape of ``A``
:func:`falses(dims...) <falses>` a ``Bool`` array with all values ``false``
:func:`falses(A) <falses>` a ``Bool`` array with all values ``false`` and the shape of ``A``
:func:`reshape(A, dims...) <reshape>` an array with the same data as the given array, but with
different dimensions.
:func:`copy(A) <copy>` copy ``A``
Expand Down
12 changes: 12 additions & 0 deletions doc/stdlib/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,24 @@ Constructors

Create a ``BitArray`` with all values set to ``true``\ .

.. function:: trues(A)

.. Docstring generated from Julia source

Create a ``BitArray`` with all values set to ``true`` of the same shape as ``A``\ .

.. function:: falses(dims)

.. Docstring generated from Julia source

Create a ``BitArray`` with all values set to ``false``\ .

.. function:: falses(A)

.. Docstring generated from Julia source

Create a ``BitArray`` with all values set to ``false`` of the same shape as ``A``\ .

.. function:: fill(x, dims)

.. Docstring generated from Julia source
Expand Down
20 changes: 20 additions & 0 deletions test/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ s1, s2, s3, s4 = 5, 8, 3, 4
allsizes = [((), BitArray{0}), ((v1,), BitVector),
((n1,n2), BitMatrix), ((s1,s2,s3,s4), BitArray{4})]

# trues and falses
for (sz,T) in allsizes
a = falses(sz...)
@test a == falses(sz)
@test !any(a)
@test sz == size(a)
b = trues(sz...)
@test b == trues(sz)
@test all(b)
@test sz == size(b)
c = trues(a)
@test all(c)
@test !any(a)
@test sz == size(c)
d = falses(b)
@test !any(d)
@test all(b)
@test sz == size(d)
end

## Conversions ##

for (sz,T) in allsizes
Expand Down