def _runGetPermanenceTrial(self, float_type): """ Check that getPermanence() returns values for a given float_type. These tests are sensitive to the data type. This because if you pass a numpy array of the type matching the C++ argument then PyBind11 does not convert the data, and the C++ code can modify the data in-place If you pass the wrong data type, then PyBind11 does a conversion so your C++ function only gets a converted copy of a numpy array, and any changes are lost after returning """ inputs = SDR(100).randomize(.05) active = SDR(100) sp = SP(inputs.dimensions, active.dimensions, stimulusThreshold=1) # Make sure that the perms start off zero. perms_in = np.zeros(sp.getNumInputs(), dtype=float_type) sp.setPermanence(0, perms_in) perms = np.zeros(sp.getNumInputs(), dtype=float_type) sp.getPermanence(0, perms) assert (perms.sum() == 0.0) for i in range(10): sp.compute(inputs, True, active) # There should be at least one perm none zero total = np.zeros(sp.getNumInputs(), dtype=float_type) for i in range(100): perms = np.zeros(sp.getNumInputs(), dtype=float_type) sp.getPermanence(i, perms) total = total + perms assert (total.sum() > 0.0)
def _runGetConnectedSynapses(self, float_type): """ Check that getConnectedSynapses() returns values. """ inputs = SDR(100).randomize(.05) active = SDR(100) sp = SP(inputs.dimensions, active.dimensions, stimulusThreshold=1) for i in range(10): sp.compute(inputs, True, active) # There should be at least one connected none zero total = np.zeros(sp.getNumInputs(), dtype=float_type) for i in range(100): connected = np.zeros(sp.getNumInputs(), dtype=float_type) sp.getPermanence(i, connected, sp.connections.connectedThreshold) total = total + connected assert (total.sum() > 0)