From help-request at octave dot org Tue Apr 11 09:47:38 2006 Subject: Re: ERROR: memory exhausted -- trying to return prompt From: David Bateman To: =?ISO-8859-1?Q?Rosa_Rud=F3_Maun=E9?= Cc: help at octave dot org Date: Tue, 11 Apr 2006 16:42:51 +0200 Rosa Rudó Mauné wrote: > I'm using Octaver version 2.1.42-athlonatlas with Windows XP. Then here is your problem v2.1.42 uses the sparse code from octave-forge that doesn't have sparse concatenation. If you are deal with sparse matrices you are strongly recommended to use octave 2.9.x > In my file text, which is called "queries.mat.txt", I've got: > -first line (information): 6042 100247 894990 > The first integer is the number of rows in the matrix, the second > integer is the number of columns in the matrix and the third integer > is the total of non-zeros of the matrix. > -other lines. > The /(i+1)/ st line contains information about the non-zero > entries of the /i /th row of the matrix. > The non-zero entries of each row are specified as a > sparse-separated list of pairs. Each pair contains the column number > followed by the value of that paricular column. What do you mean by sparse seperated list? > For example: > queries.mat.txt could be: > 2 2 2 > 1 5 => > (1,1) = 5 > 2 4 => > (2,2) = 4 Then If I've understood correctly 4 4 2 2 5 3 2 while create a sparse matrix with (4,2) = 5 and (4,3) = 2... Note octave uses compressed column format for sparse matrices and not compressed row format as you have in this file structure, so if might be more efficient to treat as a compressed column form and do a transpose to get the right format. > > My aim is: > Saving the sparse matrix in a variable, because I'll need it, for > doing operations. > > My code is: > disp(fix(clock)); > fid=fopen('queries.mat.txt'); > tline=fgetl(fid); > capsalera=str2num(tline); > n=0; > while n <6042; > tline0 = fgetl(fid); > if tline0==-1 > break; > endif > tline=str2num(tline0); > n=n+1; > matriulinea=[ones(length(tline)/2, 1) > reshape(tline,2,length(tline)/2)']; > matriusparse=sparse(matriulinea(:,1), matriulinea(:,2), > matriulinea(:,3),1,100247); I think there is a problem with this line. You are saying your matrix has 1 row and 100247 columns. In fact given your file format why are you calling sparse in the while loop. I would have thought something like fid = fopen("queries.mat.txt"); tmp = sscanf(fgetl(fid),"%f"); nr = tmp(1); nc = tmp(2); nz = tmp(3); ra = []; ca = []; va = []; nv = 0; i = 0; while (!feof(fid)) i++; tmp = fgetl(fid,"%f") if (rem(length(tmp),2) != 0) error ("must have even number of elements in each row"); endif tmp = reshape(tmp,length(tmp)/2,2); nv = nv + size(tmp,1); ra = [ra; ones(size(tmp,1),1)*i]; ca = [ca; tmp(:,1)]; va = [va, tmp(:,2)]; if (nv >= nz) break; endif endwhile matriuindexos=sparse(ra,ca,va,nr,nc); fclose(fid); would have been more appropriate. Note the above code is untested. I suspect what is happening with your code is due to some range checking error in the ancient version of octave you are using as the code as you've written shouldn't work.. D. > if n==1 > matriuindexos=matriusparse; > else > matriuindexos=[matriuindexos; matriusparse]; > endif > endwhile > matriuindexos=sparse(matriuindexos); > fclose(fid); > disp(fix(clock)); > > > Rosa Rudó Mauné > > > > > On 4/11/06, *David Bateman* > wrote: > > Rosa Rudó Mauné wrote: > > > Hello, > > > > I want to create a sparse matrix from a file. The file has got > 100247 > > lines and 6042 columns. I read it line by line and I concatenate it, > > but when reaching line 73 the program stops and gives an error. The > > mistake is: > > > > ERROR: memory exhausted -- trying to return prompt > > > > Do you know how I can solve it? > > > > Rosa Rudó Mauné > > More information please... What version of octave? What is the > format of > the lines of code? What is the code you are using to read the file? > > D. > > -- > David > Bateman David dot Bateman at motorola dot com > > Motorola Labs - Paris +33 1 69 35 48 04 (Ph) > Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob) > 91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax) > > The information contained in this communication has been > classified as: > > [x] General Business Information > [ ] Motorola Internal Use Only > [ ] Motorola Confidential Proprietary > > -- David Bateman David dot Bateman at motorola dot com Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob) 91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax) The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------