blob: 17c57db375bba0d826615d5e38f034dfd43f0f63 [file] [log] [blame]
Ana Krulec434c22d2018-11-28 13:48:36 +01001/*
2 * Copyright 2018 The Android Open Source Project
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#pragma once
18
19#include <cinttypes>
20#include <numeric>
21#include <vector>
22
23namespace android {
24namespace scheduler {
25// This number is used to set the size of the arrays in scheduler that hold information
26// about layers.
27static constexpr size_t ARRAY_SIZE = 30;
28
29// Calculates the statistical mean (average) in the data structure (array, vector). The
30// function does not modify the contents of the array.
31template <typename T>
32auto calculate_mean(const T& v) {
33 using V = typename T::value_type;
34 V sum = std::accumulate(v.begin(), v.end(), 0);
35 return sum / static_cast<V>(v.size());
36}
37
38// Calculates the statistical median in the vector. Return 0 if the vector is empty. The
39// function modifies the vector contents.
40int64_t calculate_median(std::vector<int64_t>* v);
41
42// Calculates the statistical mode in the vector. Return 0 if the vector is empty.
43int64_t calculate_mode(const std::vector<int64_t>& v);
44
45} // namespace scheduler
46} // namespace android