Line | |
---|
1 | function x = ndsum(x,dim)
|
---|
2 | % NDSUM Multi-dimensional summation.
|
---|
3 | % NDSUM(X,DIM) sums out the dimensions in DIM, and squeezes the result.
|
---|
4 |
|
---|
5 | % Written by Tom Minka
|
---|
6 | % (c) Microsoft Corporation. All rights reserved.
|
---|
7 |
|
---|
8 | if 0
|
---|
9 | % permutation takes too long
|
---|
10 | x = permute_to_front(x,dim);
|
---|
11 | sz = size(x);
|
---|
12 | msz = sz(1:length(dim));
|
---|
13 | ksz = sz(length(dim)+1:end);
|
---|
14 | x = reshape(x,[prod(msz) ksz]);
|
---|
15 | x = sum(x);
|
---|
16 | x = mysqueeze(x);
|
---|
17 | else
|
---|
18 | sz = size(x);
|
---|
19 | for i=1:length(dim)
|
---|
20 | x = sum(x, dim(i));
|
---|
21 | end
|
---|
22 | addflops(prod(sz)-numel(x));
|
---|
23 | %x = mysqueeze(x);
|
---|
24 | sz(dim) = [];
|
---|
25 | x = reshape(x,[sz 1 1]);
|
---|
26 | end
|
---|
Note: See
TracBrowser
for help on using the repository browser.