18#include "absl/log/check.h"
19#include "absl/types/span.h"
27template <
typename SparseColumnLike>
30 for (
const SparseColumn::Entry e :
column) {
31 sum +=
Square(e.coefficient());
46 for (
const SparseColumn::Entry e : v) {
78 const int end = data.size();
79 const int shifted_end =
end - 3;
84 for (; i < shifted_end; i += 4) {
85 sum1 += data[i] * data[i];
86 sum2 += data[i + 1] * data[i + 1];
87 sum3 += data[i + 2] * data[i + 2];
88 sum4 += data[i + 3] * data[i + 3];
92 sum += data[i] * data[i];
94 sum += data[i + 1] * data[i + 1];
96 sum += data[i + 2] * data[i + 2];
107 const int end = data.size();
108 const int shifted_end =
end - 3;
113 for (; i < shifted_end; i += 4) {
114 sum1 += data[i] * data[i];
115 sum2 += data[i + 1] * data[i + 1];
116 sum3 += data[i + 2] * data[i + 2];
117 sum4 += data[i + 3] * data[i + 3];
125 sum += data[i] * data[i];
128 sum += data[i + 1] * data[i + 1];
131 sum += data[i + 2] * data[i + 2];
154 infinity_norm = std::max(infinity_norm, fabs(v[
row]));
156 return infinity_norm;
159template <
typename SparseColumnLike>
162 for (
const SparseColumn::Entry e :
column) {
163 infinity_norm = std::max(infinity_norm, fabs(e.coefficient()));
165 return infinity_norm;
177 if (
row.empty())
return 0.0;
182 return static_cast<double>(sum) /
row.size().value();
188 if (fabs((*
row)[
col]) < threshold) {
205 RowIndex* row_index) {
207 for (
const SparseColumn::Entry e :
column) {
208 if (rows_to_consider[e.row()] && fabs(e.coefficient()) > infinity_norm) {
209 infinity_norm = fabs(e.coefficient());
210 *row_index = e.row();
213 return infinity_norm;
217 for (
const SparseColumn::Entry e :
column) {
218 if (e.coefficient() != 0.0) {
219 (*b)[e.row()] =
false;
225 for (
const SparseColumn::Entry e :
column) {
226 DCHECK_GE(radius[e.row()], 0.0);
227 if (fabs(e.coefficient()) > radius[e.row()])
return false;
void Add(const FpNumber &value)
Adds an FpNumber to the sum.
FpNumber Value() const
Gets the value of the sum.
double Density(const DenseRow &row)
void RemoveNearZeroEntries(Fractional threshold, DenseRow *row)
Fractional Square(Fractional f)
Fractional InfinityNormTemplate(const SparseColumnLike &column)
Fractional SquaredNormTemplate(const SparseColumnLike &column)
Fractional PreciseSquaredNorm(const SparseColumn &v)
Fractional RestrictedInfinityNorm(const ColumnView &column, const DenseBooleanColumn &rows_to_consider, RowIndex *row_index)
Fractional InfinityNorm(const DenseColumn &v)
Returns the maximum of the coefficients of 'v'.
void SetSupportToFalse(const ColumnView &column, DenseBooleanColumn *b)
Fractional SquaredNorm(const SparseColumn &v)
StrictITIVector< RowIndex, Fractional > DenseColumn
Column-vector types. Column-vector types are indexed by a row index.
bool IsDominated(const ColumnView &column, const DenseColumn &radius)
Returns true iff for all 'row' we have '|column[row]| <= radius[row]'.
Fractional SquaredNormAndResetToZero(absl::Span< Fractional > data)
In SWIG mode, we don't want anything besides these top-level includes.
std::optional< int64_t > end
StrictITIVector< Index, Fractional > values
bool ShouldUseDenseIteration(double ratio_for_using_dense_representation) const
std::vector< Index > non_zeros