LinAlgebra.c 969 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "types.h"
  2. #include <math.h>
  3. pyReal vecScalarProduct(const pyWord size, const pyReal * a, const pyReal * b) {
  4. pyWord i;
  5. pyReal s = 0.0;
  6. for(i = 0; i < size ; i ++) {
  7. s += a[i] * b[i];
  8. }
  9. return s;
  10. }
  11. pyReal vecNorm(const pyWord size, const pyReal * a) {
  12. pyWord i;
  13. pyReal s = 0.0;
  14. for(i = 0; i < size ; i ++) {
  15. s += a[i] * a[i];
  16. }
  17. return sqrt(s);
  18. }
  19. pyReal vecDistSquared(const pyWord size, const pyReal * a, const pyReal * b) {
  20. pyWord i;
  21. pyReal s = 0.0, d;
  22. for(i = 0; i < size ; i ++) {
  23. d = a[i] - b[i]
  24. s += d * d;
  25. }
  26. return s;
  27. }
  28. void vecSubst(const pyWord size, pyReal * dst, const pyReal * a, const pyReal * b ) {
  29. pyWord i;
  30. for(i = 0; i < size ; i ++) {
  31. dst[i] = a[i] - b[i];
  32. }
  33. }
  34. void vecScale(const pyWord size, pyReal * dst, pyReal s, const pyReal * a) {
  35. pyWord i;
  36. for(i = 0; i < size ; i ++) {
  37. dst[i] = s * a[i];
  38. }
  39. }