imate
C++/CUDA Reference
c_affine_matrix_function.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright 2021, Siavash Ameli <sameli@berkeley.edu>
3  * SPDX-License-Identifier: BSD-3-Clause
4  * SPDX-FileType: SOURCE
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the license found in the LICENSE.txt file in the root
8  * directory of this source tree.
9  */
10 
11 
12 // =======
13 // Headers
14 // =======
15 
17 #include <cassert> // assert
18 #include "../_c_basic_algebra/c_vector_operations.h" // cVectorOperations
19 
20 
21 // ===========
22 // constructor
23 // ===========
24 
27 
28 template <typename DataType>
30  const LongIndexType num_rows_,
31  const LongIndexType num_columns_):
32 
33  // Base class constructor
34  cLinearOperator<DataType>(num_rows_, num_columns_),
35 
36  B_is_identity(false)
37 {
38  // This class has one parameter that is t in A+tB
39  this->num_parameters = 1;
40 }
41 
42 
43 // ==========
44 // destructor
45 // ==========
46 
49 
50 template <typename DataType>
52 {
53 }
54 
55 
56 // ==============
57 // get eigenvalue
58 // ==============
59 
96 
97 template <typename DataType>
99  const DataType* known_parameters,
100  const DataType known_eigenvalue,
101  const DataType* inquiry_parameters) const
102 {
103  assert((this->eigenvalue_relation_known == 1) && \
104  "An eigenvalue relation is not known. This function should be "
105  "called only when the matrix B is a scalar multiple of the "
106  "identity matrix");
107 
108  // Shift the eigenvalue by the parameter
109  DataType inquiry_eigenvalue = \
110  known_eigenvalue - known_parameters[0] + inquiry_parameters[0];
111 
112  return inquiry_eigenvalue;
113 }
114 
115 
116 // =================
117 // add scaled vector
118 // =================
119 
134 
135 template <typename DataType>
137  const DataType* input_vector,
138  const LongIndexType vector_size,
139  const DataType scale,
140  DataType* output_vector) const
141 {
142  // Subtracting two vectors with minus scale sign, which is adding.
144  input_vector, vector_size, -scale, output_vector);
145 }
146 
147 
148 // ===============================
149 // Explicit template instantiation
150 // ===============================
151 
152 template class cAffineMatrixFunction<float>;
153 template class cAffineMatrixFunction<double>;
Base class for affine matrix functions of one parameter.
void _add_scaled_vector(const DataType *input_vector, const LongIndexType vector_size, const DataType scale, DataType *output_vector) const
Performs the operation , where is an input vector scaled by and it the output vector.
virtual ~cAffineMatrixFunction()
Virtual destructor.
cAffineMatrixFunction(const LongIndexType num_rows_, const LongIndexType num_columns_)
Constructor.
DataType get_eigenvalue(const DataType *known_parameters, const DataType known_eigenvalue, const DataType *inquiry_parameters) const
This function defines an analytic relationship between a given set of parameters and the correspondin...
Base class for linear operators. This class serves as interface for all derived classes.
IndexType num_parameters
static void subtract_scaled_vector(const DataType *input_vector, const LongIndexType vector_size, const DataType scale, DataType *output_vector)
Subtracts the scaled input vector from the output vector.
int LongIndexType
Definition: types.h:60