progress - nelson

Contents:
1) Progress
2) Sparse Matrix representation in python
3) Issues with `#include <Rmath.h>`

1)Progress
---------------------
- I translated the bare essentials of the R code that preps the variables before calling `gamlr.c`.    
- Once we have a minimum working version I can add back in the `doxx` precalculation, etc.       
- The very top of gamlr.py mymics the example in `help(gamlr)`. This is for testing and I'll remove it when things work. 


```python
n = 1000
p = 3
#xvar = matrix(0.9, nrow=p,ncol=p)
xvar=numpy.ones(shape=(p,p))*.9
#diag(xvar) <- 1
numpy.fill_diagonal(xvar,1)

#x <- matrix(rnorm(p*n), nrow=n)%*%chol(xvar)
x = numpy.random.standard_normal(p*n)
x.shape = (n,p)
numpy.dot(x,numpy.linalg.cholesky(xvar))
#y <- 4 + 3*x[,1] + -1*x[,2] + rnorm(n)
y = 4+3*x[:,0]+-1*x[:,1]+numpy.random.standard_normal(n)
```

2) Sparse Matrix representation in python
--------------------------------------------------
gamlr.R uses `x=as(x,"dgCMatrix")`
and then in the c function calls `x@i, x@p` etc.

I coded up a quick SparseMatrix class in python that follows along the same conventions, where
`x@i` = `x.p`, etc. 

3) Issues with `#include <Rmath.h>`
--------------------------------------------

Created gamlr.py, which contains all R code (in comments) from gamlr.R and python equivalent.

Next step is to link a (complied) gamlr.c to this gamlr.py. 
Currently encountering errors with compiling gamlr.c

```bash
nauner@linux1:~/gamlr/Python$ gcc -o gamlr.o gamlr.c
gamlr.c:5:19: fatal error: Rmath.h: No such file or directory
```

Commenting out 
```c
//#include <Rmath.h>
```

produces
```bash
nauner@linux1:~/gamlr/Python$ gcc -o gamlr.o gamlr.c
gamlr.c: In function ‘dof’:
gamlr.c:86:16: warning: incompatible implicit declaration of built-in function ‘fabs’ [enabled by default]
gamlr.c: In function ‘Bmove’:
gamlr.c:136:8: warning: incompatible implicit declaration of built-in function ‘fabs’ [enabled by default]
gamlr.c: In function ‘docurve’:
gamlr.c:144:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
gamlr.c:144:3: note: use option -std=c99 or -std=gnu99 to compile your code
gamlr.c:149:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
gamlr.c: In function ‘cdsolve’:
gamlr.c:180:11: error: ‘INFINITY’ undeclared (first use in this function)
gamlr.c:180:11: note: each undeclared identifier is reported only once for each function it appears in
gamlr.c:200:19: warning: incompatible implicit declaration of built-in function ‘fabs’ [enabled by default]
gamlr.c:226:17: warning: incompatible implicit declaration of built-in function ‘fmax’ [enabled by default]
gamlr.c: In function ‘gamlr’:
gamlr.c:317:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
gamlr.c:318:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
gamlr.c:335:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
gamlr.c:336:28: error: ‘INFINITY’ undeclared (first use in this function)
gamlr.c:337:21: warning: incompatible implicit declaration of built-in function ‘sqrt’ [enabled by default]
gamlr.c:358:11: warning: incompatible implicit declaration of built-in function ‘log’ [enabled by default]
gamlr.c:367:7: error: ‘for’ loop initial declarations are only allowed in C99 mode
gamlr.c:375:7: error: ‘for’ loop initial declarations are only allowed in C99 mode
gamlr.c:408:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
gamlr.c:411:31: warning: incompatible implicit declaration of built-in function ‘fabs’ [enabled by default]
```