Google OR-Tools
v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
vector_sum.h
Go to the documentation of this file.
1
// Copyright 2010-2025 Google LLC
2
// Licensed under the Apache License, Version 2.0 (the "License");
3
// you may not use this file except in compliance with the License.
4
// You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software
9
// distributed under the License is distributed on an "AS IS" BASIS,
10
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
// See the License for the specific language governing permissions and
12
// limitations under the License.
13
14
// Fast summation of arrays (vectors, spans) of numbers.
15
//
16
// Speed: up to 2x faster than Eigen for float arrays with ~100 elements or more
17
// (as of 2023-05).
18
// Precision: Better or comparable precision to std::accumulate<> on the same
19
// value type. That said, the precision is inferior to precise sum
20
// algorithm such as ::AccurateSum.
21
22
#ifndef ORTOOLS_UTIL_VECTOR_SUM_H_
23
#define ORTOOLS_UTIL_VECTOR_SUM_H_
24
25
#include "absl/types/span.h"
26
#include "
ortools/util/vector_sum_internal.h
"
27
28
namespace
operations_research
{
29
30
// Computes the sum of `values`, assuming that the first element of `values` is
31
// aligned to 16 bytes.
32
inline
float
AlignedVectorSum
(absl::Span<const float> values) {
33
return
internal::VectorSum
<4, 4,
/*assume_aligned_at_start=*/
true
>(values);
34
}
35
36
// Computes the sum of `values` without assuming anything.
37
inline
float
VectorSum
(absl::Span<const float> values) {
38
return
internal::VectorSum
<4, 4,
/*assume_aligned_at_start=*/
false
>(values);
39
}
40
41
}
// namespace operations_research
42
43
#endif
// ORTOOLS_UTIL_VECTOR_SUM_H_
operations_research::internal::VectorSum
Value VectorSum(absl::Span< const Value > values)
Definition
vector_sum_internal.h:138
operations_research
OR-Tools root namespace.
Definition
binary_indexed_tree.h:21
operations_research::VectorSum
float VectorSum(absl::Span< const float > values)
Definition
vector_sum.h:37
operations_research::AlignedVectorSum
float AlignedVectorSum(absl::Span< const float > values)
Definition
vector_sum.h:32
vector_sum_internal.h
ortools
util
vector_sum.h
Generated by
1.15.0