Open JeffFessler opened 4 years ago
This is a great idea! I think the summation loop won't be a problem. A mild challenge is multiply-and-add, because we will rely on LinearCombination
multiplication. But we will need to work on that anyway, to make use of 5-arg mul!
for matrices, which can do multiplication and addition all in one go, allocation-free. Our current generic 5-arg mul!
does allocate an intermediate vector since that is unavoidable for FunctionMap
s, for instance. So we should introduce some clever multiple dispatch to do that only when really necessary. We already do have a test that requests that there is at most one allocation in LinearCombination
multiplication, and we should get that down to zero when all involved linear maps are matrix-based.
I may give it a try when I'm done with the current PRs.
I've got it 90% done. Famous saying about the last 10%... Will send something soon.
🤣 just like me: I also keep telling I won't have time, and then I'm too curious wether it works and start working on it immediately.
Exactly.
This is a rough idea that I want to sketch out now, even though I don't have time to work on it. Suppose
A
is aMxN
linear operator and we think of it being embedded with zeros around it to make a bigger linear operatorB = [0 0 0; 0 A 0; 0 0 0]
where the zeros around it are matrices some of which might be of size0x0
. All one needs to specifyB
is the size of the upper left 0 and the lower right 0. Call this aOffsetMap
or such, where the operationy = B * x
is simplyWe cache the ranges at construction time, very much in the spirit of how
hvcat
is done. All of thehcat
andvcat
andhvcat
objects, I meanBlockMap
objects, are simply sums of theseOffsetBlock
objects with appropriate offsets for each block. ABlockDiagonalMap
is also just a sum of suchOffsetMap
objects. One could imagine other block sparse matrices made by summing several such objects. Instead of having to define separate types for each pattern, all of these are just sums (LinearCombinationMap
) ofOffsetMap
objects. Wish I had thought of this earlier. The only question I have is whether the summation in aLinearCombinationMap
will be as fast as the loops for aBlockMap
. Or am I overlooking any other drawback?