comparison ext/DiffinitiveSparseArraysExt.jl @ 1751:f3d7e2d7a43f feature/sbp_operators/laplace_curvilinear

Merge feature/grids/manifolds
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 11 Sep 2024 16:26:19 +0200
parents 471a948cd2b2
children
comparison
equal deleted inserted replaced
1731:3684db043add 1751:f3d7e2d7a43f
1 module DiffinitiveSparseArraysExt
2
3 using Diffinitive
4 using Diffinitive.LazyTensors
5
6 using SparseArrays
7 using Tokens
8
9 """
10 sparse(t::LazyTensor)
11
12 The sparse matrix representation of `t`.
13
14 If `L` is a `LazyTensor` and `v` a tensor, then `A = sparse(L)` is constructed
15 so that `A*reshape(v,:) == reshape(L*v,:)`.
16 """
17 function SparseArrays.sparse(t::LazyTensor)
18 v = ArrayToken(:v, prod(domain_size(t)))
19
20 v̄ = reshape(v,domain_size(t)...)
21 tv = reshape(t*v̄, :)
22 return Tokens._to_matrix(tv, prod(range_size(t)), prod(domain_size(t)))
23 end
24
25 end