-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 some docstrings from helpdb to function definitions #22520
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,6 +212,37 @@ function getindex(::Type{Any}, vals::ANY...) | |
end | ||
getindex(::Type{Any}) = Array{Any,1}(0) | ||
|
||
""" | ||
fill!(A, x) | ||
|
||
Fill array `A` with the value `x`. If `x` is an object reference, all elements will refer to | ||
the same object. `fill!(A, Foo())` will return `A` filled with the result of evaluating | ||
`Foo()` once. | ||
|
||
```jldoctest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While you are at it, perhaps add an |
||
julia> A = zeros(2,3) | ||
2×3 Array{Float64,2}: | ||
0.0 0.0 0.0 | ||
0.0 0.0 0.0 | ||
|
||
julia> fill!(A, 2.) | ||
2×3 Array{Float64,2}: | ||
2.0 2.0 2.0 | ||
2.0 2.0 2.0 | ||
|
||
julia> a = [1, 1, 1]; A = fill!(Vector{Vector{Int}}(3), a); a[1] = 2; A | ||
3-element Array{Array{Int64,1},1}: | ||
[2, 1, 1] | ||
[2, 1, 1] | ||
[2, 1, 1] | ||
|
||
julia> x = 0; f() = (global x += 1; x); fill!(Vector{Int}(3), f()) | ||
3-element Array{Int64,1}: | ||
1 | ||
1 | ||
1 | ||
``` | ||
""" | ||
function fill!(a::Union{Array{UInt8}, Array{Int8}}, x::Integer) | ||
ccall(:memset, Ptr{Void}, (Ptr{Void}, Cint, Csize_t), a, x, length(a)) | ||
return a | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,12 @@ systemerror(p, b::Bool; extrainfo=nothing) = b ? throw(Main.Base.SystemError(str | |
|
||
## assertion functions and macros ## | ||
|
||
""" | ||
assert(cond) | ||
|
||
Throw an [`AssertionError`](@ref) if `cond` is `false`. | ||
Also available as the macro `@assert expr`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps only |
||
""" | ||
assert(x) = x ? nothing : throw(Main.Base.AssertionError()) | ||
macro assert(ex, msgs...) | ||
msg = isempty(msgs) ? ex : msgs[1] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -384,22 +384,6 @@ to return. | |
""" | ||
read(s::IO, ::Type{T}, dims::Dims) where {T} = read!(s, Array{T}(dims)) | ||
|
||
@noinline function read!(s::IO, a::Array{UInt8}) # mark noinline to ensure the array is gc-rooted somewhere (by the caller) | ||
unsafe_read(s, pointer(a), sizeof(a)) | ||
return a | ||
end | ||
|
||
@noinline function read!(s::IO, a::Array{T}) where T # mark noinline to ensure the array is gc-rooted somewhere (by the caller) | ||
if isbits(T) | ||
unsafe_read(s, pointer(a), sizeof(a)) | ||
else | ||
for i in eachindex(a) | ||
a[i] = read(s, T) | ||
end | ||
end | ||
return a | ||
end | ||
|
||
function read(s::IO, ::Type{Char}) | ||
ch = read(s, UInt8) | ||
if ch < 0x80 | ||
|
@@ -419,6 +403,28 @@ function read(s::IO, ::Type{Char}) | |
return Char(c) | ||
end | ||
|
||
""" | ||
read!(stream::IO, array::Union{Array, BitArray}) | ||
read!(filename::AbstractString, array::Union{Array, BitArray}) | ||
|
||
Read binary data from an I/O stream or file, filling in `array`. | ||
""" | ||
@noinline function read!(s::IO, a::Array{T}) where T # mark noinline to ensure the array is gc-rooted somewhere (by the caller) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, any reason these functions where moved down? :) |
||
if isbits(T) | ||
unsafe_read(s, pointer(a), sizeof(a)) | ||
else | ||
for i in eachindex(a) | ||
a[i] = read(s, T) | ||
end | ||
end | ||
return a | ||
end | ||
|
||
@noinline function read!(s::IO, a::Array{UInt8}) # mark noinline to ensure the array is gc-rooted somewhere (by the caller) | ||
unsafe_read(s, pointer(a), sizeof(a)) | ||
return a | ||
end | ||
|
||
# readuntil_string is useful below since it has | ||
# an optimized method for s::IOStream | ||
readuntil_string(s::IO, delim::UInt8) = String(readuntil(s, delim)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the variable name a isn't referenced in the signature, might make more sense if consistent