@@ -95,68 +95,21 @@ void DenseMatrix<T>::left_multiply_transpose(const DenseMatrix<T> & A)
9595 if (this ->use_blas_lapack )
9696 this ->_multiply_blas (A, LEFT_MULTIPLY_TRANSPOSE);
9797 else
98- {
99- // Check to see if we are doing (A^T)*A
100- if (this == &A)
101- {
102- // libmesh_here();
103- DenseMatrix<T> B (*this );
104-
105- // Simple but inefficient way
106- // return this->left_multiply_transpose(B);
107-
108- // More efficient, but more code way
109- // If A is mxn, the result will be a square matrix of Size n x n.
110- const unsigned int n_rows = A.m ();
111- const unsigned int n_cols = A.n ();
112-
113- // resize() *this and also zero out all entries.
114- this ->resize (n_cols,n_cols);
115-
116- // Compute the lower-triangular part
117- for (unsigned int i=0 ; i<n_cols; ++i)
118- for (unsigned int j=0 ; j<=i; ++j)
119- for (unsigned int k=0 ; k<n_rows; ++k) // inner products are over n_rows
120- (*this )(i,j) += B (k,i)*B (k,j);
121-
122- // Copy lower-triangular part into upper-triangular part
123- for (unsigned int i=0 ; i<n_cols; ++i)
124- for (unsigned int j=i+1 ; j<n_cols; ++j)
125- (*this )(i,j) = (*this )(j,i);
126- }
98+ this ->_left_multiply_transpose (A);
99+ }
127100
128- else
129- {
130- DenseMatrix<T> B (*this );
131-
132- this ->resize (A.n (), B.n ());
133-
134- libmesh_assert_equal_to (A.m (), B.m ());
135- libmesh_assert_equal_to (this ->m (), A.n ());
136- libmesh_assert_equal_to (this ->n (), B.n ());
137-
138- const unsigned int m_s = A.n ();
139- const unsigned int p_s = A.m ();
140- const unsigned int n_s = this ->n ();
141-
142- // Do it this way because there is a
143- // decent chance (at least for constraint matrices)
144- // that A.transpose(i,k) = 0.
145- for (unsigned int i=0 ; i<m_s; i++)
146- for (unsigned int k=0 ; k<p_s; k++)
147- if (A.transpose (i,k) != 0 .)
148- for (unsigned int j=0 ; j<n_s; j++)
149- (*this )(i,j) += A.transpose (i,k)*B (k,j);
150- }
151- }
152101
102+ template <typename T>
103+ template <typename T2>
104+ void DenseMatrix<T>::left_multiply_transpose(const DenseMatrix<T2> & A)
105+ {
106+ this ->_left_multiply_transpose (A);
153107}
154108
155109
156-
157110template <typename T>
158111template <typename T2>
159- void DenseMatrix<T>::left_multiply_transpose (const DenseMatrix<T2> & A)
112+ void DenseMatrix<T>::_left_multiply_transpose (const DenseMatrix<T2> & A)
160113{
161114 // Check to see if we are doing (A^T)*A
162115 if (this == &A)
@@ -267,67 +220,23 @@ void DenseMatrix<T>::right_multiply_transpose (const DenseMatrix<T> & B)
267220 if (this ->use_blas_lapack )
268221 this ->_multiply_blas (B, RIGHT_MULTIPLY_TRANSPOSE);
269222 else
270- {
271- // Check to see if we are doing B*(B^T)
272- if (this == &B)
273- {
274- // libmesh_here();
275- DenseMatrix<T> A (*this );
276-
277- // Simple but inefficient way
278- // return this->right_multiply_transpose(A);
279-
280- // More efficient, more code
281- // If B is mxn, the result will be a square matrix of Size m x m.
282- const unsigned int n_rows = B.m ();
283- const unsigned int n_cols = B.n ();
284-
285- // resize() *this and also zero out all entries.
286- this ->resize (n_rows,n_rows);
287-
288- // Compute the lower-triangular part
289- for (unsigned int i=0 ; i<n_rows; ++i)
290- for (unsigned int j=0 ; j<=i; ++j)
291- for (unsigned int k=0 ; k<n_cols; ++k) // inner products are over n_cols
292- (*this )(i,j) += A (i,k)*A (j,k);
293-
294- // Copy lower-triangular part into upper-triangular part
295- for (unsigned int i=0 ; i<n_rows; ++i)
296- for (unsigned int j=i+1 ; j<n_rows; ++j)
297- (*this )(i,j) = (*this )(j,i);
298- }
299-
300- else
301- {
302- DenseMatrix<T> A (*this );
303-
304- this ->resize (A.m (), B.m ());
305-
306- libmesh_assert_equal_to (A.n (), B.n ());
307- libmesh_assert_equal_to (this ->m (), A.m ());
308- libmesh_assert_equal_to (this ->n (), B.m ());
309-
310- const unsigned int m_s = A.m ();
311- const unsigned int p_s = A.n ();
312- const unsigned int n_s = this ->n ();
313-
314- // Do it this way because there is a
315- // decent chance (at least for constraint matrices)
316- // that B.transpose(k,j) = 0.
317- for (unsigned int j=0 ; j<n_s; j++)
318- for (unsigned int k=0 ; k<p_s; k++)
319- if (B.transpose (k,j) != 0 .)
320- for (unsigned int i=0 ; i<m_s; i++)
321- (*this )(i,j) += A (i,k)*B.transpose (k,j);
322- }
323- }
223+ this ->_right_multiply_transpose (B);
324224}
325225
326226
327227
328228template <typename T>
329229template <typename T2>
330230void DenseMatrix<T>::right_multiply_transpose (const DenseMatrix<T2> & B)
231+ {
232+ this ->_right_multiply_transpose (B);
233+ }
234+
235+
236+
237+ template <typename T>
238+ template <typename T2>
239+ void DenseMatrix<T>::_right_multiply_transpose (const DenseMatrix<T2> & B)
331240{
332241 // Check to see if we are doing B*(B^T)
333242 if (this == &B)
0 commit comments