Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Problem with writelist and list of matrices
PostPosted: Sat Sep 12, 2009 8:55 am 

Joined: Wed Jul 15, 2009 3:38 pm
Posts: 10
I have a problem using the writelist function when I write a list of matrices to a file and want to recreate the list in memory by reading the file later on. Here is a simple example:

Code:
ring R = 0, (x,y,z), dp;
matrix A[3][3] = 0,1,0, -1,0,0, 0,0,1;      
matrix B[3][3] = 0,1,0,  0,0,1, 1,0,0;      
matrix C[3][3] = 0,1,0,  1,0,0, 0,0,1;
list L = A,B,C;
writelist("simple-write.txt", "simplist", L);


This creates the text file alright:
list simplist;
simplist[1]=matrix(
0,1,0,-1,0,0,0,0,1);
etc...

but when I try to read it and recreate simplist:

Code:
ring R = 0, (x,y,z), dp;
execute(read("simple-write.txt"));  // does not create the list simplist in memory


The error I get is:
Code:
? error occurred in Read-Oh.sing line 10: `0,1,0,-1,0,0,0,0,1);`
? wrong type declaration. type 'help matrix;'
? last reserved name was `matrix`
skipping text from `-` error at token `)`

According to the help files (D.2.4.9), this should create the object simplist. It works for other objects, but not for lists of matrices.
If someone can tell me what is going wrong, I shall be most grateful...

Ravi


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Problem with writelist and list of matrices
PostPosted: Tue Sep 15, 2009 12:55 pm 
The cast matrix is incomplete, dimensions nrows and ncols are missing.

To fix the problem for the datataypes matrix and intmat,
change the for-loop as follows

Code:
for( i=1;i<=size(L);i=i+1 )
   {
     if (typeof(L[i]) == "intmat")
     {
       write(fil,"   "+nam+"["+string(i)+"]="+
              "intmat(intvec("+string(L[i])+
          "),"+string(nrows(L[i]))+","+string(ncols(L[i]))+");");
     }
     if ( typeof(L[i])== "matrix")
     {
        write(fil,"   "+nam+"["+string(i)+"]="+
              "matrix(ideal("+string(L[i])+
          "),"+string(nrows(L[i]))+","+string(ncols(L[i]))+");");
     }
     else
     {
       write(fil,"   "+nam+"["+string(i)+"]="+typeof(L[i])+"(",string(L[i])+");");
     }
   }


(Note: Other datatypes as string also do not work properly.)


Report this post
Top
  
Reply with quote  
 Post subject: Re: Problem with writelist and list of matrices
PostPosted: Tue Sep 15, 2009 3:39 pm 

Joined: Wed Jul 15, 2009 3:38 pm
Posts: 10
Thank you. It works now. To avoid defining the list every time I read the file, I added a declaration before your for loop:

write(fil, "list " + nam + ";");

Thanks again.

Ravi :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

It is currently Fri May 13, 2022 11:06 am
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group