-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathbasis.jl
More file actions
32 lines (28 loc) · 813 Bytes
/
basis.jl
File metadata and controls
32 lines (28 loc) · 813 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
"""
basis(a::AbstractArray, i)
Construct the `i`-th standard basis array in the vector space of `a`.
"""
function basis(a::AbstractArray{T}, i) where {T}
b = similar(a)
fill!(b, zero(T))
b[i] = one(T)
if ismutable_array(a)
return b
else
return map(+, zero(a), b)
end
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`.
!!! warning
Does not work on GPU, since this is intended for sparse autodiff and SparseMatrixColorings.jl doesn't work on GPUs either.
"""
function multibasis(a::AbstractArray{T}, inds) where {T}
b = similar(a)
fill!(b, zero(T))
for i in inds
b[i] = one(T)
end
return ismutable_array(a) ? b : map(+, zero(a), b)
end