00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <math.h>
00026 #include <flgrCoreVector.h>
00027 #include <flgrCoreArithVector.h>
00028 #include <flgrCoreDispatch.h>
00029 #include <flgrCoreDataIO.h>
00030 #include "flgrMatrixTransform.h"
00031 #include "flgrMatrixTransformSSE.h"
00032 #include "flgrMatrixTransformSSE2.h"
00033
00035
00037 #define flgr2d_matrix_matrixprod(dtype) \
00038 int i,j,k; \
00039 int n,n2,m,m2; \
00040 FLGR_Vector *vdat_a = flgr_vector_create(dat_a->spp,dat_a->type); \
00041 FLGR_Vector *vdat_b = flgr_vector_create(dat_a->spp,dat_a->type); \
00042 FLGR_Vector *vsum = flgr_vector_create(dat_a->spp,dat_a->type); \
00043 \
00044 \
00045 \
00046 m=dat_a->size_y; \
00047 n=dat_b->size_x; \
00048 m2=dat_b->size_y; \
00049 n2=dat_a->size_x; \
00050 \
00051 for(i=0 ; i<m ; i++) { \
00052 for(j=0 ; j<n ; j++) { \
00053 flgr_vector_clear(vsum); \
00054 for(k=0 ; k<m2; k++) { \
00055 flgr2d_get_data_vector_##dtype(dat_a,i,k,vdat_a); \
00056 flgr2d_get_data_vector_##dtype(dat_b,k,j,vdat_b); \
00057 flgr_vector_mult(vdat_a, vdat_a, vdat_b); \
00058 flgr_vector_add(vsum,vsum,vdat_a); \
00059 } \
00060 flgr2d_set_data_vector_##dtype(dat_res,i,j,vsum); \
00061 } \
00062 } \
00063 \
00064 flgr_vector_destroy(vdat_a); \
00065 flgr_vector_destroy(vdat_b); \
00066 flgr_vector_destroy(vsum); \
00067 \
00068 return
00069
00070 void flgr2d_matrix_mult_fgBIT(FLGR_Data2D *dat_res, FLGR_Data2D *dat_a, FLGR_Data2D *dat_b) {
00071 flgr_no_define_type_function(FLGR_BIT);
00072 }
00073
00074 void flgr2d_matrix_mult_fgUINT8(FLGR_Data2D *dat_res, FLGR_Data2D *dat_a, FLGR_Data2D *dat_b) {
00075 flgr2d_matrix_matrixprod(fgUINT8);
00076 }
00077
00078 void flgr2d_matrix_mult_fgUINT16(FLGR_Data2D *dat_res, FLGR_Data2D *dat_a, FLGR_Data2D *dat_b) {
00079 flgr2d_matrix_matrixprod(fgUINT16);
00080 }
00081
00082 void flgr2d_matrix_mult_fgUINT32(FLGR_Data2D *dat_res, FLGR_Data2D *dat_a, FLGR_Data2D *dat_b) {
00083 flgr2d_matrix_matrixprod(fgUINT32);
00084 }
00085
00086 void flgr2d_matrix_mult_fgINT8(FLGR_Data2D *dat_res, FLGR_Data2D *dat_a, FLGR_Data2D *dat_b) {
00087 flgr2d_matrix_matrixprod(fgINT8);
00088 }
00089
00090 void flgr2d_matrix_mult_fgINT16(FLGR_Data2D *dat_res, FLGR_Data2D *dat_a, FLGR_Data2D *dat_b) {
00091 flgr2d_matrix_matrixprod(fgINT16);
00092 }
00093
00094 void flgr2d_matrix_mult_fgINT32(FLGR_Data2D *dat_res, FLGR_Data2D *dat_a, FLGR_Data2D *dat_b) {
00095 flgr2d_matrix_matrixprod(fgINT32);
00096 }
00097
00098 void flgr2d_matrix_mult_fgFLOAT32(FLGR_Data2D *dat_res, FLGR_Data2D *dat_a, FLGR_Data2D *dat_b) {
00099 flgr2d_matrix_matrixprod(fgFLOAT32);
00100 }
00101
00102 void flgr2d_matrix_mult_fgFLOAT64(FLGR_Data2D *dat_res, FLGR_Data2D *dat_a, FLGR_Data2D *dat_b) {
00103 flgr2d_matrix_matrixprod(fgFLOAT64);
00104 }
00105
00106 FLGR_Ret flgr2d_matrix_mult(FLGR_Data2D *dat_res, FLGR_Data2D *dat_a, FLGR_Data2D *dat_b) {
00107 int n,m;
00108
00109
00110 if((dat_res==NULL) || (dat_a==NULL) || (dat_b==NULL)){
00111 POST_ERROR("Null objects!\n");
00112 return FLGR_RET_NULL_OBJECT;
00113 }
00114
00115 m=dat_a->size_y;
00116 n=dat_b->size_x;
00117
00118
00119 if((m!=n)) return -1;
00120 if((dat_res->size_y!=m) || (dat_res->size_x!=n)) return FLGR_RET_SIZE_ERROR;
00121 if(dat_a->type != dat_b->type) return FLGR_RET_TYPE_DIFFERENT;
00122 if(dat_res->type != dat_b->type) return FLGR_RET_TYPE_DIFFERENT;
00123
00124 FLGR_DISPATCH_PROCEDURE(dat_a->type,flgr2d_matrix_mult,dat_res, dat_a, dat_b);
00125
00126 }