Polymetic  1.1
A c++ library for polynomial and matrix arithmetic, focused on applications in Kinematics.
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
Matrix_impl.ipp
Go to the documentation of this file.
1 // Copyright 2018 Dhruvesh Nikhilkumar Patel
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
18 #ifndef _MATRIX_IMPL_IPP
19 #define _MATRIX_IMPL_IPP
20 
21 #include "../include/Matrix.hpp"
24 template <typename EntryT>
26 {
27  if (M.size1() != M.size2()) {
28  throw std::invalid_argument("Matrix supplied to trace() is not square");
29  }
30  size_t n = M.size1();
31  EntryT t {0};
32  for (size_t i = 0; i < n ; ++i){
33  t+=M(i,i);
34  }
35  return t;
36 }
37 
38 #endif // _MATRIX_IMPL_H
39 
40 
41 
42 
43 template <typename MatrixT>
44 bool boost::numeric::ublas::isSquare(const MatrixT& M)
45 {
46  return (M.size1() == M.size2());
47 }
boost::numeric::ublas::matrix< EntryT > Matrix
Typedef for the main matrix class.
Definition: Matrix.hpp:24
EntryT trace(const Matrix< EntryT > &M)
Finds trace of a square matrix.
Definition: Matrix_impl.ipp:25
bool isSquare(const MatrixT &M)
Convinience function to check if a matrix is square or not.
Definition: Matrix_impl.ipp:44