def testCDerivative_beta(self): """Make sure the cython code returns the same values as python code.""" beta = 0.79 #Start with something small outputs, timeslots = self.generateRandomTestData(100) risk_groups = get_risk_groups(outputs, timeslots) #Now get a new set, that won't match this, so beta doesn't diverge outputs, rnd_timeslots = self.generateRandomTestData(100) risk_outputs = [None for i in xrange(len(timeslots))] beta_risk = [np.zeros(len(risk_groups[i])) for i in xrange(len(risk_groups))] part_func = np.zeros(len(timeslots)) weighted_avg = np.zeros(len(timeslots)) pyget_slope(beta, risk_outputs, beta_risk, part_func, weighted_avg, outputs, timeslots) beta_force = get_beta_force(beta, outputs, risk_groups, part_func, weighted_avg) for output_index in xrange(len(outputs)): cder = cderivative_beta(beta, part_func, weighted_avg, beta_force, output_index, outputs, timeslots, risk_groups) pyder = pyderivative_beta(beta, part_func, weighted_avg, beta_force, output_index, outputs, timeslots, risk_groups) #print(cder, pyder) assert(isinstance(pyder, cder.__class__)) assert(round(cder, 20) == round(pyder, 20)) assert(cder == pyder)