Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double* my_solver(int N, double* A, double *B) {
- printf("NEOPT SOLVER\n");
- register int i, j, k = 0;
- register double* Apatrat = (double*)calloc(N *N, sizeof(double));
- //if(Apatrat == NULL) return NULL;
- register double* C = (double*)calloc(N *N, sizeof(double));
- // if(C == NULL) return NULL;
- //int dim = N * N;
- double* ap = Apatrat;
- double* a = A;
- double* au = A;
- int dim = N * N;
- register int t = 0;
- for (t = 0, i = 0; i < dim; i += N, ++t) {
- for (j = t; j < N; j++) {
- a = A + i + t;
- au = A + i + j;
- for (k = t; k <= j; k++) {
- *ap += (*a) * (*au);
- ++a;
- au += N;
- }
- ++ap;
- }
- ap += t + 1;
- }
- // calculez B x A
- double* c = C;
- double* b = B;
- for (i = 0; i < dim; i += N) {
- for (j = 0; j < N; j++) {
- b = B + i + j;
- a = A + j * N + j;
- for (k = j; k < N; k++) {
- *c += (*b) * (*a);
- ++b;
- ++a;
- }
- ++c;
- }
- }
- c = C;
- for (t = 0, i = 0; i < N; i++, t += N) {
- for (j = 0; j < N; j++) {
- ap = Apatrat + t + i;
- b = B + t + j;
- for (k = i; k < N; k++) {
- *c += (*ap) * (*b);
- ++ap;
- b += N;
- }
- ++c;
- }
- }
- return C;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement