Demo entry 6625608

java

   

Submitted by java on Jun 21, 2017 at 12:05
Language: Java. Code size: 1.0 kB.

//获取矩阵A
    jbyte *olddata_A = (jbyte*)env->GetByteArrayElements(matrixA, 0);
    jint row_A=nRow_A;
    jint col_A=nCol_A;
    jsize  oldsize_A = row_A * col_A;

    unsigned char *pData_A= (unsigned char*)olddata_A;
    //存入矩阵A
unsigned int matA[row_A][col_A];
for (int i=0; i<row_A; i++)
    {
        for (int j=0; j<col_A; j++)
        {
             matA[i][j] = pData_A[i*col_A  + j];		// 复制数据到二维数组
        }
}
//用同样方法获取矩阵B,然后进行矩阵相乘。
gf_init(8, prim_poly[8]);    //初始化有限域
//矩阵相乘
unsigned char result_matrix[row_A][col_B];
for (int i=0; i<row_A; i++)
{
  for (int j=0;j<col_B; j++)
  {
     // Now, the main element must be nonsingular.
     int temp = 0;
     for (int k = 0; k < col_A; k++){
         temp = gf_add(temp, gf_mul(matA[i][k], matB[k][j]));
     }
     result_matrix[i][j]=temp;
   }
}
gf_uninit();  //释放有限域

//返回结果
jsize myLen=row_A*col_B;
jbyteArray jarrRV = env->NewByteArray(myLen);
jbyte *jby=(jbyte*)result_matrix;
env->SetByteArrayRegion(jarrRV, 0, myLen, jby);

return jarrRV;

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).