1 //
2 // Copyright (c) 2018-2019, Cem Bassoy, [email protected]
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // The authors gratefully acknowledge the support of
9 // Fraunhofer IOSB, Ettlingen, Germany
10 //
11
12
13 #include <boost/numeric/ublas/tensor.hpp>
14 #include <boost/numeric/ublas/matrix.hpp>
15 #include <boost/numeric/ublas/vector.hpp>
16 #include <ostream>
17
main()18 int main()
19 {
20 using namespace boost::numeric::ublas;
21
22 using tensorf = tensor<float>;
23 using matrixf = matrix<float>;
24 using vectorf = vector<float>;
25
26 auto A = tensorf{3,4,2};
27 auto B = A = 2;
28
29 // Calling overloaded operators
30 // and using simple tensor expression templates.
31 if( A != (B+1) )
32 A += 2*B - 1;
33
34 // formatted output
35 std::cout << "% --------------------------- " << std::endl;
36 std::cout << "% --------------------------- " << std::endl << std::endl;
37 std::cout << "A=" << A << ";" << std::endl << std::endl;
38
39 auto n = shape{3,4};
40 auto D = matrixf(n[0],n[1],1);
41 auto e = vectorf(n[1],1);
42 auto f = vectorf(n[0],2);
43
44 // Calling constructor with
45 // vector expression templates
46 tensorf C = 2*f;
47 // formatted output
48 std::cout << "% --------------------------- " << std::endl;
49 std::cout << "% --------------------------- " << std::endl << std::endl;
50 std::cout << "C=" << C << ";" << std::endl << std::endl;
51
52
53 // Calling overloaded operators
54 // and mixing simple tensor and matrix expression templates
55 tensorf F = 3*C + 4*prod(2*D,e);
56
57 // formatted output
58 std::cout << "% --------------------------- " << std::endl;
59 std::cout << "% --------------------------- " << std::endl << std::endl;
60 std::cout << "F=" << F << ";" << std::endl << std::endl;
61
62
63 }
64