File: bug_test.c

package info (click to toggle)
dynare 4.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 40,640 kB
  • sloc: fortran: 82,231; cpp: 72,734; ansic: 28,874; pascal: 13,241; sh: 4,300; objc: 3,281; yacc: 2,833; makefile: 1,288; lex: 1,162; python: 162; lisp: 54; xml: 8
file content (44 lines) | stat: -rwxr-xr-x 923 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

#include <math.h>
#include <stdlib.h>
#include <stdio.h>

#include "dw_std.h"

t main(void)
{
  int m=1; 
  int n=7;
  double X[7];
  double tau[1];
  
  int lwork, info;
  double *work, opt_size;
  
  int i;

  // Randomly generate 1x7 matrix X
  for (i=6; i >= 0; i--) X[i]=(double)rand()/RAND_MAX;

  // Make size inquiry
  lwork=-1;
  dgeqrf(&m,&n,X,&m,tau,&opt_size,&lwork,&info);

  // Attempt QR decomposition
  work=(double*)dw_malloc((lwork=(int)opt_size)*sizeof(double));
  dgeqrf(&m,&n,X,&m,tau,work,&lwork,&info);

  // Is problem?
  if (info)
    {
      printf("Unexpected error: info= %d  lwork= %d  m = %d  n = %d\n",info,lwork,m,n);

      // work around
      dw_free(work);
      work=(double*)dw_malloc((lwork=(m > n) ? m*m : n*n)*64*sizeof(double));
      dgeqrf(&m,&n,X,&m,tau,work,&lwork,&info);
      printf("info = %d  work[0]= %d\n",info,(int)work[0]);
    }
  else
    printf("Successful\n");
}