File: _logit.c.src

package info (click to toggle)
python-scipy 0.14.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 52,228 kB
  • ctags: 63,719
  • sloc: python: 112,726; fortran: 88,685; cpp: 86,979; ansic: 85,860; makefile: 530; sh: 236
file content (40 lines) | stat: -rw-r--r-- 571 bytes parent folder | download
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
/*-*-c-*-*/

/*
 * ufuncs to compute logit(p) = log(p/(1-p)) and
 * expit(x) = 1/(1+exp(-x))
 */

#include <Python.h>
#include <math.h>

#include "numpy/npy_math.h"
#include "_logit.h"

/*
 * Inner loops for logit and expit
 */

/**begin repeat
 * #type = npy_float, npy_double, npy_longdouble#
 * #c = f,,l#
 */

@type@ logit@c@(@type@ x)
{
    x /= 1 - x;
    return npy_log@c@(x);
}

@type@ expit@c@(@type@ x)
{
    if (x < 0) {
        x = npy_exp@c@(x);
        return x / (1 + x);
    }
    else {
        return 1 / (1 + npy_exp@c@(-x));
    }
}

/**end repeat**/