Zulip Chat Archive
Stream: new members
Topic: Extracting block out of a matrix
Vivek Rajesh Joshi (May 20 2024 at 08:07):
If I have a Fin-indexed mxn matrix, given some indices i and j, how do I extract the block matrix starting from (i,j) upto (m,n) from the original matrix? I tried using Matrix.toBlock
but it isn't giving me Fin-indexed matrix, and I can't figure out how to construct a submatrix from the way it has been defined.
Yaël Dillies (May 20 2024 at 08:09):
Vivek Rajesh Joshi said:
I tried using
Matrix.toBlock
but it isn't giving me Fin-indexed matrix
Why is that a problem?
Vivek Rajesh Joshi (May 20 2024 at 08:50):
It isn't exactly a problem, just a matter of convenience. In my code so far I've been working with Fin-indexed matrices, so if I can continue that it would be nice. If that isn't possible, I'll try to work with these matrices going forward.
Eric Wieser (May 20 2024 at 09:02):
The general answer is "use docs#Matrix.submatrix", which leaves you the job of constructing the maps you want between the index types
Eric Wieser (May 20 2024 at 09:03):
This should hopefully make it obvious why using Fin
here can be annoying, as the map from Fin j
to Fin (i + j + k)
is a bit fiddly to write down
Iris Rotarescu (May 20 2024 at 09:09):
(deleted)
Vivek Rajesh Joshi (May 20 2024 at 10:41):
So if I want to take the bottom right 2x2 block out of a 3x3 matrix, should I give both the reindex maps as 0 -> 1, 1 -> 1, 2 -> 2?
Eric Wieser (May 20 2024 at 10:57):
Going from a big matrix to a small matrix means your indexing map goes from the small index to the big index; so that map is backwards
Vivek Rajesh Joshi (May 20 2024 at 11:00):
Wouldn't I then have to map 1 to both 0 and 1?
Vivek Rajesh Joshi (May 20 2024 at 11:06):
Never mind, I figured it out. Thanks for the help!
Mitchell Lee (May 20 2024 at 16:24):
The reindexing map is called docs#Finset.orderEmbOfFin
Mitchell Lee (May 20 2024 at 16:25):
I think that it would usually be better not to use Fin-indexed matrices, however.
Last updated: May 02 2025 at 03:31 UTC