Mercurial > repos > public > sbplib_julia
comparison ext/DiffinitiveSparseArraysExt.jl @ 1726:471a948cd2b2 rename_module
Rename project from Sbplib to Diffinitive
| author | Vidar Stiernström <vidar.stiernstrom@gmail.com> |
|---|---|
| date | Sat, 07 Sep 2024 12:11:53 -0700 |
| parents | ext/SbplibSparseArraysExt.jl@8787b2f9f5f8 |
| children |
comparison
equal
deleted
inserted
replaced
| 1725:8317252e4535 | 1726:471a948cd2b2 |
|---|---|
| 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 |
