Skip to content

Commit

Permalink
Minor bug fix
Browse files Browse the repository at this point in the history
Bug fixing:

#49 Simulation fails when running on GPU
  • Loading branch information
mathinking committed Jul 8, 2017
1 parent 5b4dcb6 commit b383641
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 6 additions & 1 deletion chn/+network/@HopfieldNetwork/invsatlin.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
function y = invsatlin(x,u0)
y = zeros(size(x));

if isa(x,'gpuArray')
y = zeros(size(x), 'gpuArray');
else
y = zeros(size(x));
end

y(x <= 0) = -u0;
y(x >= 1) = u0;
Expand Down
8 changes: 7 additions & 1 deletion chn/+network/@HopfieldNetwork/satlin.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
function y = satlin(x,u0)
y = zeros(size(x));

if isa(x,'gpuArray')
y = zeros(size(x), 'gpuArray');
else
y = zeros(size(x));
end
y(x>-u0 & x<u0) = 0.5 * (x(x>-u0 & x<u0)./u0 + 1);
y(x>=u0) = 1;

end
5 changes: 3 additions & 2 deletions chn/+network/@HopfieldNetworkTSP/sim.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
if ~isSaddle
V = incorporateResults(net,V,iter,timeID);
end


end

Expand Down Expand Up @@ -565,7 +566,7 @@
sumV = sum(sumVcol);

% $E(t + \Delta t) = E(t) - S_{1}\Delta t + \frac{1}{2}S_{2}\Delta t^{2}$
if strcmp(net.Setting.ExecutionEnvironment,'GPU')
if strcmp(net.Setting.ExecutionEnvironment,'gpu')
S1 = gather(S1);
S2 = gather(S2);
dt = gather(dt);
Expand All @@ -589,7 +590,7 @@
end
end

if strcmp(net.Setting.ExecutionEnvironment,'GPU') && nargout > 1
if strcmp(net.Setting.ExecutionEnvironment,'gpu') && nargout > 1
V = gather(V);
U = gather(U);
iter = gather(iter);
Expand Down

0 comments on commit b383641

Please sign in to comment.