For transpose :

In  the example we can see permutations are provided as arrays for rows and 
cols.
The permutation is equivalent of taking transpose of matrix.
But we cant represent transpose as a permutation matrix.


>>> a = np.matrix([[1,2],[3,5]])
>>> # a * perm = a.T            
>>> # perm = a.I * a.T
>>> a.I*a.T
matrix([[-1., -5.],
        [ 1.,  4.]])
>>>

the output is not permutation matrix. 

On Tuesday, February 27, 2024 at 10:03:25 PM UTC+5:30 Dima Pasechnik wrote:

>
>
> On 27 February 2024 15:34:20 GMT, 'Animesh Shree' via sage-devel <
> sage-...@googlegroups.com> wrote:
> >I tried scipy which uses superLU. We get the result but there is little 
> bit 
> >of issue.
> >
> >
> >--For Dense--
> >The dense matrix factorization gives this output using permutation matrix
> >sage: a = Matrix(RDF, [[1, 0],[2, 1]], sparse=True)
> >sage: a
> >[1.0 0.0]
> >[2.0 1.0]
> >sage: p,l,u = a.dense_matrix().LU()
> >sage: p
> >[0.0 1.0]
> >[1.0 0.0]
> >sage: l
> >[1.0 0.0]
> >[0.5 1.0]
> >sage: u
> >[ 2.0 1.0]
> >[ 0.0 -0.5]
> >
>
> you'd probably want to convert the permutation matrix into a permutation.
>
>
> >--For Sparse--
> >But the scipy LU decomposition uses permutations which involves taking 
> >transpose, also the output permutations are represented as array.
>
> It is very normal to represent permutations as arrays.
> One can reconstruct the permutation matrix from such an array trivially 
> (IIRC, Sage even has a function for it)
>
> I am not sure what you mean by "taking transpose".
>
> >sage: p,l,u = a.LU(force=True)
> >sage: p
> >{'perm_r': [1, 0], 'perm_c': [1, 0]}
> >sage: l
> >[1.0 0.0]
> >[0.0 1.0]
> >sage: u
> >[1.0 2.0]
> >[0.0 1.0]
> >
> >
> >Shall I continue with this?
>
> sure, you are quite close to getting it all done it seems.
>
>
> >On Tuesday, February 6, 2024 at 11:29:07 PM UTC+5:30 Dima Pasechnik wrote:
> >
> >> Non-square case for LU is in fact easy. Note that if you have A=LU as
> >> a block matrix
> >> A11 A12
> >> A21 A22
> >>
> >> then its LU-factors L and U are
> >> L11 0 and U11 U12
> >> L21 L22 0 U22
> >>
> >> and A11=L11 U11, A12=L11 U12, A21=L21 U11, A22=L21 U12+L22 U22
> >>
> >> Assume that A11 is square and full rank (else one may apply
> >> permutations of rows and columns in the usual way). while A21=0 and
> >> A22=0. Then one can take L21=0, L22=U22=0, while A12=L11 U12
> >> implies U12=L11^-1 A12.
> >> That is, we can first compute LU-decomposition of a square matrix A11,
> >> and then compute U12 from it and A.
> >>
> >> Similarly, if instead A12=0 and A22=0, then we can take U12=0,
> >> L22=U22=0, and A21=L21 U11,
> >> i.e. L21=A21 U11^-1, and again we compute LU-decomposition of A11, and
> >> then L21=A21 U11^-1.
> >>
> >> ----------------
> >>
> >> Note that in some cases one cannot get LU, but instead must go for an
> >> PLU,with P a permutation matrix.
> >> For non-square matrices this seems a bit more complicated, but, well,
> >> still doable.
> >>
> >> HTH
> >> Dima
> >>
> >>
> >>
> >>
> >> On Mon, Feb 5, 2024 at 6:00 PM Nils Bruin <nbr...@sfu.ca> wrote:
> >> >
> >> > On Monday 5 February 2024 at 02:31:04 UTC-8 Dima Pasechnik wrote:
> >> >
> >> >
> >> > it is the matter of adding extra zero rows or columns to the matrix 
> you 
> >> want to decompose. This could be a quick fix.
> >> >
> >> > (in reference to computing LU decompositions of non-square matrices) 
> -- 
> >> in a numerical setting, adding extra zero rows/columns may not be such 
> an 
> >> attractive option: if previously you know you had a maximal rank 
> matrix, 
> >> you have now ruined it by the padding. It's worth checking the 
> >> documentation and literature if padding is appropriate/desirable for 
> the 
> >> target algorithm/implementation.
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google 
> >> Groups "sage-devel" group.
> >> > To unsubscribe from this group and stop receiving emails from it, 
> send 
> >> an email to sage-devel+...@googlegroups.com.
> >> > To view this discussion on the web visit 
> >> 
> https://groups.google.com/d/msgid/sage-devel/622a01e0-9197-40c5-beda-92729c4e4a32n%40googlegroups.com
> >> .
> >>
> >
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/ff4bb798-5634-4d9b-84e9-4f1a132f3e10n%40googlegroups.com.

Reply via email to