From: <aba...@us...> - 2012-06-24 09:56:19
|
Revision: 10679 http://octave.svn.sourceforge.net/octave/?rev=10679&view=rev Author: abarth93 Date: 2012-06-24 09:56:12 +0000 (Sun, 24 Jun 2012) Log Message: ----------- Modified Paths: -------------- trunk/octave-forge/extra/ncArray/inst/@BaseArray/size.m trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/ncBaseArray.m trunk/octave-forge/extra/ncArray/inst/test_ncarray.m Added Paths: ----------- trunk/octave-forge/extra/ncArray/inst/@BaseArray/reduce.m trunk/octave-forge/extra/ncArray/inst/@BaseArray/sum.m Added: trunk/octave-forge/extra/ncArray/inst/@BaseArray/reduce.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@BaseArray/reduce.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@BaseArray/reduce.m 2012-06-24 09:56:12 UTC (rev 10679) @@ -0,0 +1,28 @@ +function s = reduce(self,funred,funelem,dim) + +sz = size(self); +if nargin == 3 + dim = find(sz ~= 1,1); + if isempty(dim) + dim = 1; + end +end + +idx.type = '()'; +nd = length(sz); +idx.subs = cell(1,nd); +for i=1:nd + idx.subs{i} = ':'; +end + +if size(self,dim) == 0 + s = []; +else + idx.subs{dim} = 1; + s = funelem(subsref(self,idx)); + + for i=2:size(self,dim) + idx.subs{dim} = i; + s = funred(s,funelem(subsref(self,idx))); + end +end Modified: trunk/octave-forge/extra/ncArray/inst/@BaseArray/size.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@BaseArray/size.m 2012-06-24 05:35:16 UTC (rev 10678) +++ trunk/octave-forge/extra/ncArray/inst/@BaseArray/size.m 2012-06-24 09:56:12 UTC (rev 10679) @@ -3,6 +3,10 @@ sz = self.sz; if nargin == 2 - sz = sz(dim); + if dim > length(sz) + sz = 1; + else + sz = sz(dim); + end end Added: trunk/octave-forge/extra/ncArray/inst/@BaseArray/sum.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@BaseArray/sum.m (rev 0) +++ trunk/octave-forge/extra/ncArray/inst/@BaseArray/sum.m 2012-06-24 09:56:12 UTC (rev 10679) @@ -0,0 +1,10 @@ +function s = sum(self,varargin) + +funred = @plus; +funelem = @(x) x; + +s = reduce(self,funred,funelem,varargin{:}); + +if isempty(s) + s = 0; +end Modified: trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/ncBaseArray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/ncBaseArray.m 2012-06-24 05:35:16 UTC (rev 10678) +++ trunk/octave-forge/extra/ncArray/inst/@ncBaseArray/ncBaseArray.m 2012-06-24 09:56:12 UTC (rev 10679) @@ -56,7 +56,7 @@ self.sz = self.vinfo.Size; self.dims = self.vinfo.Dimensions; -self.nd = length(self.dims); +self.nd = length(self.dims); % number of netcdf dimensions retval = class(self,'ncBaseArray',BaseArray(self.sz)); end Modified: trunk/octave-forge/extra/ncArray/inst/test_ncarray.m =================================================================== --- trunk/octave-forge/extra/ncArray/inst/test_ncarray.m 2012-06-24 05:35:16 UTC (rev 10678) +++ trunk/octave-forge/extra/ncArray/inst/test_ncarray.m 2012-06-24 09:56:12 UTC (rev 10679) @@ -1,4 +1,4 @@ -function test_ncarray() +%function test_ncarray() % test ncBaseArray, ncCatArray and ncArray varname = 'SST'; @@ -75,6 +75,27 @@ ind = floor(numel(SST_ref) * rand(100,1))+1; assert(isequalwithequalnans(SST(ind),SST_ref(ind))) +assert(isequalwithequalnans(SST_ref(1,:,:), SST(1,:,:))) + +% sum + +sumSST = sum(SST,1); +sumSSTref = sum(SST_ref,1); +assert(isequalwithequalnans(sumSST, sumSSTref)) + +sumSST = sum(SST,2); +sumSSTref = sum(SST_ref,2); +assert(isequalwithequalnans(sumSST, sumSSTref)) + +sumSST = sum(SST,3); +sumSSTref = sum(SST_ref,3); +assert(isequalwithequalnans(sumSST, sumSSTref)) + +sumSST = sum(SST); +sumSSTref = sum(SST_ref); +assert(isequalwithequalnans(sumSST, sumSSTref)) + + % writing r = round(randn(size(SST))); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |