Hi again,

Mostly, this does the job :

def sparse_magma_matrix(mat):
    s= "SparseMatrix(" + str(mat.nrows()) + ", " + str(mat.ncols()) + ", ["
    entries= ", ".join([ "<"+str(i+1)+", " + str(j+1)+", 
"+str(mat[i,j])+">" for i,j in mat.dict() ])
    return s + entries + "])"

One should probably worry about the coefficient ring -- as such, it only 
works if Magma can guess what it is by itself.

For anyone reading this, concretely, i have then tried:

f= open("foo.m", "w")
f.write("M:= " + sparse_magma_matrix(mat) + ";")
f.close()

Then within Magma, I have created the polynomial ring -- which, it turned 
out, had to be the appropriate fraction field, otherwise the determinant 
function does not work -- so in my case :

R<a0, a1, a2, a3, a4, a5>:= FunctionField(GF(5), 6) ;

and then:

load "foo.m";

(don't forget the ; at the end!!!)

Then i tried 

Determinant(M);

and, amazingly, Magma gives an answer instantly. Absolutely incredible :-)










On Tuesday, February 26, 2019 at 6:21:44 PM UTC+1, John Cremona wrote:
>
>
>
> On Tue, 26 Feb 2019 at 17:01, Vincent Delecroix <20100.d...@gmail.com 
> <javascript:>> wrote:
>
>> I don't think this has ever been implemented in Sage. You
>> have to figure out how to create a sparse matrix in magma
>> and write Sage code to produce it. You can get inspiration
>> from the current code of _magma_init_
>>
>>      def _magma_init_(self):
>>          P = magma(self.parent())
>>          v = [x._magma_init_(magma) for x in self.list()]
>>          return '%s![%s]'%(P.name(), ','.join(v))
>>
>> Vincent
>>
>
> This would be a very useful addition (for some people).  Magma constructs 
> sparse matrices using SparseMatrix() with several interfaces including
>
> (m::RngIntElt, n::RngIntElt, Q::SeqEnum[Tup]) -> MtrxSprs
>
>         The m by n sparse matrix, whose entries are given by the tuples in 
> Q of the form <i, j, x> (specifying that x is at entry (i, j)).
>
> Example:
>
> > M:=SparseMatrix(3,3,[<1,1,1>,<2,2,1>,<3,3,1>]);
> > IdentitySparseMatrix(Integers(), 3) eq M;      
> true
>
>
>  
>
>>
>> Le 26/02/2019 à 17:55, Pierre Guillot a écrit :
>> > Thanks! I think to know where the issue is :
>> > 
>> > M= random_matrix(ZZ, 10, sparse= True, density= 0.1)
>> > M._magma_init_(magma)
>> > 
>> > 
>> '_sage_[11]![0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-14,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,8,0,0,0,0]'
>> > 
>> > 
>> > This does not look like a sparse matrix to me : it's been converted to a
>> > "dense" matrix before magma code was produced...
>> > 
>> > no wonder if my 50,000 x 50,000 matrix takes forever to load...
>> > 
>> > If anyone has an easy fix, it would be great. Otherwise, i'll have to 
>> learn
>> > the syntax for sparse matrices in magma, and figure out how magma reads
>> > from a file...
>> > 
>> > 
>> > 
>> > 
>> > 
>> > 
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "sage-support" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to sage-support...@googlegroups.com <javascript:>.
>> To post to this group, send email to sage-s...@googlegroups.com 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/sage-support.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to