-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathbasis.jl
More file actions
39 lines (33 loc) · 889 Bytes
/
basis.jl
File metadata and controls
39 lines (33 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
pre_basis(a::AbstractArray{T}) where {T} = fill!(similar(a), zero(T))
function post_basis(b::AbstractArray, a::AbstractArray)
if ismutable_array(a)
return b
else
return map(+, zero(a), b)
end
end
"""
basis(a::AbstractArray, i)
Construct the `i`-th standard basis array in the vector space of `a`.
"""
function basis(a::AbstractArray, i)
b = pre_basis(a)
b[i] = oneunit(eltype(b))
return post_basis(b, a)
end
# compatible with zero-length vectors
function basis(a::AbstractArray)
b = pre_basis(a)
return post_basis(b, a)
end
"""
multibasis(a::AbstractArray, inds)
Construct the sum of the `i`-th standard basis arrays in the vector space of `a` for all `i ∈ inds`.
"""
function multibasis(a::AbstractArray, inds)
b = pre_basis(a)
for i in inds
b[i] = oneunit(eltype(b))
end
return post_basis(b, a)
end