//--------------------------------------------------------------------------- // Make new size of matrix NaMatrix& NaMatrix::new_dim (unsigned nR, unsigned nC) { if(nR * nC > nDimRow * nDimCol){ delete[] pMatr; pMatr = new NaReal[nR * nC]; init_zero(); } nDimRow = nR; nDimCol = nC; return *this; }
int main() { float tab1[N1] = {3.2, 2.1, -8.4, 0.0, 5.5}; // a eviter generalement float tab2[N2]; float tab3[N3]; init_zero(tab2, N2); init_basic(tab3, N3); affiche(tab1, N1); affiche(tab2, N2); affiche(tab3, N3); return EXIT_SUCCESS; }
Decimal & Decimal::operator *= (int x) { if (x < 0) { is_neg ^= 1; x = -x; } else if (x == 0) { init_zero(); return *this; } int last = 0; for (int i = len - 1; i >= 0; i--) { long long tmp = 1LL * data[i] * x + last; last = tmp / mo; data[i] = tmp - 1LL * last * mo; } integer = integer * x + last; return *this; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { mwSize N, P,ndiags; mwSize n_threads; double *coefr, *coefi, *offset, *yr, *yi, *xr, *xi; int Si_alloc=0, xi_alloc=0; char *n_threads_str = NULL; /* read input, initialize complex part to zero if input is real.*/ N = mxGetN(COEF); ndiags = mxGetM(COEF); coefr = mxGetPr(COEF); if(mxIsComplex(COEF)){ coefi = mxGetPi(COEF); } else{ coefi = mxCalloc(N*ndiags,sizeof(double)); init_zero(coefi,N*ndiags); Si_alloc = 1; } offset = mxGetPr(OFFSET); P = mxGetN(X); if(mxGetM(X) != N) { mexErrMsgIdAndTxt("SLIM_release_apps:tools:algorithms:ThreeDFreqModeling:HMvp_MT_mex:NumElements", "The row size of the vector x and the column size of the matrix A must match"); } n_threads = mxGetScalar(NTHREADS); xr = mxGetPr(X); if(mxIsComplex(X)){ xi = mxGetPi(X); } else{ xi = mxCalloc(N*P,sizeof(double)); init_zero(xi,N*P); xi_alloc = 1; } /* define output vector y and initialize with input vector x.*/ OUTPUT = mxCreateDoubleMatrix(N, P, mxCOMPLEX); yr = mxGetPr(OUTPUT); yi = mxGetPi(OUTPUT); init_zero(yr,N*P); init_zero(yi,N*P); /*Hmvp*/ do_Hmvp(N, ndiags, P, coefr,coefi,offset,yr,yi,xr,xi,n_threads); if (Si_alloc){ mxFree(coefi); } if (xi_alloc){ mxFree(xi); } return; }
void testInvers() { printf("Testing inverting\n"); // Test 0 printf("Test0\n"); // x^2 + x^1 + 1 uint32_t irred0[1] = { 0x7}; // x + 1 uint32_t input0[1] = { 0x3}; uint32_t invers0[1]; f2m_calculateInverse(1, input0, irred0, invers0); uint32_t result0[1]; init_zero(1, result0); f2m_mult (1, input0, invers0, result0); // f2m_print_human(1, result0); // Test 1 printf("Test1\n"); // x^163 + x^7 + x^6 + x^3 + 1 uint32_t irred1[6] = { 0xC9, 0x0, 0x0, 0x0, 0x0, 0x8}; // x^112 + x^32 + x^16 + x^8 + x^4 + x^2 + x^1 uint32_t input1[6] = { 0x10116, 0x1, 0x0, 0x10000, 0x0, 0x0 }; uint32_t invers1[6]; f2m_calculateInverse(6, input1, irred1, invers1); uint32_t result1[12]; init_zero(12, result1); f2m_mult (6, input1, invers1, result1); //f2m_print_human(12, result1); // todo reduce printf("Test2\n"); // x^283 + x^12 + x^7 + x^5 +1 uint32_t irred2[9] = { 0x10A1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8000000}; // x^191 + x^112 + x^32 + x^30 + x^29 + x^27 + x^26 +x^23 +x^21 +x^18 +x^17 +x^14 +x^13 +x^12 +x^7 +x^6 + x^3 + x^2 +x^1 + 1 uint32_t input2[9] = { 0x6CA670CF, 0x1, 0x0, 0x10000, 0x0, 0x80000000, 0x0, 0x0, 0x0}; uint32_t invers2[9]; f2m_calculateInverse(9, input2, irred2, invers2); uint32_t result2[18]; init_zero(18, result1); f2m_mult (18, input2, invers2, result2); // todo reduce result 2 //f2m_print_human(18, result2); printf("Test3\n"); // x^409 + x^87 + 1 uint32_t irred3[13] = { 0x1, 0x0, 0x800000, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x2000000}; // x^382 + x^224 + x^64 + x^60 + x^58 +x^52 + x^46 + x^42 + x^38 + x^36 +x^34 + x^28 + x^26 + x^14 +x^12 + x^6 + x^4 + x^2 + 1 uint32_t input3[13] = { 0x15005055, 0x14504414, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x40000000, 0x0 }; uint32_t invers3[13]; f2m_calculateInverse(13, input3, irred3, invers3); uint32_t result3[26]; init_zero(26, result3); f2m_mult (13, input3, invers3, result3); // todo reduce result 3 //f2m_print_human(26, result3); printf("Tests passed\n"); }