Debian Codegraph @

debian/tests/build3

raw
1 #!/bin/sh
2 # autopkgtest check: Build and run a program against libmedc
3 # (C) 2013 Thomas Moulard
4 # (C) 2014 Anton Gladky
5 # Author: Thomas Moulard <[email protected]>
6 # Anton Gladky <[email protected]>
7
8 set -e
9
10 WORKDIR=$(mktemp -d)
11 echo $WORKDIR
12 trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
13 cd $WORKDIR
14 mkdir src
15 cd src
16
17 cat <<EOF > CMakeLists.txt
18 cmake_minimum_required(VERSION 3.18)
19 project(demo)
20 find_package(ALGLIB REQUIRED)
21 include_directories(\${ALGLIB_INCLUDE_DIRS})
22
23 add_executable(demo demo.cpp)
24 target_link_libraries(demo \${ALGLIB_LIB})
25 install(TARGETS demo DESTINATION bin)
26
27 EOF
28
29 cat <<EOF > demo.cpp
30 #include "stdafx.h"
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <math.h>
34 #include "linalg.h"
35
36 using namespace alglib;
37
38
39 int main(int argc, char **argv)
40 {
41 //
42 // rmatrixsyrk() function allows us to calculate symmetric rank-K update
43 // C := beta*C + alpha*A'*A, where C is square N*N matrix, A is square K*N
44 // matrix, alpha and beta are scalars. It is also possible to update by
45 // adding A*A' instead of A'*A.
46 //
47 // Parameters of this function are:
48 // * N, K - matrix size
49 // * Alpha - coefficient before A
50 // * A, IA, JA - matrix and submatrix offsets
51 // * OpTypeA - multiplication type:
52 // * 0 - A*A^T is calculated
53 // * 2 - A^T*A is calculated
54 // * Beta - coefficient before C
55 // * C, IC, JC - preallocated input/output matrix and submatrix offsets
56 // * IsUpper - whether upper or lower triangle of C is updated;
57 // this function updates only one half of C, leaving
58 // other half unchanged (not referenced at all).
59 //
60 // Below we will show how to calculate simple product C:=A'*A
61 //
62 // NOTE: beta=0 and we do not use previous value of C, but still it
63 // MUST be preallocated.
64 //
65 ae_int_t n = 2;
66 ae_int_t k = 1;
67 double alpha = 1.0;
68 ae_int_t ia = 0;
69 ae_int_t ja = 0;
70 ae_int_t optypea = 2;
71 double beta = 0.0;
72 ae_int_t ic = 0;
73 ae_int_t jc = 0;
74 bool isupper = true;
75 real_2d_array a = "[[1,2]]";
76
77 // preallocate space to store result
78 real_2d_array c = "[[0,0],[0,0]]";
79
80 // calculate product, store result into upper part of c
81 rmatrixsyrk(n, k, alpha, a, ia, ja, optypea, beta, c, ic, jc, isupper);
82
83 // output result.
84 // IMPORTANT: lower triangle of C was NOT updated!
85 printf("%s\n", c.tostring(3).c_str()); // EXPECTED: [[1,2],[0,4]]
86 return 0;
87 }
88
89
90 EOF
91
92 cd ..
93 mkdir build
94 cd build
95 cmake -DCMAKE_INSTALL_PREFIX=./../inst ./../src
96 make
97 make install
98 echo "build: OK"
99 [ -x demo ]
100 ./demo
101 echo "run: OK"
102