-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
88 lines (69 loc) · 2.38 KB
/
main.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* This file test the implementation of the algorithm in [1].
*
* References :
* [1] - Randomized Extended Kaczmarz for Solving Least-Squares. Anastasios Zouzias and Nikolaos Freris (http://arxiv.org/abs/1205.5770)
*
*
* Author : Anastasios Zouzias
* Affiliation : University of Toronto
* Email : zouzias@cs.toronto.edu
* Website : http://www.cs.toronto.edu/~zouzias/
* Copyright (C) 2012, Anastasios Zouzias
*
* September 2012; Last revision: 15-November-2014
*/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <stddef.h>
#include "algorithms/REK/REKBLAS.h"
#include "matrix/sparseMatrix.h"
#include "matrix/matrix.h"
#include "utils/utils.h"
int main() {
// Dimensions of matrix A (m x n).
int m = 5000, n = 500;
// Maximum number of iterations
double TOL = 10e-8;
// Sparsity parameter
double sparsity = 0.25;
/* initialize random seed */
srand(time(NULL));
// Allocating space for unknown vector x, right size vector b, and solution vector xls, for Ax = b
double *xls = gaussianVector(n);
double* b = (double*) malloc( m * sizeof(double));
double* x = (double*) malloc( n * sizeof(double));
memset (x, 0, n * sizeof (double));
// LS Error
double error = 0.0;
// Input matrix is sparse (REK_sparse)
SMAT *As = fillSparseMat(m, n, sparsity);
// Set b = As * x
myDGEMVSparse(As,xls, b);
//**********************************************
// Test the sparse version of REK *
//**********************************************
printf("--->REK for sparse (%dx%d)-matrix with sparsity %f.\n", m, n, sparsity);
sparseREK (As, x, b, TOL);
error = lsErrorSparse(As, x, b);
freeSMAT(As);
printf("Sparse REK: LS error is : %e\n", error);
//**********************************************
// Test the dense version of REK *
//**********************************************
printf("--->REK for dense (%dx%d)-matrix.\n", m, n);
MAT *A = fillRandomEntries(m, n);
memset (b, 0, m * sizeof (double));
memset (x, 0, n * sizeof (double));
myDGEMV(A,xls, b);
denseREKBLAS(A, x, b, TOL);
error = lsError(A, x, b);
freeMAT(A);
printf("Dense REK: LS error is : %e\n", error);
free(xls);
free(x);
free(b);
return 0;
};