cholmod_timing.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2009, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #include "cholmod.h"
37 #include <time.h>
38 #define CPUTIME ((double) (clock ( )) / CLOCKS_PER_SEC)
39 
40 int main (void)
41 {
42  cholmod_sparse *A ;
43  cholmod_dense *x, *b, *r ;
44  cholmod_factor *L ;
45  double one [2] = {1,0}, m1 [2] = {-1,0} ; /* basic scalars */
46  cholmod_common c ;
47  cholmod_start (&c) ; /* start CHOLMOD */
48  A = cholmod_read_sparse (stdin, &c) ; /* read in a matrix */
49  cholmod_print_sparse (A, "A", &c) ; /* print the matrix */
50  if (A == NULL || A->stype == 0) /* A must be symmetric */
51  {
52  cholmod_free_sparse (&A, &c) ;
53  cholmod_finish (&c) ;
54  return (0) ;
55  }
56  b = cholmod_ones (A->nrow, 1, A->xtype, &c) ; /* b = ones(n,1) */
57  double t0 = CPUTIME;
58  L = cholmod_analyze (A, &c) ; /* analyze */
59  cholmod_factorize (A, L, &c) ; /* factorize */
60  x = cholmod_solve (CHOLMOD_A, L, b, &c) ; /* solve Ax=b */
61  double t1 = CPUTIME;
62  printf("Time: %12.4f \n", t1-t0);
63  r = cholmod_copy_dense (b, &c) ; /* r = b */
64  cholmod_sdmult (A, 0, m1, one, x, r, &c) ; /* r = r-Ax */
65  printf ("norm(b-Ax) %8.1e\n",
66  cholmod_norm_dense (r, 0, &c)) ; /* print norm(r) */
67  cholmod_free_factor (&L, &c) ; /* free matrices */
68  cholmod_free_sparse (&A, &c) ;
69  cholmod_free_dense (&r, &c) ;
70  cholmod_free_dense (&x, &c) ;
71  cholmod_free_dense (&b, &c) ;
72  cholmod_finish (&c) ; /* finish CHOLMOD */
73  return (0) ;
74 }
int main(void)
#define CPUTIME


sparse_bundle_adjustment
Author(s):
autogenerated on Fri Apr 3 2020 03:30:53