A Julia data type that is a subtype of
where every element is the same constant.
The "constant" in the name has two meaning:
every element of the array has the same constant value,
and the array is immutable
setindex! is unsupported).
Caution: This Package No Longer Maintained!
This package is now a subset of the existing
(that I did not know about when I wrote it).
My original version had a extra couple features
but I contributed those to
So now I will no longer maintain this package
and I strongly recommend you use
At the Julia REPL run:
using Pkg; Pkg.add("ConstantArrays").
At the Julia REPL execute:
?ConstantArray and press enter to get help.
Primary usage example:
x = ConstantArray(42, (5,7))
makes a "lazy" constant "array"
functionally equivalent to
but essentially requires only
the memory need to store a struct
with the value
42 and the dimensions
The motivating use of this type
is for the "masks" used in tomographic image reconstruction
that are often uniform
but also often patient conforming.
The default one-argument usage
mask = ConstantArray((4,6)) uses
as the constant value
for this purpose.
The idea here is somewhat analogous
UniformScaling type (
I is non-essential
because one could accomplish something similar
I requires much less memory.
ConstantArray is non-essential, but
ConstantArray(true, (100,100,100)) uses about a million times
less memory than
A better analogy might be a sparse array,
where only the nonzero values are stored
to save memory.
ConstantArray needs only to store only a single value.
The most useful operations are probably
x .* y
both of which are faster
Developed by Jeff Fessler at the University of Michigan, with some inspiration from ReadOnlyArrays.jl.