On 2012-12-05, John Cremona <[email protected]> wrote:
> ------=_Part_659_23379607.1354727026909
> Content-Type: text/plain; charset=ISO-8859-1
>
>
>
> On Wednesday, December 5, 2012 5:00:00 PM UTC, Dima Pasechnik wrote:
>>
>> On 2012-12-05, John Cremona <[email protected] <javascript:>> wrote:
>> > ------=_Part_32_14834482.1354721238473
>> > Content-Type: text/plain; charset=ISO-8859-1
>> >
>> >
>> >
>> > On Wednesday, December 5, 2012 1:56:55 PM UTC, Jason Grout wrote:
>> >>
>> >> On 12/5/12 7:46 AM, John Cremona wrote:
>> >> > I don't know why this takes so long:
>> >> >
>> >> > I have a field F (a snumber field of high degree, 288 in fact) and
>> >> > want to create a 100x100 matrix over F from a list of 100 lists of
>> 100
>> >> > elements of F, while I will call "entries". If I do
>> >> >
>> >> > M = Matrix(entries)
>> >> >
>> >> > which certainly works fine with smaller examples, then I get tired of
>> >> > waiting (after 10 or 15 minutes) and cannot even interrupt with
>> >> > Ctrl-C. But if I do
>> >> >
>> >> > M = copy(MatrixSpace(F,100).zero_matrix())
>> >> > for i in range(100):
>> >> > for j in range(100):
>> >> > M[i,j] = entries[i,j]
>> >> >
>> >> > it works in a few seconds. So what is going wrong with the first
>> >> (simpler) way?
>> >>
>> >> If you just do Matrix(entries), it tries to guess the right base ring
>> >> (using the Sequence() command, IIRC). In the second example, you are
>> >> explicitly telling Sage the base ring. I wonder if that is what is
>> >> going on. To check, can you try doing:
>> >>
>> >> matrix(F, entries)
>> >>
>> >>
>> > That is slow too. Try
>> >
>> >
>> > Q1092.<z>=CyclotomicField(1092)
>> > entries = [[Q1092.zero_element() for i in range(100)] for j in
>> range(100)]
>> > M=Matrix(Q1092,entries)
>> >
>> > which takes a long time (*) and cannot be interrupted with Ctrl-C.
>>
>> from what Volker wrote, it can be gathered that
>> M=Matrix(Q1092,entries,sparse=True)
>> might work much faster.
without sparse=True during initialization
you are creating a *dense* representation of 0 of your field, for
each matrix entry, and this hurts...
I just tried the following (note that I relaced 0's by 1's, so I am not
creating an empty sparse matrix, but actually a fully dense sparse
matrix):
sage: Q1092.<z>=CyclotomicField(1092)
sage: entries = [[Q1092.one() for i in range(100)] for j in range(100)]
sage: timeit('M=Matrix(Q1092,entries,sparse=True)')
5 loops, best of 3: 572 ms per loop
So this is quite quick, isn't it?
>>
>
> But Dima, the actual matrix I want to create has almost no zero entries;
> the zero matrix example was just a simplification to illustrate the issue.
> Or you you actually mean that tagging the matrix as sparse would be worth
> trying even if it is not?
>
> John
>
>
>> Dima
>>
>>
>>
>
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
Visit this group at http://groups.google.com/group/sage-support?hl=en.