2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "VISQErrorApproximator.h"
22 using namespace mpqsolver::bisection;
24 void VISQErrorApproximator::init(const std::string &visq_data_path)
27 std::ifstream file(visq_data_path);
31 void VISQErrorApproximator::init(std::istream &visq_data)
34 Json::Value completeJsonData;
35 if (!reader.parse(visq_data, completeJsonData))
37 throw std::runtime_error("Invalid visq stream");
40 if (!completeJsonData.isMember("error"))
42 throw std::runtime_error("No 'error' section in visq stream");
45 auto layers = completeJsonData["error"][0];
46 auto names = layers.getMemberNames();
47 for (auto name : names)
49 auto value = layers[name].asFloat();
50 _layer_errors[name] = value;
54 float VISQErrorApproximator::approximate(const std::string &node_name) const
56 auto iter = _layer_errors.find(node_name);
57 if (iter == _layer_errors.end())