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