Coverage Report

Created: 2026-03-22 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fluent-bit/lib/ripser-1.2.1/ripser_internal.hpp
Line
Count
Source
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*  ripser_internal.hpp a part of Fluent Bit
4
 *  ==========
5
 *  Copyright (C) 2025 The Fluent Bit Authors
6
 *
7
 *  Licensed under the Apache License, Version 2.0 (the "License");
8
 *  you may not use this file except in compliance with the License.
9
 *  You may obtain a copy of the License at
10
 *
11
 *      http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 *  Unless required by applicable law or agreed to in writing, software
14
 *  distributed under the License is distributed on an "AS IS" BASIS,
15
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 *  See the License for the specific language governing permissions and
17
 *  limitations under the License.
18
 */
19
20
#ifndef RIPSER_INTERNAL_HPP
21
#define RIPSER_INTERNAL_HPP
22
23
#include <cstdint>
24
#include <vector>
25
#include <utility>
26
#include <cmath>
27
#include <numeric>
28
#include <limits>
29
30
typedef float    value_t;
31
typedef int64_t  index_t;
32
typedef uint16_t coefficient_t;
33
34
enum compressed_matrix_layout { LOWER_TRIANGULAR, UPPER_TRIANGULAR };
35
36
template <compressed_matrix_layout Layout>
37
struct compressed_distance_matrix {
38
    std::vector<value_t> distances;
39
    std::vector<value_t*> rows;
40
41
    compressed_distance_matrix(std::vector<value_t>&& _distances)
42
0
        : distances(std::move(_distances)),
43
0
          rows((1 + std::sqrt(1 + 8 * distances.size())) / 2) {
44
0
        init_rows();
45
0
    }
46
47
    template <typename DistanceMatrix>
48
    compressed_distance_matrix(const DistanceMatrix& mat)
49
        : distances(mat.size() * (mat.size() - 1) / 2), rows(mat.size()) {
50
        init_rows();
51
        for (size_t i = 1; i < size(); ++i) {
52
            for (size_t j = 0; j < i; ++j) {
53
                rows[i][j] = mat(i, j);
54
            }
55
        }
56
    }
57
58
    value_t operator()(const index_t i, const index_t j) const;
59
0
    size_t size() const { return rows.size(); }
Unexecuted instantiation: compressed_distance_matrix<(compressed_matrix_layout)0>::size() const
Unexecuted instantiation: compressed_distance_matrix<(compressed_matrix_layout)1>::size() const
60
    void init_rows();
61
};
62
63
typedef compressed_distance_matrix<LOWER_TRIANGULAR> compressed_lower_distance_matrix;
64
typedef compressed_distance_matrix<UPPER_TRIANGULAR> compressed_upper_distance_matrix;
65
66
struct interval_recorder {
67
    using callback_t = void(*)(int dim, value_t birth, value_t death, void *user_data);
68
69
    callback_t cb        = nullptr;
70
    void      *user_data = nullptr;
71
72
0
    void emit(int dim, value_t birth, value_t death) const {
73
0
        if (cb) {
74
0
            cb(dim, birth, death, user_data);
75
0
        }
76
0
    }
77
};
78
79
template <typename DistanceMatrix>
80
class ripser;
81
82
void ripser_run_from_compressed_lower(
83
    compressed_lower_distance_matrix &&dist,
84
    index_t dim_max,
85
    value_t threshold,
86
    float ratio,
87
    interval_recorder recorder);
88
89
#endif /* RIPSER_INTERNAL_H */