Skip to content

Commit 5beb45f

Browse files
author
Andy Ferris
committed
Added copy
1 parent c1ead9f commit 5beb45f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/StaticArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Base: @pure, @propagate_inbounds, getindex, setindex!, size, similar,
77
broadcast, broadcast!, conj, transpose, ctranspose, hcat, vcat,
88
ones, zeros, eye, one, cross, vecdot, reshape, fill, fill!, det,
99
inv, eig, trace, vecnorm, norm, dot, diagm, sum, prod, count, any,
10-
all, sumabs, sumabs2, minimum, maximum, extrema, mean
10+
all, sumabs, sumabs2, minimum, maximum, extrema, mean, copy
1111

1212
export StaticScalar, StaticArray, StaticVector, StaticMatrix
1313
export Scalar, SArray, SVector, SMatrix

src/abstractarray.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,22 @@ end
294294
return $newtype(a)
295295
end
296296
end
297+
298+
# Clever ruse to determine if a type is "mutable"
299+
# Definitely *not* a deep copy.
300+
@generated function copy(a::StaticArray)
301+
try
302+
out = a()
303+
return quote
304+
$(Expr(:meta, :inline))
305+
out = $(a)()
306+
out .= a
307+
return out
308+
end
309+
catch
310+
return quote
311+
$(Expr(:meta, :inline))
312+
a
313+
end
314+
end
315+
end

0 commit comments

Comments
 (0)