My guess is that the problem is that you are using the “in place” style operators for your update. That means:
W -= <... update formula ...>
As opposed to:
W = W - <... update formula ...>
The in place form only works if you first break the connection to the global variables that are the test inputs. Here’s a thread which goes into the details of why this is required.