Mercurial > repos > public > sbplib_julia
comparison ext/DiffinitiveSparseArraysExt.jl @ 1829:871f3f1decea refactor/grids/iterable_boundary_indices
Merge default
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Sun, 20 Oct 2024 21:38:09 +0200 |
| parents | 471a948cd2b2 |
| children |
comparison
equal
deleted
inserted
replaced
| 1828:8adecef380b4 | 1829:871f3f1decea |
|---|---|
| 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 |
