Files
matlab/RBM/UFLDL/rica/bsxfunwrap.m
T
jens 7b34529b24 imported RBM
git-svn-id: http://moon:8086/svn/matlab/trunk@91 801c6759-fa7c-4059-a304-17956f83a07c
2016-07-12 11:24:12 +00:00

28 lines
1.0 KiB
Matlab

function c = bsxfunwrap(func, a, b)
global usegpu;
if usegpu
if size(a,1) > 1 && size(b,1) == 1
assert(size(a,2) == size(b,2), 'bsxfunwrap singleton dimensions dont agree');
c = func(a, repmat(b, size(a,1), 1));
elseif size(a,2) > 1 && size(b,2) == 1
assert(size(a,1) == size(b,1), 'bsxfunwrap singleton dimensions dont agree');
c = func(a, repmat(b, 1, size(a,2)));
elseif size(b,1) > 1 && size(a,1) == 1
assert(size(b,2) == size(a,2), 'bsxfunwrap singleton dimensions dont agree');
c = func(repmat(a, size(b, 1), 1), b);
elseif size(b,2) > 1 && size(a,2) == 1
assert(size(b,1) == size(a,1), 'bsxfunwrap singleton dimensions dont agree');
c = func(repmat(a, 1, size(b, 2)), b);
else
assert(size(a,1) == size(b,1), 'no bsxfun to do, bsxfunwrap dimensions dont agree');
assert(size(a,2) == size(b,2), 'no bsxfun to do, bsxfunwrap dimensions dont agree');
c = func(a, b);
end
else
c = bsxfun(func, a, b);
end
end