annotate scripts/general/accumarray.m @ 10271:297996005012

1 more small fix in accumarray
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 08 Feb 2010 07:20:27 +0100
parents 217d36560dfa
children db613bccd992
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8820
diff changeset
1 ## Copyright (C) 2007, 2008, 2009 David Bateman
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2 ## Copyright (C) 2009 VZLU Prague
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
3 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6770
diff changeset
4 ## This file is part of Octave.
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
5 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6770
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6770
diff changeset
7 ## under the terms of the GNU General Public License as published by
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6770
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6770
diff changeset
9 ## your option) any later version.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6770
diff changeset
10 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6770
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6770
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6770
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6770
diff changeset
14 ## General Public License for more details.
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
15 ##
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6770
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6770
diff changeset
18 ## <http://www.gnu.org/licenses/>.
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
19
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
20 ## -*- texinfo -*-
9163
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
21 ## @deftypefn {Function File} {} accumarray (@var{subs}, @var{vals}, @var{sz}, @var{func}, @var{fillval}, @var{issparse})
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
22 ## @deftypefnx {Function File} {} accumarray (@var{csubs}, @var{vals}, @dots{})
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
23 ##
7186
800f1fd3ffb8 [project @ 2007-11-26 19:16:07 by jwe]
jwe
parents: 7016
diff changeset
24 ## Create an array by accumulating the elements of a vector into the
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8934
diff changeset
25 ## positions defined by their subscripts. The subscripts are defined by
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8934
diff changeset
26 ## the rows of the matrix @var{subs} and the values by @var{vals}. Each row
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
27 ## of @var{subs} corresponds to one of the values in @var{vals}.
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
28 ##
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
29 ## The size of the matrix will be determined by the subscripts themselves.
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8934
diff changeset
30 ## However, if @var{sz} is defined it determines the matrix size. The length
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
31 ## of @var{sz} must correspond to the number of columns in @var{subs}.
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
32 ##
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
33 ## The default action of @code{accumarray} is to sum the elements with the
9163
9cb0c21e97f7 Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
34 ## same subscripts. This behavior can be modified by defining the @var{func}
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8934
diff changeset
35 ## function. This should be a function or function handle that accepts a
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8934
diff changeset
36 ## column vector and returns a scalar. The result of the function should not
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
37 ## depend on the order of the subscripts.
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
38 ##
8325
b93ac0586e4b spelling corrections
Brian Gough<bjg@network-theory.co.uk>
parents: 7186
diff changeset
39 ## The elements of the returned array that have no subscripts associated with
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8934
diff changeset
40 ## them are set to zero. Defining @var{fillval} to some other value allows
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
41 ## these values to be defined.
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
42 ##
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8934
diff changeset
43 ## By default @code{accumarray} returns a full matrix. If @var{issparse} is
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
44 ## logically true, then a sparse matrix is returned instead.
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
45 ##
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
46 ## An example of the use of @code{accumarray} is:
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
47 ##
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
48 ## @example
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
49 ## @group
7186
800f1fd3ffb8 [project @ 2007-11-26 19:16:07 by jwe]
jwe
parents: 7016
diff changeset
50 ## accumarray ([1,1,1;2,1,2;2,3,2;2,1,2;2,3,2], 101:105)
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
51 ## @result{} ans(:,:,1) = [101, 0, 0; 0, 0, 0]
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
52 ## ans(:,:,2) = [0, 0, 0; 206, 0, 208]
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
53 ## @end group
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
54 ## @end example
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
55 ## @end deftypefn
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
56
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
57 function A = accumarray (subs, val, sz = [], func = [], fillval = [], isspar = [])
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
58
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
59 if (nargin < 2 || nargin > 6)
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
60 print_usage ();
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
61 endif
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
62
7186
800f1fd3ffb8 [project @ 2007-11-26 19:16:07 by jwe]
jwe
parents: 7016
diff changeset
63 if (iscell (subs))
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
64 subs = cellfun (@(x) x(:), subs, "UniformOutput", false);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
65 ndims = numel (subs);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
66 if (ndims == 1)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
67 subs = subs{1};
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
68 endif
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
69 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
70 ndims = columns (subs);
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
71 endif
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
72
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
73 if (isempty (fillval))
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
74 fillval = 0;
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
75 endif
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
76
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
77 if (isempty (isspar))
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
78 isspar = false;
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
79 endif
7186
800f1fd3ffb8 [project @ 2007-11-26 19:16:07 by jwe]
jwe
parents: 7016
diff changeset
80
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
81 if (isspar)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
82
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
83 ## Sparse case. Avoid linearizing the subscripts, because it could overflow.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
84
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
85 if (fillval != 0)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
86 error ("accumarray: fillval must be zero in the sparse case");
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
87 endif
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
88
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
89 ## Ensure subscripts are a two-column matrix.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
90 if (iscell (subs))
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
91 subs = [subs{:}];
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
92 endif
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
93
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
94 ## Validate dimensions.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
95 if (ndims == 1)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
96 subs(:,2) = 1;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
97 elseif (ndims != 2)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
98 error ("accumarray: in the sparse case, needs 1 or 2 subscripts");
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
99 endif
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
100
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
101 if (isnumeric (val) || islogical (val))
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
102 vals = double (val);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
103 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
104 error ("accumarray: in the sparse case, values must be numeric or logical");
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
105 endif
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
106
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
107 if (! (isempty (func) || func == @sum))
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
108
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
109 ## Reduce values. This is not needed if we're about to sum them, because
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
110 ## "sparse" can do that.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
111
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
112 ## Sort indices.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
113 [subs, idx] = sortrows (subs);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
114 n = rows (subs);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
115 ## Identify runs.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
116 jdx = find (any (diff (subs, 1, 1), 2));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
117 jdx = [jdx; n];
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
118
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
119 val = cellfun (func, mat2cell (val(:)(idx), diff ([0; jdx])));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
120 subs = subs(jdx, :);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
121 endif
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
122
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
123 ## Form the sparse matrix.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
124 if (isempty (sz))
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
125 A = sparse (subs(:,1), subs(:,2), val);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
126 elseif (length (sz) == 2)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
127 A = sparse (subs(:,1), subs(:,2), val, sz(1), sz(2));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
128 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
129 error ("accumarray: dimensions mismatch")
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
130 endif
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
131
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
132 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
133
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
134 ## Linearize subscripts.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
135 if (ndims > 1)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
136 if (isempty (sz))
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
137 if (iscell (subs))
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
138 sz = cellfun (@max, subs);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
139 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
140 sz = max (subs, [], 1);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
141 endif
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
142 elseif (ndims != length (sz))
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
143 error ("accumarray: dimensions mismatch")
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
144 endif
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
145
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
146 ## Convert multidimensional subscripts.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
147 if (ismatrix (subs))
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
148 subs = num2cell (subs, 1);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
149 endif
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
150 subs = sub2ind (sz, subs{:});
10271
297996005012 1 more small fix in accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10269
diff changeset
151 elseif (! isempty (sz) && length (sz) < 2)
10269
217d36560dfa small fixes to accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10268
diff changeset
152 error ("accumarray: needs at least 2 dimensions");
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
153 endif
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
154
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
155
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
156 ## Some built-in reductions handled efficiently.
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
157
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
158 if (isempty (func) || func == @sum)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
159 ## Fast summation.
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
160 if (isempty (sz))
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
161 A = __accumarray_sum__ (subs, val);
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
162 else
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
163 A = __accumarray_sum__ (subs, val, prod (sz));
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
164 ## set proper shape.
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
165 A = reshape (A, sz);
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
166 endif
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
167
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
168 ## we fill in nonzero fill value.
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
169 if (fillval != 0)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
170 mask = true (size (A));
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
171 mask(subs) = false;
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
172 A(mask) = fillval;
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
173 endif
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
174 elseif (func == @max)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
175 ## Fast maximization.
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
176
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
177 if (isinteger (val))
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
178 zero = intmin (class (val));
10269
217d36560dfa small fixes to accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10268
diff changeset
179 elseif (islogical (val))
217d36560dfa small fixes to accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10268
diff changeset
180 zero = false;
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
181 elseif (fillval == 0 && all (val(:) >= 0))
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
182 ## This is a common case - fillval is zero, all numbers nonegative.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
183 zero = 0;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
184 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
185 zero = NaN; # Neutral value.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
186 endif
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
187
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
188 if (isempty (sz))
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
189 A = __accumarray_max__ (subs, val, zero);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
190 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
191 A = __accumarray_max__ (subs, val, zero, prod (sz));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
192 A = reshape (A, sz);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
193 endif
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
194
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
195 if (fillval != zero && isnan (fillval) != isnan (zero))
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
196 mask = true (size (A));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
197 mask(subs) = false;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
198 A(mask) = fillval;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
199 endif
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
200 elseif (func == @min)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
201 ## Fast minimization.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
202
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
203 if (isinteger (val))
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
204 zero = intmax (class (val));
10269
217d36560dfa small fixes to accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10268
diff changeset
205 elseif (islogical (val))
217d36560dfa small fixes to accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10268
diff changeset
206 zero = true;
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
207 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
208 zero = NaN; # Neutral value.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
209 endif
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
210
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
211 if (isempty (sz))
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
212 A = __accumarray_min__ (subs, val, zero);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
213 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
214 A = __accumarray_min__ (subs, val, zero, prod (sz));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
215 A = reshape (A, sz);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
216 endif
8820
89b95972e178 fix previously introduced problem in octave_sort, improve design
Jaroslav Hajek <highegg@gmail.com>
parents: 8507
diff changeset
217
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
218 if (fillval != zero && isnan (fillval) != isnan (zero))
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
219 mask = true (size (A));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
220 mask(subs) = false;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
221 A(mask) = fillval;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
222 endif
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
223 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
224
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
225 ## The general case. Reduce values.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
226 n = rows (subs);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
227 if (numel (val) == 1)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
228 val = val(ones (1, n), 1);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
229 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
230 val = val(:);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
231 endif
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
232
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
233 ## Sort indices.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
234 [subs, idx] = sort (subs);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
235 ## Identify runs.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
236 jdx = find (diff (subs, 1, 1));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
237 jdx = [jdx; n];
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
238 val = mat2cell (val(idx), diff ([0; jdx]));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
239 ## Optimize the case when function is @(x) {x}, i.e. we just want to
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
240 ## collect the values to cells.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
241 persistent simple_cell_str = func2str (@(x) {x});
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
242 if (! strcmp (func2str (func), simple_cell_str))
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
243 val = cellfun (func, val);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
244 endif
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
245 subs = subs(jdx);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
246
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
247 ## Construct matrix of fillvals.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
248 if (iscell (val))
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
249 A = cell (sz);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
250 elseif (fillval == 0)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
251 A = zeros (sz, class (val));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
252 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
253 A = repmat (fillval, sz);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
254 endif
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
255
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
256 ## Set the reduced values.
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
257 A(subs) = val;
6770
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
258 endif
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
259 endif
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
260 endfunction
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
261
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
262 %!error (accumarray (1:5))
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
263 %!error (accumarray ([1,2,3],1:2))
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
264 %!assert (accumarray ([1;2;4;2;4],101:105), [101;206;0;208])
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
265 %!assert (accumarray ([1,1,1;2,1,2;2,3,2;2,1,2;2,3,2],101:105),cat(3, [101,0,0;0,0,0],[0,0,0;206,0,208]))
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
266 %!assert (accumarray ([1,1,1;2,1,2;2,3,2;2,1,2;2,3,2],101:105,[],@(x)sin(sum(x))),sin(cat(3, [101,0,0;0,0,0],[0,0,0;206,0,208])))
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
267 %!assert (accumarray ({[1 3 3 2 3 1 2 2 3 3 1 2],[3 4 2 1 4 3 4 2 2 4 3 4],[1 1 2 2 1 1 2 1 1 1 2 2]},101:112),cat(3,[0,0,207,0;0,108,0,0;0,109,0,317],[0,0,111,0;104,0,0,219;0,103,0,0]))
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
268 %!assert (accumarray ([1,1;2,1;2,3;2,1;2,3],101:105,[2,4],@max,NaN),[101,NaN,NaN,NaN;104,NaN,105,NaN])
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
269 %!assert (accumarray ([1 1; 2 1; 2 3; 2 1; 2 3],101:105,[2 4],@prod,0,true),sparse([1,2,2],[1,1,3],[101,10608,10815],2,4))
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
270 %!assert (accumarray ([1 1; 2 1; 2 3; 2 1; 2 3],1,[2,4]), [1,0,0,0;2,0,2,0])
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
271 %!assert (accumarray ([1 1; 2 1; 2 3; 2 1; 2 3],101:105,[2,4],@(x)length(x)>1),[false,false,false,false;true,false,true,false])
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
272 %!test
babcbcc11ab6 [project @ 2007-07-06 08:44:04 by dbateman]
dbateman
parents:
diff changeset
273 %! A = accumarray ([1 1; 2 1; 2 3; 2 1; 2 3],101:105,[2,4],@(x){x});
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
274 %! assert (A{2},[102;104])
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
275 %!test
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
276 %! subs = ceil (rand (2000, 3)*10);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
277 %! val = rand (2000, 1);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
278 %! assert (accumarray (subs, val, [], @max), accumarray (subs, val, [], @(x) max (x)));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
279 %!test
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
280 %! subs = ceil (rand (2000, 1)*100);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
281 %! val = rand (2000, 1);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
282 %! assert (accumarray (subs, val, [100, 1], @min, NaN), accumarray (subs, val, [100, 1], @(x) min (x), NaN));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
283 %!test
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
284 %! subs = ceil (rand (2000, 2)*30);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
285 %! subsc = num2cell (subs, 1);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
286 %! val = rand (2000, 1);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
287 %! assert (accumarray (subsc, val, [], [], 0, true), accumarray (subs, val, [], [], 0, true));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
288 %!test
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
289 %! subs = ceil (rand (2000, 3)*10);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
290 %! subsc = num2cell (subs, 1);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
291 %! val = rand (2000, 1);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
292 %! assert (accumarray (subsc, val, [], @max), accumarray (subs, val, [], @max));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
293
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 9859
diff changeset
294