Mercurial > repos > public > sbplib_julia
comparison ext/DiffinitiveSparseArraysExt.jl @ 1748:03894fd7b132 feature/grids/manifolds
Merge feature/grids/curvilinear
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 11 Sep 2024 15:41:58 +0200 |
parents | 471a948cd2b2 |
children |
comparison
equal
deleted
inserted
replaced
1695:a4c52ae93b11 | 1748:03894fd7b132 |
---|---|
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 |