3

I want to do in place vector addition in cython, so I'm using scipy.linalg.cython_blas.daxpy .

My syntax is:

daxpy(&n_samples, &tmp, &Q[0, ii], &inc, &G[0], &inc)

But in scikit-learn code, I read

axpy(n_samples, -w[ii], &X_data[ii * n_samples], 1, R_data, 1)

where axpy has been defined as daxpy earlier.

Is the & mandatory for the first two variable (int and double respectively) ? Why is there no & for the two first arguments in sklearn code ?

P. Camilleri
  • 12,664
  • 7
  • 41
  • 76

1 Answers1

3

I think this is just the difference between BLAS and CBLAS.

BLAS (which scipy.linalg wraps for you) uses a FORTRAN interface, so most(/all?) arguments (include simple ones such as integers) are passed by pointers.

Scikit-learn looks to use CBLAS rather than the scipy.linalg wrappers. CBLAS appears to define an interface that is more natural for C (simple arguments passed by value).


Therefore, if you're using the scipy Cython wrappers, you look to be doing it correctly.

DavidW
  • 29,336
  • 6
  • 55
  • 86