Mercurial > forge
changeset 12615:0039c65e5e44 octave-forge
fix bug when CatArray is indexed with (:)
author | abarth93 |
---|---|
date | Tue, 12 May 2015 20:26:49 +0000 |
parents | a6a3ef834353 |
children | a8291e04a040 |
files | extra/ncArray/inst/@CatArray/subsref.m extra/ncArray/inst/@ncArray/subsref.m extra/ncArray/inst/ncCatArray.m extra/ncArray/inst/test_ncarray.m |
diffstat | 4 files changed, 23 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/extra/ncArray/inst/@CatArray/subsref.m Tue May 12 19:11:25 2015 +0000 +++ b/extra/ncArray/inst/@CatArray/subsref.m Tue May 12 20:26:49 2015 +0000 @@ -2,17 +2,20 @@ % handle case with a single subscript % for example CA(234) - if strcmp(idx.type,'()') && length(idx.subs) == 1 % indices of elements in B ind = idx.subs{1}; - + + if strcmp(ind,':') + ind = [1:numel(self)]'; + end + % output array B = zeros(size(ind)); B(:) = NaN; if self.overlap - % transform index to subscript + % transform linear index ind to subscript subs subs = cell(1,self.nd); [subs{:}] = ind2sub(size(self),ind); @@ -26,22 +29,7 @@ for i=1:length(ind) idxe.subs = mat2cell(subs(i,:),1,ones(1,self.nd)); - %B(i) = subsref_canonical(self,idxe); - - [idx_global,idx_local,sz] = idx_global_local_(self,idxe); - tmp = zeros(sz); - tmp(:) = NaN; - - - for j=1:self.na - % get subset from j-th array - subset = subsref(self.arrays{j},idx_local{j}); - - % set subset in global array B - tmp = subsasgn(tmp,idx_global{j},subset); - end - B(i) = tmp; - + B(i) = subsref_canonical(self,idxe); end else % assume all arrays does not overlap
--- a/extra/ncArray/inst/@ncArray/subsref.m Tue May 12 19:11:25 2015 +0000 +++ b/extra/ncArray/inst/@ncArray/subsref.m Tue May 12 20:26:49 2015 +0000 @@ -33,7 +33,6 @@ j = sort(j); idx_c.type = '()'; idx_c.subs = idx(1).subs(j); - varargout{i} = subsref(self.coord(i).val,idx_c); end else
--- a/extra/ncArray/inst/ncCatArray.m Tue May 12 19:11:25 2015 +0000 +++ b/extra/ncArray/inst/ncCatArray.m Tue May 12 20:26:49 2015 +0000 @@ -127,8 +127,10 @@ for i=1:length(coord) %test if value is already defined, if yes do nothing - if ~isempty(coord(i).val) - continue + if isfield(coord(i),'val') + if ~isempty(coord(i).val) + continue + end end % the number of the dimension might be different @@ -143,13 +145,13 @@ coord(i).val = ncBaseArray(filenames{1},coord(i).name,'vinfo',vinfo); else % coordinates do also depend on the dimension over which we concatenate - i,coord(i).name,dimc,dims{dim} + %i,coord(i).name,dimc,dims{dim} coord(i).val = arr(dimc,filenames,coord(i).name,finfos); end - if dim > length(coord(i).dims) - coord(i).dims{dim} = catdimname; - end + %if dim > length(coord(i).dims) + % coord(i).dims{dim} = catdimname; + %end end data = ncArray(var,dims,coord);
--- a/extra/ncArray/inst/test_ncarray.m Tue May 12 19:11:25 2015 +0000 +++ b/extra/ncArray/inst/test_ncarray.m Tue May 12 20:26:49 2015 +0000 @@ -232,6 +232,7 @@ ncread(files{3},'SST')); + assert(isequaln(CA2(:,:,:),SST_ref)) assert(isequaln(CA2(:,:,1),SST_ref(:,:,1))) @@ -243,6 +244,13 @@ assert(isequaln(CA2(3:5:50,3:5:100,1:2:3),SST_ref(3:5:50,3:5:100,1:2:3))) assert(isequaln(CA2(3:5:50,3:5:end,1:2:3),SST_ref(3:5:50,3:5:end,1:2:3))) assert(isequaln(CA2(3:5:50,3:5:end,:),SST_ref(3:5:50,3:5:end,:))) + +% access with linear index +assert(isequaln(CA2(:),SST_ref(:))) +assert(isequaln(CA2(1:10),SST_ref(1:10))) +assert(isequaln(CA2(1:2:10),SST_ref(1:2:10))) + + ind = floor(numel(SST_ref) * rand(100,1))+1; assert(isequaln(CA2(ind),SST_ref(ind)))