/** * The Return Value Same As Snprintf * */ int smartSizeRadixDesc( __xin unsigned long long size, __xin int radixcnt, __xin const SmartRadix radix[], __xin int maxu, __xin int smart, __xin size_t buflen, __xout char* buf) { unsigned short idx = 0; unsigned long long *ssize; unsigned long long ssizedefaults[10] = {0}; SmartRadixCon con = {radix, radixcnt}; if (radixcnt + 1 < 10) { ssize = ssizedefaults; } else { ssize = (unsigned long long*)calloc(1, sizeof(unsigned long long) * (radixcnt + 1)); } // get the radix base format idx = smartRadixChange(size, &con, maxu, ssize); // build the size unit string buflen = smartRadixDesc(ssize, &con, idx, smart, buflen, buf); __CP("%s\n", buf); if (ssize != ssizedefaults) { free(ssize); } return buflen; }
/** * @brief New copy of matrix * * Allocate space and copy matrix, A = newcopy(B) * * @param [in] A * The source matrix * * @retval NOT NULL Success, pointer to new matrix * @retval NULL Failed * \ingroup matrix */ armas_x_dense_t *armas_x_newcopy(const armas_x_dense_t *A) { armas_x_dense_t *Anew = armas_x_alloc(A->rows, A->cols); if (Anew) { __CP(Anew->elems, Anew->step, A->elems, A->step, A->rows, A->cols); } return Anew; }
int smartRadixChange( __xin unsigned long long size, __xin const SmartRadixCon *con, __xin int maxu, __xout unsigned long long ssize[]) { unsigned short idx = 0; ssize[0] = size; __CP("total-size %llu\n", size); // calc size if (size) do { ssize[idx+1] = ssize[idx] / con->radix[idx].radix; ssize[idx] = ssize[idx] % con->radix[idx].radix; __CP("offset[%d]-size %llu, %llu\n", idx, ssize[idx], ssize[idx+1]); } while(++idx<con->len && ssize[idx] > 0 && --maxu>0); // max calc unit if (ssize[idx] > 0 ) { ssize[idx-1] = (ssize[idx] * con->radix[idx-1].radix) + ssize[idx-1]; } return idx; }
/** * @brief Copy matrix or vector * * Copy matrix or vector to another matrix or vector, ie. A = B. Sizes of * of operand must match, for matrix size(A) == size(B), for vector len(A) == len(B) * * @param [out] A * Destination matrix or vector, on exit copy of source matrix * @param [in] B * Source matrix or vector * * @retval A Success * @retval NULL Incompatible sizes * \ingroup matrix */ armas_x_dense_t *armas_x_mcopy(armas_x_dense_t *A, const armas_x_dense_t *B) { if (armas_x_isvector(A) && armas_x_isvector(B)) { if (armas_x_size(A) != armas_x_size(B)) return (armas_x_dense_t *)0; // blas1 vector copy armas_x_copy(A, B, (armas_conf_t *)0); return A; } if (A->rows != B->rows || A->cols != B->cols) return (armas_x_dense_t *)0; __CP(A->elems, A->step, B->elems, B->step, B->rows, B->cols); return A; }
int smartRadixDiffDesc( __xin unsigned long long lfs, __xin unsigned long long rfs, __xin int radixcnt, __xin const SmartRadix radix[], __xin int maxu, __xin int smart, __xin const char* suffixs[], __xin size_t buflen, __xout char* buf ) { int len = 0; unsigned short idx = 0; unsigned long long *ssize; unsigned long long ssizedefaults[10] = {0}; SmartRadixCon con = {radix, radixcnt}; if (radixcnt + 1 < 10) { ssize = ssizedefaults; } else { ssize = (unsigned long long*)calloc(1, sizeof(unsigned long long) * (radixcnt + 1)); } idx = smartRadixDiff(lfs, rfs, &con, maxu, ssize); // build the size unit string if (idx) { len = smartRadixDesc(ssize, &con, idx, smart, buflen, buf); if (suffixs && len > 0 && (size_t)len < buflen) { smart = snprintf(buf + len, buflen-len, "%s", suffixs[ssize[idx] + 1]); if (smart>0 && (size_t)smart<buflen-len) { len += smart; } } } else { len = snprintf(buf, buflen, "%s", suffixs[ssize[idx] + 1]); } __CP("%s\n", buf); if (ssize != ssizedefaults) { free(ssize); } return len; }