ConstantArrays.ConstantArray
— TypeConstantArray{T,D} <: AbstractArray{T,D}
value::T
dim::Dims{D}
ConstantArrays.ConstantArray
— MethodConstantArray(value, dim::Dims)
ConstantArray(dim::Dims) (default value=1)
Return a read-only AbstractArray
of dimension dim
as if it is filled with the constant value
, i.e., equivalent to fill(value, dim)
except it uses much less memory.
The setindex!
operation is not allowed for ConstantArray
Examples
julia> x = ConstantArray(7, (2,3))
2×3 ConstantArray{Int64,2}:
7 7 7
7 7 7
julia> x[1]
7
julia> x[1] = 10
ERROR: setindex! not defined for ConstantArray{Int64,2}
[...]
Base.getindex
— Methodgetindex(x::AbstractArray{T,D}, mask::ConstantArray{Bool,D})
Ensure that x[mask]
is efficient.
Base.show
— Methodshow(io::IO, x::ConstantArray)
show(io::IO, ::MIME"text/plain", x::ConstantArray)
Concise description.
ConstantArrays.getindex!
— Methodgetindex!(y::AbstractVector, x::AbstractArray{T,D}, mask::ConstantArray{Bool,D})
Equivalent to the in-place y .= x[mask]
but is non-allocating.
For non-Boolean indexing, just use @views y .= A[index]
, per https://discourse.julialang.org/t/efficient-non-allocating-in-place-getindex-for-bitarray/42268