blob: f30fc0f5b17f633e55f83628eabe16032646426e [file] [log] [blame]
Bohan Li4276357b2020-11-02 08:33:08 -08001/*
2 * Copyright (c) 2021, Alliance for Open Media. All rights reserved
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
Wan-Teh Changb2c62d92021-03-31 15:10:51 -070012#ifndef AOM_AV1_ENCODER_SPARSE_LINEAR_SOLVER_H_
13#define AOM_AV1_ENCODER_SPARSE_LINEAR_SOLVER_H_
Bohan Li4276357b2020-11-02 08:33:08 -080014
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19#include "config/aom_config.h"
20
21#if CONFIG_OPTICAL_FLOW_API
22
23// Number of iterations for solving linear equations.
24#define MAX_CG_SP_ITER 100
25
26typedef struct {
27 int n_elem; // number of non-zero elements
28 int n_rows;
29 int n_cols;
30 // using arrays to represent non-zero elements.
31 int *col_pos;
32 int *row_pos; // starts with 0
33 double *value;
34} SPARSE_MTX;
35
Bohan Li4d1b3382021-04-12 10:35:37 -070036int av1_init_sparse_mtx(const int *rows, const int *cols, const double *values,
37 int num_elem, int num_rows, int num_cols,
38 SPARSE_MTX *sm);
39int av1_init_combine_sparse_mtx(const SPARSE_MTX *sm1, const SPARSE_MTX *sm2,
40 SPARSE_MTX *sm, int row_offset1,
41 int col_offset1, int row_offset2,
42 int col_offset2, int new_n_rows,
43 int new_n_cols);
Bohan Li4276357b2020-11-02 08:33:08 -080044void av1_free_sparse_mtx_elems(SPARSE_MTX *sm);
45
46void av1_mtx_vect_multi_right(const SPARSE_MTX *sm, const double *srcv,
47 double *dstv, int dstl);
48void av1_mtx_vect_multi_left(const SPARSE_MTX *sm, const double *srcv,
49 double *dstv, int dstl);
50double av1_vect_vect_multi(const double *src1, int src1l, const double *src2);
51void av1_constant_multiply_sparse_matrix(SPARSE_MTX *sm, double c);
52
Bohan Li4d1b3382021-04-12 10:35:37 -070053int av1_conjugate_gradient_sparse(const SPARSE_MTX *A, const double *b, int bl,
54 double *x);
55int av1_bi_conjugate_gradient_sparse(const SPARSE_MTX *A, const double *b,
56 int bl, double *x);
57int av1_jacobi_sparse(const SPARSE_MTX *A, const double *b, int bl, double *x);
58int av1_steepest_descent_sparse(const SPARSE_MTX *A, const double *b, int bl,
59 double *x);
Bohan Li4276357b2020-11-02 08:33:08 -080060
61#endif // CONFIG_OPTICAL_FLOW_API
62
63#ifdef __cplusplus
64} // extern "C"
65#endif
66
Wan-Teh Changb2c62d92021-03-31 15:10:51 -070067#endif /* AOM_AV1_ENCODER_SPARSE_LINEAR_SOLVER_H_ */