-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.h
47 lines (41 loc) · 2.3 KB
/
matrix.h
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
#ifndef STDIO_H
#define STDIO_H
#include<stdio.h>
#endif
#ifndef STDDEF_H
#define STDDEF_H
#include<stddef.h>
#endif
struct Matrix{
size_t row,col;// 我们使用了[0,0]~[row-1,col-1]的内存,请使用get和set
float *data;
};
//get, set
inline float get_num(const struct Matrix *now_used, const size_t row, const size_t col);
inline void set_num(struct Matrix *now_used, const float num, const size_t row, const size_t col);
//构造函数&析构函数
struct Matrix *create_file(struct Matrix *dest, FILE *source);
void create_mat(const size_t row, const size_t col, struct Matrix *used);
void delete_mat(struct Matrix *used);
struct Matrix *copy_mat(const struct Matrix *source, struct Matrix *dest);
//计算,请确保ans不等于a且ans不等于b
void inverse(struct Matrix *a);
struct Matrix *add_mat(const struct Matrix *a, const struct Matrix *b, struct Matrix *ans); //ans=a+b
struct Matrix *sub_mat(const struct Matrix *a, const struct Matrix *b, struct Matrix *ans); //ans=a-b
struct Matrix *mul_plain(const struct Matrix *a, const struct Matrix *b, struct Matrix *ans); //ans=a*b,plain_version
struct Matrix *mul_ikj(const struct Matrix *a, const struct Matrix *b, struct Matrix *ans); //寻址优化
struct Matrix *mul_avx(const struct Matrix *a, struct Matrix *b, struct Matrix *ans); //avx指令集
//调用此后的功能请确保矩阵大小是2的整数次方(其实能整除八就行)
//可以在 matrix.c中调整defined ROLL实现其他大小循环展开
struct Matrix *mul_unroll(const struct Matrix *a, struct Matrix *b, struct Matrix *ans); //unroll
struct Matrix *mul_omp(const struct Matrix *a, struct Matrix *b, struct Matrix *ans); //omp
struct Matrix *mul_strassen(const struct Matrix *a, struct Matrix *b, struct Matrix *ans, size_t size); //strassen,会丢精度,不是omp的问题
//project3的任务,但是在这里是石山
struct Matrix *addScaler(const float num, const struct Matrix *used, struct Matrix *ans);
struct Matrix *subtractScaler(const float num, const struct Matrix *used, struct Matrix *ans);
struct Matrix *multiplyScaler(const float num, const struct Matrix *used, struct Matrix *ans);
//最大最小
float max(const struct Matrix *used);
float min(const struct Matrix *used);
//输出
void print(const struct Matrix *used);