[docs]classReducer(IPhlowerCoreModule,torch.nn.Module):"""Reducer is a neural network module that performs a reduction operation on the input tensor. Parameters ---------- activation: str Name of the activation function to apply to the output. operator: str Name of the operator to apply to the input tensors. "add" or "mul". Default is "add". nodes: list[int] List of feature dimension sizes (The last value of tensor shape). Examples -------- >>> reducer = Reducer(activation="relu", operator="add", nodes=[10, 20, 30]) >>> reducer(data) """_REGISTERED_OPERATORS={"add":torch.add,"mul":torch.mul}
[docs]defforward(self,data:IPhlowerTensorCollections,*,field_data:ISimulationField|None=None,**kwards,)->PhlowerTensor:"""forward function which overloads torch.nn.Module Args: data: IPhlowerTensorCollections data which receives from predecessors field_data: ISimulationField | None Constant information through training or prediction Returns: PhlowerTensor: Tensor object """tensors=tuple(data.values())ans=tensors[0]ans=reduce(lambdax,y:self._operator(*_to_broadcastable_shape(x,y)),tensors,)returnself._activation_func(ans)