00001 #ifndef UTIL_H
00002 #define UTIL_H
00003
00007 #include "dmatrix.h"
00008
00009 #ifdef __cplusplus
00010 extern "C" {
00011 #endif
00012
00013 #define TYPE_E 0
00014 #define TYPE_G 1
00015
00019 #define BUFFER_INC_SIZE 1024
00020 #define BUFFER_SIZE_DOUBLE sizeof(double)
00021 #define BUFFER_SIZE_INT sizeof(int)
00022 typedef struct {
00023 int elemsize;
00024 int length;
00025 int curpos;
00026 void *ptr;
00027 } buffer_t;
00028
00029 void buffer_new(buffer_t **buf, int elemsize, int length);
00030 void buffer_free(buffer_t *buf);
00031 int buffer_write(buffer_t *buf, void *src, int n);
00032 int condense_solution(const int len, double *sol, int *idx);
00033
00034
00035
00036 double find_lambdamax(const dmatrix *X, const double *b, const int sflag);
00037
00038
00039 void standardize_data(dmatrix *X, const double *b, double **average,
00040 double **stddev, double **acol, double **arow);
00041
00042
00043 int read_mm_new_matrix(const char *file_x, dmatrix **out_mat);
00044 int read_mm_new_matrix_transpose(const char *file, dmatrix **out_mat);
00045
00046 int read_mm_new_vector(const char *file_x, double **out_vec);
00047
00048 int write_mm_vector(const char *file, const int m, const double *vec,
00049 const char *comments, const int type);
00050 int write_mm_matrix(const char *file, dmatrix *mat,
00051 const char *comments, const int type);
00052
00053 int write_mm_matrix_crd_header(FILE *fp, const int m, const int n,
00054 const int nnz, const char *comments);
00055 int write_mm_matrix_crd_column(FILE *fp, const int len,
00056 const int col, const double *vec);
00057 int write_mm_matrix_crd_column_threshold(FILE *fp, const int len,
00058 const int col, const double *vec, const double threshold);
00059 int get_mm_info(const char *file, int *m, int *n, int *nz);
00060
00061 int show_histogram(const int n, const double *coeff);
00062
00063 double userinput_threshold(void);
00064 int thresholding(const int n, double *coeff, double threshold);
00065
00066
00067 #ifdef __cplusplus
00068 }
00069 #endif
00070
00071 #endif