📄 gfplus.c
字号:
#include <math.h>#include "mex.h"/* * GFPLUS Galois Field addition (vectorized) * k = gfplus(i,j,alpha,beta) *//* * Wes Wang, Cleve Moler, 10/5/95 * Copyright (c) 1995-96 The MathWorks, Inc. * All Rights Reserved * $Revision: 1.1 $ $Date: 1996/04/01 18:14:36 $ */void mexFunction(int nlhs, Matrix *plhs[], int nrhs, Matrix *prhs[]){ int mi,ni,mj,nj,m,n,k,r,inci,incj, indi, indj, nalpha; double *pi,*pj,*pr,*alpha,*beta; mi = mxGetM(prhs[0]); ni = mxGetN(prhs[0]); mj = mxGetM(prhs[1]); nj = mxGetN(prhs[1]); alpha = mxGetPr(prhs[2]); beta = mxGetPr(prhs[3]); nalpha = mxGetN(prhs[2]) * mxGetM(prhs[2]); if (nalpha != mxGetN(prhs[3]) * mxGetM(prhs[3])) mexErrMsgTxt("Dimensions of Alpha and Beta must agree."); nalpha = nalpha - 1; if ((mi == 1) & (ni == 1) & (mj == 1) & (nj == 1)) { r = ((int) alpha[(int) mxGetScalar(prhs[0]) % nalpha + 1]) ^ ((int) alpha[(int) mxGetScalar(prhs[1]) % nalpha + 1]); *mxGetPr(plhs[0] = mxCreateFull(1,1,0)) = (double) (beta[r]-1); return; } else if ((mi == mj) & (ni == nj)) { m = mi; n = ni; inci = 1; incj = 1; } else if ((mj == 1) & (nj == 1)) { m = mi; n = ni; inci = 1; incj = 0; } else if ((mi == 1) & (ni == 1)) { m = mj; n = nj; inci = 0; incj = 1; } else { mexErrMsgTxt("Matrix dimensions must agree."); } pi = mxGetPr(prhs[0]); pj = mxGetPr(prhs[1]); pr = mxGetPr(plhs[0] = mxCreateFull(m,n,0)); for (k = 0; k < m*n; k++) {/* indi = (int)*pi+1; indj = (int)*pj+1; if (indi < 0) indi = 0; if (indj < 0) indj = 0; */ indi = (*pi < 0) ? 0 : (int)*pi % nalpha + 1; indj = (*pj < 0) ? 0 : (int)*pj % nalpha + 1; r = ((int) alpha[indi]) ^ ((int) alpha[indj]); *pr++ = (double) (beta[r]-1); pi += inci; pj += incj; } return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -