~ubuntu-branches/ubuntu/lucid/igraph/lucid

« back to all changes in this revision

Viewing changes to src/lapack/dlarnv.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Malaterre
  • Date: 2009-11-16 18:12:42 UTC
  • Revision ID: james.westby@ubuntu.com-20091116181242-mzv9p5fz9uj57xd1
Tags: upstream-0.5.3
ImportĀ upstreamĀ versionĀ 0.5.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  -- translated by f2c (version 20050501).
 
2
   You must link the resulting object file with libf2c:
 
3
        on Microsoft Windows system, link with libf2c.lib;
 
4
        on Linux or Unix systems, link with .../path/to/libf2c.a -lm
 
5
        or, if you install libf2c.a in a standard place, with -lf2c -lm
 
6
        -- in that order, at the end of the command line, as in
 
7
                cc *.o -lf2c -lm
 
8
        Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
 
9
 
 
10
                http://www.netlib.org/f2c/libf2c.zip
 
11
*/
 
12
 
 
13
#include "config.h"
 
14
#include "arpack_internal.h"
 
15
#include "f2c.h"
 
16
 
 
17
/* Subroutine */ int igraphdlarnv_(integer *idist, integer *iseed, integer *n, 
 
18
        doublereal *x)
 
19
{
 
20
    /* System generated locals */
 
21
    integer i__1, i__2, i__3;
 
22
 
 
23
    /* Builtin functions */
 
24
    double log(doublereal), sqrt(doublereal), cos(doublereal);
 
25
 
 
26
    /* Local variables */
 
27
    static integer i__;
 
28
    static doublereal u[128];
 
29
    static integer il, iv, il2;
 
30
    extern /* Subroutine */ int igraphdlaruv_(integer *, integer *, doublereal *);
 
31
 
 
32
 
 
33
/*  -- LAPACK auxiliary routine (version 3.0) -- */
 
34
/*     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */
 
35
/*     Courant Institute, Argonne National Lab, and Rice University */
 
36
/*     September 30, 1994 */
 
37
 
 
38
/*     .. Scalar Arguments .. */
 
39
/*     .. */
 
40
/*     .. Array Arguments .. */
 
41
/*     .. */
 
42
 
 
43
/*  Purpose */
 
44
/*  ======= */
 
45
 
 
46
/*  DLARNV returns a vector of n random real numbers from a uniform or */
 
47
/*  normal distribution. */
 
48
 
 
49
/*  Arguments */
 
50
/*  ========= */
 
51
 
 
52
/*  IDIST   (input) INTEGER */
 
53
/*          Specifies the distribution of the random numbers: */
 
54
/*          = 1:  uniform (0,1) */
 
55
/*          = 2:  uniform (-1,1) */
 
56
/*          = 3:  normal (0,1) */
 
57
 
 
58
/*  ISEED   (input/output) INTEGER array, dimension (4) */
 
59
/*          On entry, the seed of the random number generator; the array */
 
60
/*          elements must be between 0 and 4095, and ISEED(4) must be */
 
61
/*          odd. */
 
62
/*          On exit, the seed is updated. */
 
63
 
 
64
/*  N       (input) INTEGER */
 
65
/*          The number of random numbers to be generated. */
 
66
 
 
67
/*  X       (output) DOUBLE PRECISION array, dimension (N) */
 
68
/*          The generated random numbers. */
 
69
 
 
70
/*  Further Details */
 
71
/*  =============== */
 
72
 
 
73
/*  This routine calls the auxiliary routine DLARUV to generate random */
 
74
/*  real numbers from a uniform (0,1) distribution, in batches of up to */
 
75
/*  128 using vectorisable code. The Box-Muller method is used to */
 
76
/*  transform numbers from a uniform to a normal distribution. */
 
77
 
 
78
/*  ===================================================================== */
 
79
 
 
80
/*     .. Parameters .. */
 
81
/*     .. */
 
82
/*     .. Local Scalars .. */
 
83
/*     .. */
 
84
/*     .. Local Arrays .. */
 
85
/*     .. */
 
86
/*     .. Intrinsic Functions .. */
 
87
/*     .. */
 
88
/*     .. External Subroutines .. */
 
89
/*     .. */
 
90
/*     .. Executable Statements .. */
 
91
 
 
92
    /* Parameter adjustments */
 
93
    --x;
 
94
    --iseed;
 
95
 
 
96
    /* Function Body */
 
97
    i__1 = *n;
 
98
    for (iv = 1; iv <= i__1; iv += 64) {
 
99
/* Computing MIN */
 
100
        i__2 = 64, i__3 = *n - iv + 1;
 
101
        il = min(i__2,i__3);
 
102
        if (*idist == 3) {
 
103
            il2 = il << 1;
 
104
        } else {
 
105
            il2 = il;
 
106
        }
 
107
 
 
108
/*        Call DLARUV to generate IL2 numbers from a uniform (0,1) */
 
109
/*        distribution (IL2 <= LV) */
 
110
 
 
111
        igraphdlaruv_(&iseed[1], &il2, u);
 
112
 
 
113
        if (*idist == 1) {
 
114
 
 
115
/*           Copy generated numbers */
 
116
 
 
117
            i__2 = il;
 
118
            for (i__ = 1; i__ <= i__2; ++i__) {
 
119
                x[iv + i__ - 1] = u[i__ - 1];
 
120
/* L10: */
 
121
            }
 
122
        } else if (*idist == 2) {
 
123
 
 
124
/*           Convert generated numbers to uniform (-1,1) distribution */
 
125
 
 
126
            i__2 = il;
 
127
            for (i__ = 1; i__ <= i__2; ++i__) {
 
128
                x[iv + i__ - 1] = u[i__ - 1] * 2. - 1.;
 
129
/* L20: */
 
130
            }
 
131
        } else if (*idist == 3) {
 
132
 
 
133
/*           Convert generated numbers to normal (0,1) distribution */
 
134
 
 
135
            i__2 = il;
 
136
            for (i__ = 1; i__ <= i__2; ++i__) {
 
137
                x[iv + i__ - 1] = sqrt(log(u[(i__ << 1) - 2]) * -2.) * cos(u[(
 
138
                        i__ << 1) - 1] * 6.2831853071795864769252867663);
 
139
/* L30: */
 
140
            }
 
141
        }
 
142
/* L40: */
 
143
    }
 
144
    return 0;
 
145
 
 
146
/*     End of DLARNV */
 
147
 
 
148
} /* igraphdlarnv_ */
 
149