[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: error: memory exhausted or requested size too large for range of Oct
From: |
andrewcd |
Subject: |
Re: 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 03:09:28 -0700 (PDT) |
Just to update my post: I've made a hack that partially loops the code, and
it works in about 10 seconds with my current matrix size. However, its
certainly inelegant, and probably not optimal. Any help you all could offer
would be very much appreciated.
Cheers
Andrew
function [output] = makedatematrix_loop(Tdays, baseyear, startyear,
endyear,startday,chunksize)
%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 (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.
%This code is a hack to partially loop the function when it makes octave
crash
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))];
ayear=cumsum(diy);
dim = [mheadvec repmat(dimvec,1,ceil(yearspan/4))];
amonth = cumsum(dim);
for k = 1:floor(length(Tdays)/chunksize)
b = floor(Tdays(k+((k-1)*chunksize):k*chunksize)*(ayear.^-1));
year(k+((k-1)*chunksize):k*chunksize) = sum((b>0),2)+startyear;
b = floor(Tdays(k+((k-1)*chunksize):k*chunksize)*(amonth.^-1));
m = sum((b>0),2);
month(k+((k-1)*chunksize):k*chunksize) = rem((sum((b>0),2)),12)+1;
k*chunksize;
end
leftover = rem(length(Tdays),chunksize);
already = length(Tdays)-leftover;
for k = 1:leftover
b = floor(Tdays(k+already)*(ayear.^-1));
year(k+already) = sum((b>0),2)+startyear;
b = floor(Tdays(k+already)*(amonth.^-1));
m = sum((b>0),2);
month(k+already) = rem(m,12)+1;
k+already;
end
month = month';
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-tp4630774p4630777.html
Sent from the Octave - General mailing list archive at Nabble.com.