Skip to content

Commit 5e10b9e

Browse files
New function outerprod.
1 parent 11b172f commit 5e10b9e

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

ChangeLog

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2006-09-20 Gunnar Farneb�ck <[email protected]>
2+
3+
* make_tensors_fast.m: Replace tensorprod with outerprod.
4+
5+
* make_Abc_fast.m: Replace tensorprod with outerprod.
6+
7+
* outerprod.m: New file.
8+
19
2006-03-24 Gunnar Farneb�ck <[email protected]>
210

311
* arrayloop.m: Added pointer to neighborhoodloop.

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2.1
22

3+
- New function outerprod to compute outer products of arrays.
34
- New function neighborhoodloop which works like arrayloop but
45
generates neighborhoods around each point, which are passed to a
56
callback function.

make_Abc_fast.m

+2-3
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262

263263
case 3
264264
% Set up applicability and basis functions.
265-
applicability = tensorprod(a, shiftdim(a,-1), shiftdim(a,-2));
265+
applicability = outerprod(a, a, a);
266266
[x,y,t] = ndgrid(-n:n);
267267
b = cat(4, ones(size(x)), x, y, t, x.*x, y.*y, t.*t, x.*y, x.*t, y.*t);
268268
nb = size(b,4);
@@ -390,8 +390,7 @@
390390

391391
case 4
392392
% Set up applicability and basis functions.
393-
applicability = tensorprod(a, shiftdim(a,-1), shiftdim(a,-2), ...
394-
shiftdim(a,-3));
393+
applicability = outerprod(a, a, a, a);
395394
[x,y,z,t] = ndgrid(-n:n);
396395
b = cat(5, ones(size(x)), x, y, z, t, x.*x, y.*y, z.*z, t.*t, ...
397396
x.*y, x.*z, x.*t, y.*z, y.*t, z.*t);

make_tensors_fast.m

+2-3
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@
277277

278278
case 3
279279
% Set up applicability and basis functions.
280-
applicability = tensorprod(a, shiftdim(a,-1), shiftdim(a,-2));
280+
applicability = outerprod(a, a, a);
281281
[x,y,t] = ndgrid(-n:n);
282282
b = cat(4, ones(size(x)), x, y, t, x.*x, y.*y, t.*t, x.*y, x.*t, y.*t);
283283
nb = size(b, 4);
@@ -426,8 +426,7 @@
426426

427427
case 4
428428
% Set up applicability and basis functions.
429-
applicability = tensorprod(a, shiftdim(a, -1), shiftdim(a, -2),...
430-
shiftdim(a, -3));
429+
applicability = outerprod(a, a, a, a);
431430
[x,y,z,t] = ndgrid(-n:n);
432431
b = cat(5, ones(size(x)), x, y, z, t, x.*x, y.*y, z.*z, t.*t,...
433432
x.*y, x.*z, x.*t, y.*z, y.*t, z.*t);

outerprod.m

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function z = outerprod(x, y, varargin)
2+
% OUTERPROD - Multiply two or more arrays to form an outer product.
3+
% Singular dimensions are ignored and automatically squeezed.
4+
%
5+
% Author: Gunnar Farnebäck
6+
% Computer Vision Laboratory
7+
% Linköping University, Sweden
8+
9+
10+
dims = [size(x) size(y)];
11+
dims = dims(dims ~= 1);
12+
z = reshape(x(:) * y(:)', dims);
13+
14+
if length(varargin) > 0
15+
z = outerprod(z, varargin{:});
16+
end

0 commit comments

Comments
 (0)