def setExpression(self, vec): """Sets expression in self and all children. WARNING: Will overwrite existing array with new array passed in. Expects vec to be a floating-point Numeric array. """ #if it's the root or zero branch length, just set the vector if not self.Length: self.Array = vec.copy() else: self.Array = mutate_array(vec, self.Length) curr_children = self.Children curr_arrays = [self.Array] * len(curr_children) while len(curr_children): new_children = [] new_arrays = [] for c,a in zip(curr_children, curr_arrays): if not c.Length: c.Array = a.copy() else: c.Array = mutate_array(a, c.Length) new_children.extend(c.Children) new_arrays.extend([c.Array] * len(c.Children)) curr_children = new_children curr_arrays = new_arrays
def setExpression(self, vec): """Sets expression in self and all children. WARNING: Will overwrite existing array with new array passed in. Expects vec to be a floating-point Numeric array. """ #if it's the root or zero branch length, just set the vector if not self.Length: self.Array = vec.copy() else: self.Array = mutate_array(vec, self.Length) curr_children = self.Children curr_arrays = [self.Array] * len(curr_children) while len(curr_children): new_children = [] new_arrays = [] for c, a in zip(curr_children, curr_arrays): if not c.Length: c.Array = a.copy() else: c.Array = mutate_array(a, c.Length) new_children.extend(c.Children) new_arrays.extend([c.Array] * len(c.Children)) curr_children = new_children curr_arrays = new_arrays
def test_mutate_array(self): """mutate_array should return mutated copy""" a = arange(5) m = mutate_array(a, 1, 2) assert a is not m self.assertNotEqual(a, m) residuals = m - a assert min(residuals) > -6 assert max(residuals) < 6