/* * Copyright (c) 2021, Alliance for Open Media. All rights reserved. * * This source code is subject to the terms of the BSD 2 Clause License and * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License * was not distributed with this source code in the LICENSE file, you can * obtain it at www.aomedia.org/license/software. If the Alliance for Open * Media Patent License 1.0 was not distributed with this source code in the * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/ #include"av1/common/av1_common_int.h" #include"av1/encoder/sparse_linear_solver.h" #include"config/aom_config.h" #include"aom_mem/aom_mem.h" #include"av1/common/alloccommon.h"
#if CONFIG_OPTICAL_FLOW_API /* * Input: * rows: array of row positions * cols: array of column positions * values: array of element values * num_elem: total number of elements in the matrix * num_rows: number of rows in the matrix * num_cols: number of columns in the matrix * * Output: * sm: pointer to the sparse matrix to be initialized * * Return: 0 - success * -1 - failed
*/ int av1_init_sparse_mtx(constint *rows, constint *cols, constdouble *values, int num_elem, int num_rows, int num_cols,
SPARSE_MTX *sm) {
sm->n_elem = num_elem;
sm->n_rows = num_rows;
sm->n_cols = num_cols; if (num_elem == 0) {
sm->row_pos = NULL;
sm->col_pos = NULL;
sm->value = NULL; return 0;
}
sm->row_pos = aom_calloc(num_elem, sizeof(*sm->row_pos));
sm->col_pos = aom_calloc(num_elem, sizeof(*sm->col_pos));
sm->value = aom_calloc(num_elem, sizeof(*sm->value));
/* * Combines two sparse matrices (allocating new space). * * Input: * sm1, sm2: matrices to be combined * row_offset1, row_offset2: row offset of each matrix in the new matrix * col_offset1, col_offset2: column offset of each matrix in the new matrix * new_n_rows, new_n_cols: number of rows and columns in the new matrix * * Output: * sm: the combined matrix * * Return: 0 - success * -1 - failed
*/ int av1_init_combine_sparse_mtx(const SPARSE_MTX *sm1, const SPARSE_MTX *sm2,
SPARSE_MTX *sm, int row_offset1, int col_offset1, int row_offset2, int col_offset2, int new_n_rows, int new_n_cols) {
sm->n_elem = sm1->n_elem + sm2->n_elem;
sm->n_cols = new_n_cols;
sm->n_rows = new_n_rows;
/* * Calculate matrix and vector multiplication: A*b * * Input: * sm: matrix A * srcv: the vector b to be multiplied to * dstl: the length of vectors * * Output: * dstv: pointer to the resulting vector
*/ void av1_mtx_vect_multi_right(const SPARSE_MTX *sm, constdouble *srcv, double *dstv, int dstl) {
memset(dstv, 0, sizeof(*dstv) * dstl); for (int i = 0; i < sm->n_elem; i++) {
dstv[sm->row_pos[i]] += srcv[sm->col_pos[i]] * sm->value[i];
}
} /* * Calculate matrix and vector multiplication: b*A * * Input: * sm: matrix A * srcv: the vector b to be multiplied to * dstl: the length of vectors * * Output: * dstv: pointer to the resulting vector
*/ void av1_mtx_vect_multi_left(const SPARSE_MTX *sm, constdouble *srcv, double *dstv, int dstl) {
memset(dstv, 0, sizeof(*dstv) * dstl); for (int i = 0; i < sm->n_elem; i++) {
dstv[sm->col_pos[i]] += srcv[sm->row_pos[i]] * sm->value[i];
}
}
/* * Calculate inner product of two vectors * * Input: * src1, scr2: the vectors to be multiplied * src1l: length of the vectors * * Output: * the inner product
*/ double av1_vect_vect_multi(constdouble *src1, int src1l, constdouble *src2) { double result = 0; for (int i = 0; i < src1l; i++) {
result += src1[i] * src2[i];
} return result;
}
/* * Multiply each element in the matrix sm with a constant c
*/ void av1_constant_multiply_sparse_matrix(SPARSE_MTX *sm, double c) { for (int i = 0; i < sm->n_elem; i++) {
sm->value[i] *= c;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.