do calculation of arrangement
arg_useful.h@0:fe553d45f0b2, 2015-04-18 (annotated)
- Committer:
- hirokimineshita
- Date:
- Sat Apr 18 09:27:00 2015 +0000
- Revision:
- 0:fe553d45f0b2
- Child:
- 1:0f4bc913a3cc
2015/04/18 PM 6
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hirokimineshita | 0:fe553d45f0b2 | 1 | #ifndef _ARG_USEFUL_20150418_1411_ |
hirokimineshita | 0:fe553d45f0b2 | 2 | #define _ARG_USEFUL_20150418_1411_ |
hirokimineshita | 0:fe553d45f0b2 | 3 | |
hirokimineshita | 0:fe553d45f0b2 | 4 | //at matrix, place is from left to right and next, from up to down |
hirokimineshita | 0:fe553d45f0b2 | 5 | |
hirokimineshita | 0:fe553d45f0b2 | 6 | /** arg_subs : |
hirokimineshita | 0:fe553d45f0b2 | 7 | * |
hirokimineshita | 0:fe553d45f0b2 | 8 | * @bref substitution of arrangements |
hirokimineshita | 0:fe553d45f0b2 | 9 | * @param arg_to arrangement of what you want to submitition |
hirokimineshita | 0:fe553d45f0b2 | 10 | * @param arg_from arrangement of original |
hirokimineshita | 0:fe553d45f0b2 | 11 | * @param all_ele numbers of elements |
hirokimineshita | 0:fe553d45f0b2 | 12 | */ |
hirokimineshita | 0:fe553d45f0b2 | 13 | void arg_subs(float *arg_to,float *arg_from,int all_ele) |
hirokimineshita | 0:fe553d45f0b2 | 14 | { |
hirokimineshita | 0:fe553d45f0b2 | 15 | for(int i=0; i<all_ele; i++)arg_to[i]=arg_from[i]; |
hirokimineshita | 0:fe553d45f0b2 | 16 | } |
hirokimineshita | 0:fe553d45f0b2 | 17 | |
hirokimineshita | 0:fe553d45f0b2 | 18 | /** arg_swap : |
hirokimineshita | 0:fe553d45f0b2 | 19 | * |
hirokimineshita | 0:fe553d45f0b2 | 20 | * @bref swap two arrangements |
hirokimineshita | 0:fe553d45f0b2 | 21 | * @param arg_a arrangement of what you want to swap |
hirokimineshita | 0:fe553d45f0b2 | 22 | * @param arg_b (same as arg_a) |
hirokimineshita | 0:fe553d45f0b2 | 23 | * @param all_ele numbers of elements |
hirokimineshita | 0:fe553d45f0b2 | 24 | */ |
hirokimineshita | 0:fe553d45f0b2 | 25 | void arg_swap(float *arg_a,float *arg_b, int all_ele) |
hirokimineshita | 0:fe553d45f0b2 | 26 | { |
hirokimineshita | 0:fe553d45f0b2 | 27 | float c; |
hirokimineshita | 0:fe553d45f0b2 | 28 | for(int i=0; i<all_ele; i++){ |
hirokimineshita | 0:fe553d45f0b2 | 29 | c=arg_a[i]; |
hirokimineshita | 0:fe553d45f0b2 | 30 | arg_a[i]=arg_b[i]; |
hirokimineshita | 0:fe553d45f0b2 | 31 | arg_b[i]=c; |
hirokimineshita | 0:fe553d45f0b2 | 32 | } |
hirokimineshita | 0:fe553d45f0b2 | 33 | } |
hirokimineshita | 0:fe553d45f0b2 | 34 | |
hirokimineshita | 0:fe553d45f0b2 | 35 | /** arg_plus : |
hirokimineshita | 0:fe553d45f0b2 | 36 | * |
hirokimineshita | 0:fe553d45f0b2 | 37 | * @bref do addition of two matrix a[row][col] |
hirokimineshita | 0:fe553d45f0b2 | 38 | * @param ans matrix of answer |
hirokimineshita | 0:fe553d45f0b2 | 39 | * @param arg_a matrix of what you want to add |
hirokimineshita | 0:fe553d45f0b2 | 40 | * @param arg_b (same as arg_a) |
hirokimineshita | 0:fe553d45f0b2 | 41 | * @param row numbers of elements of row |
hirokimineshita | 0:fe553d45f0b2 | 42 | * @param col numbers of elements of col |
hirokimineshita | 0:fe553d45f0b2 | 43 | */ |
hirokimineshita | 0:fe553d45f0b2 | 44 | void arg_plus(float *ans,float *arg_a,float *arg_b,int row,int col) |
hirokimineshita | 0:fe553d45f0b2 | 45 | { |
hirokimineshita | 0:fe553d45f0b2 | 46 | for(int i=0; i<row; i++){ |
hirokimineshita | 0:fe553d45f0b2 | 47 | for(int j=0; j<col; j++)ans[i*col+j] = arg_a[i*col+j]+arg_b[i*col+j]; |
hirokimineshita | 0:fe553d45f0b2 | 48 | } |
hirokimineshita | 0:fe553d45f0b2 | 49 | } |
hirokimineshita | 0:fe553d45f0b2 | 50 | |
hirokimineshita | 0:fe553d45f0b2 | 51 | /** arg_minus : |
hirokimineshita | 0:fe553d45f0b2 | 52 | * |
hirokimineshita | 0:fe553d45f0b2 | 53 | * @bref do subtraction of two matrix like a-b |
hirokimineshita | 0:fe553d45f0b2 | 54 | * @param ans matrix of answer |
hirokimineshita | 0:fe553d45f0b2 | 55 | * @param arg_a matrix of what you want to minus |
hirokimineshita | 0:fe553d45f0b2 | 56 | * @param arg_b (same as arg_a) |
hirokimineshita | 0:fe553d45f0b2 | 57 | * @param row numbers of elements of row |
hirokimineshita | 0:fe553d45f0b2 | 58 | * @param col numbers of elements of col |
hirokimineshita | 0:fe553d45f0b2 | 59 | */ |
hirokimineshita | 0:fe553d45f0b2 | 60 | void arg_minus(float *ans,float *arg_a,float *arg_b,int row,int col) |
hirokimineshita | 0:fe553d45f0b2 | 61 | { |
hirokimineshita | 0:fe553d45f0b2 | 62 | for(int i=0; i<row; i++){ |
hirokimineshita | 0:fe553d45f0b2 | 63 | for(int j=0; j<col; j++)ans[i*col+j] = arg_a[i*col+j]-arg_b[i*col+j]; |
hirokimineshita | 0:fe553d45f0b2 | 64 | } |
hirokimineshita | 0:fe553d45f0b2 | 65 | } |
hirokimineshita | 0:fe553d45f0b2 | 66 | |
hirokimineshita | 0:fe553d45f0b2 | 67 | /** arg_multi : |
hirokimineshita | 0:fe553d45f0b2 | 68 | * |
hirokimineshita | 0:fe553d45f0b2 | 69 | * @bref do multiplication of two matrix like a*b |
hirokimineshita | 0:fe553d45f0b2 | 70 | * @param ans matrix of answer |
hirokimineshita | 0:fe553d45f0b2 | 71 | * @param arg_a matrix of what you want to minus |
hirokimineshita | 0:fe553d45f0b2 | 72 | * @param row_a numbers of elements of row of arg_a |
hirokimineshita | 0:fe553d45f0b2 | 73 | * @param col_b numbers of elements of col of arg_a |
hirokimineshita | 0:fe553d45f0b2 | 74 | * @param arg_b (same as arg_a) |
hirokimineshita | 0:fe553d45f0b2 | 75 | * @param row_b numbers of elements of row of arg_b |
hirokimineshita | 0:fe553d45f0b2 | 76 | * @param col_b numbers of elements of col of arg_b |
hirokimineshita | 0:fe553d45f0b2 | 77 | * @retval 0 you can multiplication |
hirokimineshita | 0:fe553d45f0b2 | 78 | * @retval -1 you can't multiplication |
hirokimineshita | 0:fe553d45f0b2 | 79 | */ |
hirokimineshita | 0:fe553d45f0b2 | 80 | int arg_multi(float *ans,float *arg_a,int row_a,int col_a,float *arg_b,int row_b,int col_b) |
hirokimineshita | 0:fe553d45f0b2 | 81 | { |
hirokimineshita | 0:fe553d45f0b2 | 82 | if(col_a!=row_b)return -1; |
hirokimineshita | 0:fe553d45f0b2 | 83 | else{ |
hirokimineshita | 0:fe553d45f0b2 | 84 | for(int i=0; i<row_a; i++){ |
hirokimineshita | 0:fe553d45f0b2 | 85 | for(int j=0; j<col_b; j++){ |
hirokimineshita | 0:fe553d45f0b2 | 86 | ans[i*col_b+j]=0; |
hirokimineshita | 0:fe553d45f0b2 | 87 | for(int k=0; k<col_a; k++)ans[i*col_b+j]+=arg_a[i*col_a+k]*arg_b[j+col_b*k]; |
hirokimineshita | 0:fe553d45f0b2 | 88 | } |
hirokimineshita | 0:fe553d45f0b2 | 89 | } |
hirokimineshita | 0:fe553d45f0b2 | 90 | } |
hirokimineshita | 0:fe553d45f0b2 | 91 | return 0; |
hirokimineshita | 0:fe553d45f0b2 | 92 | } |
hirokimineshita | 0:fe553d45f0b2 | 93 | |
hirokimineshita | 0:fe553d45f0b2 | 94 | |
hirokimineshita | 0:fe553d45f0b2 | 95 | #endif |