Skip to content

Commit b383641

Browse files
committed
Minor bug fix
Bug fixing: #49 Simulation fails when running on GPU
1 parent 5b4dcb6 commit b383641

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

chn/+network/@HopfieldNetwork/invsatlin.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
function y = invsatlin(x,u0)
2-
y = zeros(size(x));
2+
3+
if isa(x,'gpuArray')
4+
y = zeros(size(x), 'gpuArray');
5+
else
6+
y = zeros(size(x));
7+
end
38

49
y(x <= 0) = -u0;
510
y(x >= 1) = u0;
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
function y = satlin(x,u0)
2-
y = zeros(size(x));
2+
3+
if isa(x,'gpuArray')
4+
y = zeros(size(x), 'gpuArray');
5+
else
6+
y = zeros(size(x));
7+
end
38
y(x>-u0 & x<u0) = 0.5 * (x(x>-u0 & x<u0)./u0 + 1);
49
y(x>=u0) = 1;
10+
511
end

chn/+network/@HopfieldNetworkTSP/sim.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
if ~isSaddle
8181
V = incorporateResults(net,V,iter,timeID);
8282
end
83+
8384

8485
end
8586

@@ -565,7 +566,7 @@
565566
sumV = sum(sumVcol);
566567

567568
% $E(t + \Delta t) = E(t) - S_{1}\Delta t + \frac{1}{2}S_{2}\Delta t^{2}$
568-
if strcmp(net.Setting.ExecutionEnvironment,'GPU')
569+
if strcmp(net.Setting.ExecutionEnvironment,'gpu')
569570
S1 = gather(S1);
570571
S2 = gather(S2);
571572
dt = gather(dt);
@@ -589,7 +590,7 @@
589590
end
590591
end
591592

592-
if strcmp(net.Setting.ExecutionEnvironment,'GPU') && nargout > 1
593+
if strcmp(net.Setting.ExecutionEnvironment,'gpu') && nargout > 1
593594
V = gather(V);
594595
U = gather(U);
595596
iter = gather(iter);

0 commit comments

Comments
 (0)