def executeOperation(self, task, input): self.logger.info( " ------------------------------- SUM KERNEL: Operating on input '{0}', shape = {1}, origin = {2}" .format(input.name, input.shape, input.origin)) return npArray.createResult( task, input, input.array.sum(axis=self.getAxes(task.metadata), keepdims=True).filled(input.array.fill_value))
def executeOperations(self, task, inputs): available_inputIds = [inputId.split('-')[0] for inputId in inputs] data_inputIds = [inputId.split('-')[0] for inputId in task.inputs] wids = [inputId + "_WEIGHTS_" for inputId in data_inputIds] weight_inputIds = [(wid if (wid in available_inputIds) else None) for wid in wids] inputs_with_weights = zip(data_inputIds, weight_inputIds) self.logger.info("@@@@ data inputIds = " + str(data_inputIds) + ", weight_inputIds = " + str(weight_inputIds) + ", inputs = " + str(inputs)) results = [] try: for input_pair in inputs_with_weights: input = inputs.get(input_pair[0]) # npArray if (input is None): raise Exception("Can't find input " + input_pair[0] + " in numpyModule.WeightedAverageKernel") else: weights = inputs.get(input_pair[1]).array if not ( input_pair[1] is None) else None axes = self.getOrderedAxes(task, input) self.logger.info("\n Executing average, input: " + str(input_pair[0]) + ", shape = " + str(input.array.shape) + ", task metadata = " + str(task.metadata) + " Input metadata: " + str(input.metadata)) t0 = time.time() result = input.array for axis in axes: current_shape = list(result.shape) if (current_shape[axis] > 1): self.logger.info(" %ZP% Exec: axis: " + str(axis) + ", shape: " + str(current_shape)) wts = None if (weights == None) else np.broadcast_to( weights, current_shape) (result, weights) = ma.average(result, axis, wts, True) current_shape[axis] = 1 result = result.reshape(current_shape) weights = weights.reshape(current_shape) results.append( npArray.createResult( task, input, result.filled(input.array.fill_value))) t1 = time.time() self.logger.info( " ------------------------------- AVEW KERNEL: Operating on input '{0}', shape = {1}, origin = {2}, time = {3}" .format(input.name, input.shape, input.origin, t1 - t0)) except Exception as err: self.logger.error("Error in WeightedAverageKernel: " + err.message + "\n" + traceback.format_exc()) results.append(npArray.empty(task.rId)) return results
def executeOperations(self, task, inputs): kernel_inputs = [ inputs.get(inputId.split('-')[0]) for inputId in task.inputs ] if None in kernel_inputs: raise Exception( "ExecuteTask ERROR: required input {0} not available in task inputs: {1}" .format(task.inputs, inputs.keys())) results = [] axes = self.getAxes(task.metadata) self.logger.info( " ~~~~~~~~~~~~~~~~~~~~~~~~~~ Execute Operations, inputs: " + str(task.inputs) + ", task metadata = " + str(task.metadata) + ", axes = " + str(axes)) for input in kernel_inputs: t0 = time.time() if (input.array is None): raise Exception("Missing data for input " + input.name + " in Average Kernel") result_array = input.array.sum(axis=axes, keepdims=True) mask_array = input.array.count(axis=self.getAxes(task.metadata), keepdims=True) results.append( npArray.createResult( task, input, result_array.filled(input.array.fill_value))) results.append( npArray.createAuxResult(task.rId + "_WEIGHTS_", dict(input.metadata, **task.metadata), input, mask_array)) t1 = time.time() self.logger.info( " ------------------------------- SUMW KERNEL: Operating on input '{0}', shape = {1}, origin = {2}, result sample = {3}, undef = {4}, time = {5}" .format(input.name, input.shape, input.origin, result_array.flat[0:10], input.array.fill_value, t1 - t0)) return results
def executeOperation(self, task, input): return npArray.createResult( task, input, input.array.min(axis=self.getAxes(task.metadata), keepdims=True).filled(input.array.fill_value))
def reduce(self, input0, input1, task): return npArray.createResult( task, input0, np.maximum(input0.array, input1.array).filled(input0.array.fill_value))