ProtectedArrays
Documentation for ProtectedArrays.
julia> using ProtectedArrays
julia> a = zeros(2, 5)
2×5 Matrix{Float64}:
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
julia> pa = protect(a)
2×5 ProtectedMatrix(::Matrix{Float64}) with eltype Float64:
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
julia> pa[1] = 1.
ERROR: `ProtectedArray` does not allow modifying elements with `setindex!`,
use `unprotect` if you really know what you're doing.
[...]
julia> pa[1, 1] = 1.
ERROR: `ProtectedArray` does not allow modifying elements with `setindex!`,
use `unprotect` if you really know what you're doing.
[...]
julia> pa[:, 1] .= 1.
ERROR: `ProtectedArray` does not allow modifying elements with `setindex!`,
use `unprotect` if you really know what you're doing.
[...]
julia> fill!(pa, 1.)
ERROR: `ProtectedArray` does not allow modifying elements with `setindex!`,
use `unprotect` if you really know what you're doing.
[...]
julia> a # unmodified
2×5 Matrix{Float64}:
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
API
ProtectedArrays.ProtectedArray
ProtectedArrays.ProtectedMatrix
ProtectedArrays.ProtectedVector
Base.similar
ProtectedArrays.protect
ProtectedArrays.unprotect
ProtectedArrays.ProtectedArray
— TypeProtectedArray(array)
Wrapper around an array which disables setindex!
to prevent modifications.
ProtectedArrays.ProtectedMatrix
— TypeProtectedMatrix(matrix)
Type alias and convenience constructor for two-dimensional ProtectedArray
s.
ProtectedArrays.ProtectedVector
— TypeProtectedVector(vector)
Type alias and convenience constructor for one-dimensional ProtectedArray
s.
Base.similar
— Methodsimilar(pa::ProtectedArray, eltype=eltype(pa), dims=size(pa))
Create an uninitialized mutable array based on the underlying array parent(pa)
wrapped by ProtectedArray
.
ProtectedArrays.protect
— Functionprotect(array::AbstractArray)
Wrap an array into a ProtectedArray
to prevent modifications.
See also unprotect
.
ProtectedArrays.unprotect
— Functionunprotect(::ProtectedArray)
Unwrap a ProtectedArray
into the underlying array.
This is a synonym of parent
.
See also protect
.