help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

error: memory exhausted or requested size too large for range of Octave'


From: andrewcd
Subject: error: memory exhausted or requested size too large for range of Octave's index type -- trying to return to prompt
Date: Sun, 17 Jun 2012 00:36:34 -0700 (PDT)

Hi All,

I'm running Octave 3.2.3 (in QtOctave) in Ubuntu 10.04, 64 bit.  (This is
the latest version available for my distribution).

I wrote the little function below to take a vector of days since a baseyear
and make it into a Nx2 of years and months, and I am getting the message in
the title when I try to multiply a [10^7x1]*[1x17].  (It is a panel dataset
with about 20K observational units over about 600 periods).  However, when I
do the following:

a = rand(10^7,1);
b = rand(1,18);
tic; c = a*b; toc
Elapsed time is 129.727182 seconds.

...I don't get the same error message, though the process is clearly quite
slow.  Any tips on how to get around this error?  Speeding things up would
be a bonus.  

Tips much appreciated!
Thanks,
Andrew
************************************

function [output] = makedatematrix(Tdays, baseyear, startyear,
endyear,startday)

%This function takes a vector of days and converts it into  Nx2 matrix of
years and months.  It accounts for leap years.  Tdays is a vector of days
since a certain baseyear, startyear is the first year in the data, endyear
is the last year in the data, and startday is the first day of the first
year (from 1-366) in the dataset.  It'd be nice if this code could calculate
everything just from the baseyear, but for now we'll just live with it as it
is. 

Tdays = Tdays-min(Tdays)+startday;

daysinyear = [366 365 365 365];
daysinmonth = [31 28 31 30 31 30 31 31 30 31 30 31];
daysinmonth_ly = [31 29 31 30 31 30 31 31 30 31 30 31];
dimvec = [daysinmonth_ly daysinmonth daysinmonth daysinmonth];

if rem(startyear,4)==0
        headvec = [366 365 365 365];
        mheadvec = [daysinmonth_ly daysinmonth daysinmonth daysinmonth];
        else
                if rem(startyear,4)==1
                        headvec = [365 365 365];
                        mheadvec = [daysinmonth daysinmonth daysinmonth];
                        else
                                if rem(startyear,4)==2;
                                        headvec = [365 365];
                                        mheadvec = [daysinmonth daysinmonth];
                                        else
                                                if rem(startyear,4)==3;
                                                        headvec = [365];
                                                        mheadvec = 
[daysinmonth];
                                                        else
                                                                disp("Something 
is fucked up")
                                                                endif
                                                                endif
                                                                endif
        endif
yearspan = endyear-startyear;

diy = [headvec repmat(daysinyear,1,ceil(yearspan/4))];
a=cumsum(diy);

b = floor(Tdays*(a.^-1));

year = sum((b>0),2)+startyear;
%month

dim = [mheadvec repmat(dimvec,1,ceil(yearspan/4))];

a = cumsum(dim);

b = floor(Tdays*(a.^-1));

m = sum((b>0),2);

month = rem(m,12)+1;
output = [year month];

end


--
View this message in context: 
http://octave.1599824.n4.nabble.com/error-memory-exhausted-or-requested-size-too-large-for-range-of-Octave-s-index-type-trying-to-returnt-tp4630774.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]