1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "fcp/aggregation/core/tensor_aggregator.h" 18 19 #include <utility> 20 21 #include "fcp/aggregation/core/input_tensor_list.h" 22 #include "fcp/base/monitoring.h" 23 24 namespace fcp { 25 namespace aggregation { 26 Accumulate(InputTensorList tensors)27Status TensorAggregator::Accumulate(InputTensorList tensors) { 28 FCP_RETURN_IF_ERROR(CheckValid()); 29 30 // Delegate aggregation to the derived class. 31 return AggregateTensors(std::move(tensors)); 32 } 33 CanReport() const34bool TensorAggregator::CanReport() const { return CheckValid().ok(); } 35 Report()36StatusOr<OutputTensorList> TensorAggregator::Report() && { 37 FCP_RETURN_IF_ERROR(CheckValid()); 38 if (!CanReport()) { 39 return FCP_STATUS(FAILED_PRECONDITION) 40 << "TensorAggregator::Report: the report goal isn't met"; 41 } 42 return std::move(*this).TakeOutputs(); 43 } 44 45 } // namespace aggregation 46 } // namespace fcp 47