1 //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc.
2
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #include <boost/qvm/vec_operations.hpp>
7 #include <boost/qvm/vec.hpp>
8 #include <boost/qvm/map_mat_vec.hpp>
9 #include "test_qvm_matrix.hpp"
10 #include "test_qvm_vector.hpp"
11 #include "gold.hpp"
12
13 namespace
14 {
15 template <int A,int B,bool LessThan=(A<B)>
16 struct
17 get_min
18 {
19 static int const value=B;
20 };
21
22 template <int A,int B>
23 struct
24 get_min<A,B,true>
25 {
26 static int const value=A;
27 };
28
29 template <int Rows,int Cols>
30 void
test()31 test()
32 {
33 using namespace boost::qvm;
34 int const D=get_min<Rows,Cols>::value;
35 test_qvm::matrix<M1,Rows,Cols> x(42,1);
36 test_qvm::vector<V1,D> y=diag(x);
37 for( int i=0; i!=D; ++i )
38 y.b[i]=x.a[i][i];
39 BOOST_QVM_TEST_EQ(y.a,y.b);
40 diag(x) *= 2;
41 for( int i=0; i!=D; ++i )
42 x.b[i][i] *= 2;
43 BOOST_QVM_TEST_EQ(x.a,x.b);
44 diag(x) + diag(x);
45 -diag(x);
46 }
47 }
48
49 int
main()50 main()
51 {
52 test<1,2>();
53 test<1,3>();
54 test<1,4>();
55 test<1,5>();
56 test<2,1>();
57 test<3,1>();
58 test<4,1>();
59 test<5,1>();
60 test<2,2>();
61 test<3,3>();
62 test<4,4>();
63 test<5,5>();
64 return boost::report_errors();
65 }
66