void ivar_get_array_nontask( struct array *var, struct ivar iv ) { struct ivar_internals *ivi = iv.internals; struct array *ptr; log_2("ivar_get_array_nontask %p %p - enter\n", var, &iv); pthread_mutex_lock( &(ivi->mutex) ); if ( !ivi->full ) log_2("ivar_get_array_nontask %p %p - waiting for data\n", var, &iv); while(!ivi->full) { int err = pthread_cond_wait( &(ivi->cond), &(ivi->mutex) ); if (err) { exit(err); } } assert(ivi->full); pthread_mutex_unlock( &(ivi->mutex) ); if (NULL == ivi->data) { log_2("ivar_get_array_nontask %p %p - data uninitialized\n", var, &iv); } else { ptr = (struct array*)ivi->data; initArray( var, ptr->elemSize, ptr->length ); copyArray( var, ptr ); } log_2("ivar_get_array_nontask %p %p - leave\n", var, &iv); }
void ivar_get_array( struct array *var, struct ivar iv ) { struct array *ptr; log_2("ivar_get_array %p %p - enter\n", var, &iv); ivar_get_helper(iv.internals); ptr = (struct array*)iv.internals->data; assert(ptr); initArray( var, ptr->elemSize, ptr->length ); copyArray( var, ptr ); log_2("ivar_get_array %p %p - leave\n", var, &iv); }
void ivar_put_array( struct ivar iv, struct array *d ) { struct ivar_internals *ivi = iv.internals; log_2("ivar_put_array %p %p - enter\n", &iv, d); pthread_mutex_lock( &(ivi->mutex) ); ivi->data = (void*)malloc( sizeof(struct array) ); initArray( ivi->data, d->elemSize, d->length ); copyArray( ivi->data, d ); ivi->full = 1; pthread_cond_broadcast( &(ivi->cond) ); pthread_mutex_unlock( &(ivi->mutex) ); log_2("ivar_put_array %p %p - leave\n", &iv, d); }
double _MDL(SegBox *s){ double costT = 0.0; int k = s->model.k; int d = s->model.d; int m = s->len; int i; double costC = s->costC; double costM = costHMM(k, d); double costLen = 0.0; for(i=0;i<s->nSb;i++) costLen += log_2(s->Sb[i].len); costLen += m * log_2(k); costT = costC + costLen + costM; return costT; }
//the information content of a column double ProteinMotif::Info(int col) { int x; double sum=0; for(x=0;x<AA;x++) { if(f[col][x]>0) { sum+=f[col][x]*log_2(f[col][x]); } } if(sum!=0) sum=sum*(-1); else sum=log_2(20); return(log_2(20)-sum); }
MipMap::MipMap(const std::vector<uint8_t> &texels, int width, int height, int ncomp, WRAP_MODE wrap_mode) : wrap_mode(wrap_mode), width(width), height(height), ncomp(ncomp) { if (weight_table[0] == -1){ init_weight_table(); } //We only support power of two textures at the moment //Determine if pow2 via http://www.graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2 if (!(width && !(width & (width - 1))) || !(height && !(height & (height - 1)))){ std::cout << "MipMap Error: Only powers of two are supported at the moment\n"; assert("Non power of two texture"); } int n_levels = 1 + static_cast<int>(log_2(std::max(width, height))); pyramid.reserve(n_levels); pyramid.emplace_back(width, height, texels); for (int i = 1; i < n_levels; ++i){ int w = std::max(1, pyramid[i - 1].width / 2); int h = std::max(1, pyramid[i - 1].height / 2); pyramid.emplace_back(w, h); std::vector<uint8_t> &img = pyramid.back().texels; img.resize(w * h * ncomp); for (int t = 0; t < h; ++t){ for (int s = 0; s < w; ++s){ Colorf cf = 0.25 * (texel(i - 1, 2 * s, 2 * t) + texel(i - 1, 2 * s + 1, 2 * t) + texel(i - 1, 2 * s, 2 * t + 1) + texel(i - 1, 2 * s + 1, 2 * t + 1)); cf.normalize(); Color24 c{cf}; //Write the number of components that we have only for (int j = 0; j < ncomp; ++j){ img[t * w * ncomp + s * ncomp + j] = c[j]; } } } } }
/* permutes the array using a bit-reversal permutation */ void permute_bitrev(int n, int *A_re, int *A_im) { int idata i; int idata bri; int idata log2n; int idata t_re; int idata t_im; log2n = log_2(n); for (i=0; i<n; i++) { bri = bitrev(i, log2n); /* skip already swapped elements */ if (bri <= i) continue; t_re = A_re[i]; t_im = A_im[i]; A_re[i]= A_re[bri]; A_im[i]= A_im[bri]; A_re[bri]= t_re; A_im[bri]= t_im; } }
int main(){ uint32_t i; for(i = 0; i < 150; i++){ printf("log2(%u) = %u\n", i, log_2(i)); } return 0; }
/* Computes d_{ID}(A+t,B) using one-dimensional range searching. Time complexity O(|M|\log m). */ static int processSparseFast(int m, int n, matchList *M) { keyTypeNode *match; int i,d; int *values=(int*)malloc(sizeof(int)*(m+2)); unsigned int leaves = 1<<(log_2(m)+1); treeNode *A = CreateCompleteBinaryTree(leaves); values[0] = 0; insertLeaf(A,leaves, 0); for (i=1;i<=m+1;i++) values[i]=INT_MAX; match = M->first->next; while (match != NULL) { i = predecessor(A,leaves,match->key.i); insertLeaf(A,leaves, match->key.i); if (values[i]-2<values[match->key.i]) { values[match->key.i] = values[i]-2; deleteGreaterSuccessors(A,leaves,match->key.i,values); } match = match->next; } d = values[m+1]+m+n+2; free(values); free(A); return d; }
void fft_swap_in_place(std::array<T, N>& data) { static_assert(power_of_two(N), "only defined for N == power of two"); for(size_t i=0; i<N/2; i++) { const size_t i_rev = __RBIT(i) >> (32 - log_2(N)); std::swap(data[i], data[i_rev]); } }
void fft_swap(const std::array<T, N>& src, std::array<T, N>& dst) { static_assert(power_of_two(N), "only defined for N == power of two"); for(size_t i=0; i<N; i++) { const size_t i_rev = __RBIT(i) >> (32 - log_2(N)); dst[i_rev] = src[i]; } }
void FormantFilter::setfreq_and_q(float frequency, float q_) { //Convert form real freq[Hz] const float freq = log_2(frequency) - 9.96578428f; //log2(1000)=9.95748f. Qfactor = q_; setpos(freq); }
double _MDLtotal(Stack *Opt, Stack *C){ int r = Opt->idx + C->idx; int m = mSegment(Opt) + mSegment(C); double cost = MDLSegment(Opt) + MDLSegment(C); double costT = cost + log_s(r) + log_s(m) + m*log_2(r) + FB*r*r; fprintf(stdout, "%d %d %.0f \n", r, m, costT); return costT; }
void test_battery(int n) { test_all(n, 5); test_all(n, log_2(n)); test_all(n, (int) sqrt((double) n)); test_all(n, n / 2); printf("\n"); }
size_t get_random_block_size( void ) { // Generate the random numbe in the range of [2^0, 2^(lrgst_blk-smlst_blk) ) size_t r_num = rand() % ((1 << (lrgst_blk - smlst_blk)) - 1) + 1; r_num = (lrgst_blk - 1) - log_2(r_num); r_num = (rand() % (1 << r_num)) + (1 << r_num) + 1; return r_num; }
int main() { int *input; input = (int *) malloc(sizeof(int)); printf("Please input a non-negative integer.\n"); scanf("%d", input); printf("The largest integer x such that 2^x <= %d is %d\n", *input, log_2(*input)); }
void init(int argc,char **argv) { register struct sym *sp; if (sigset(SIGINT, SIG_IGN) != SIG_IGN) sigset(SIGINT,onintr); setbuf(stdout,(char *)NULL); svargc = --argc; svargv = argv; while(svargc>0 && svargv[1][0] == '-'){ switch(svargv[1][1]){ default: dbg=1; } svargc--; svargv++; } ifile=1; if(svargc<=0)curfile = stdin; else if((curfile = fopen(svargv[1],"r")) == NULL){ printf("can't open file %s\n",svargv[1]); exit(1); } scalptr = salloc(1); sputc(scalptr,0); basptr = salloc(1); sputc(basptr,10); obase=10; log_10=log_2(10L); ll=68; fw=1; fw1=0; tenptr = salloc(1); sputc(tenptr,10); obase=10; inbas = salloc(1); sputc(inbas,10); sqtemp = salloc(1); sputc(sqtemp,2); chptr = salloc(0); strptr = salloc(0); divxyz = salloc(0); stkbeg = stkptr = &stack[0]; stkend = &stack[STKSZ]; stkerr = 0; readptr = &readstk[0]; k=0; sp = sptr = &symlst[0]; while(sptr < &symlst[TBLSZ]){ sptr->next = ++sp; sptr++; } sptr->next=0; sfree = &symlst[0]; return; }
int can_do(struct problem *p) { return (SINGLE_PRECISION && p->rank == 1 && p->sign == -1 && problem_complex_power_of_two(p, 1) && ((log_2(p->n[0]) & 1) == 0) && /* power of 4 */ p->n[0] > 4 && p->n[0] <= 1024); }
STATIC_INLINE void free_list_insert (bdescr *bd) { nat ln; ASSERT(bd->blocks < BLOCKS_PER_MBLOCK); ln = log_2(bd->blocks); dbl_link_onto(bd, &free_list[ln]); }
int log_2(int x) { if (x == 0) { // invalid input, log(0) is undefined (or -inf) fprintf(stderr, "error: log on %d\n", x); return -1; } else if (x == 1) { return 0; } else { return 1 + log_2(x / 2); } }
void hubp1_program_tiling( struct hubp *hubp, const union dc_tiling_info *info, const enum surface_pixel_format pixel_format) { struct dcn10_hubp *hubp1 = TO_DCN10_HUBP(hubp); REG_UPDATE_6(DCSURF_ADDR_CONFIG, NUM_PIPES, log_2(info->gfx9.num_pipes), NUM_BANKS, log_2(info->gfx9.num_banks), PIPE_INTERLEAVE, info->gfx9.pipe_interleave, NUM_SE, log_2(info->gfx9.num_shader_engines), NUM_RB_PER_SE, log_2(info->gfx9.num_rb_per_se), MAX_COMPRESSED_FRAGS, log_2(info->gfx9.max_compressed_frags)); REG_UPDATE_4(DCSURF_TILING_CONFIG, SW_MODE, info->gfx9.swizzle, META_LINEAR, info->gfx9.meta_linear, RB_ALIGNED, info->gfx9.rb_aligned, PIPE_ALIGNED, info->gfx9.pipe_aligned); }
static int _dim_is_power_of_two( QSP_ARG_DECL Data_Obj *dp, int dim_idx, const char *funcname ) { if( log_2( OBJ_DIMENSION(dp,dim_idx) ) == -1 ){ sprintf(ERROR_STRING, "%s: Number of %ss of image %s (%d) is not a power of two!?", funcname, dimension_name[dim_idx],OBJ_NAME(dp),OBJ_DIMENSION(dp,dim_idx)); WARN(ERROR_STRING); longlist(dp); return FALSE; } return TRUE; }
void fft_swap(const std::array<complex16_t, N>& src, std::array<T, N>& dst) { static_assert(power_of_two(N), "only defined for N == power of two"); for(size_t i=0; i<N; i++) { const size_t i_rev = __RBIT(i) >> (32 - log_2(N)); const auto s = src[i]; dst[i_rev] = { static_cast<typename T::value_type>(s.real()), static_cast<typename T::value_type>(s.imag()) }; } }
static int _fft_row_size_ok(QSP_ARG_DECL Data_Obj *dp, const char * funcname ) { if( log_2(OBJ_COLS(dp)) == -1 ){ sprintf(ERROR_STRING, "%s: number of columns of image %s (%d) is not a power of two for FFT", funcname,OBJ_NAME(dp),OBJ_COLS(dp)); WARN(ERROR_STRING); longlist(dp); return(-1); } return(0); }
void frecuency_multiplication(Image<T> &img,const char *filename, int num_kernel = 0){ int Ncols = (img.cols == (1<<(log_2(img.cols))-1))? img.cols : 1<<(log_2(img.cols)); int Nrows = (img.rows == (1<<(log_2(img.rows))-1))? img.rows : 1<<(log_2(img.rows)); Ncols = Nrows = max(Ncols,Nrows); cout<<Ncols<<" "<<Nrows<<endl; Image<cpx> ori(Nrows,Ncols); Image<cpx> kernel(Nrows,Ncols); Image<cpx> kernel_frec(Nrows,Ncols); Image<T> init_kernel(3,3); Image<cpx> dest(Nrows,Ncols); Image<cpx> final(Nrows,Ncols); Image<T> final2(Nrows,Ncols); initialize_kernel(init_kernel,num_kernel); cp_and_padding(ori,img); cp_and_padding(kernel,init_kernel); FFT_image(ori,dest); FFT_image(kernel,kernel_frec); multiply(dest,kernel_frec,final); FFT_image(final,ori,-1); for(int i = 0; i < final.rows; ++i) for(int j = 0; j < final.cols; ++j){ //final2(i,j) = ori(i,j).a / (Nrows*Ncols); // REAL final2(i,j) = sqrt(ori(i,j).modsq()) / (Nrows*Ncols); // Magnitude assert(ori(i,j).b < 1e-4); } final2.normalize(400); save_image(filename, final2); }
void merge(int a[], int b[], int m, int n) { int a_size=m; int b_size=n; while (n != 0 && m != 0) { printf("%d %d\n",m,n); if (!(m > n)) { int t = log_2(n / m); int i = n + 1 - pow_2(t); if (a[m-1] < b[i-1]) { printf("Decreasing n\n"); n = n - pow_2(t); } else { int k = binsearch(i-1,n,a[m-1],b)+1; printf("Inserting %d into b at %d\n", a[m-1], k-1); insert(a[m-1],k-1,b_size,b); b_size++; m = m - 1; n = k; } } else /* m > n */ { int t = log_2(m / n); int i = m + 1 - pow_2(t); if (b[n-1] < a[i-1]) { printf("Decreasing m\n"); m = m - pow_2(t); } else { int k = binsearch(i-1,m,b[n-1],a)+1; printf("Inserting %d into a at %d\n", b[n-1], k-1); insert(b[n-1],k-1,a_size,a); a_size++; n = n - 1; m = k; } } } printf("%d %d\n",m,n); }
// Take a free block group bd, and split off a group of size n from // it. Adjust the free list as necessary, and return the new group. static bdescr * split_free_block (bdescr *bd, W_ n, nat ln) { bdescr *fg; // free group ASSERT(bd->blocks > n); dbl_link_remove(bd, &free_list[ln]); fg = bd + bd->blocks - n; // take n blocks off the end fg->blocks = n; bd->blocks -= n; setup_tail(bd); ln = log_2(bd->blocks); dbl_link_onto(bd, &free_list[ln]); return fg; }
/* Reports {j} such that d_{ID}(A + t, T_{j'...j}) <= k. Time complexity is O(|M|\log m). */ static void searchOccurrences(int m, int k, int t, matchList *M, occType* occ) { keyTypeNode *match; int i,d,value; int *values=(int*)malloc(sizeof(int)*(m+2)); unsigned int leaves = 1<<(log_2(m)+1); treeNode *A = CreateCompleteBinaryTree(leaves); values[0] = 0; insertLeaf(A,leaves, 0); for (i=1;i<=m+1;i++) values[i]=INT_MAX; match = M->first->next; /* discard the pair (m+1,n+1) since it is only used in the distance computation (hence using match->next != NULL) */ while (match->next != NULL) { i = predecessor(A,leaves,match->key.i); /* let's check if cheeper to start a new occurrence */ d = min2(values[i]-2,-match->key.j-1); insertLeaf(A,leaves, match->key.i); if (d<values[match->key.i]) { values[match->key.i] = d; deleteGreaterSuccessors(A,leaves,match->key.i,values); } /* We should report an interval [key.j,j] on the last row, where the current point induces occurrences d_{ID}(A+t,T_{j''...j'})<=k, where j' in [key.j,j]. However, since d_{ID}(A+t,T_{j''...key.j}) will be the best occurrence induced by the current point, let's just report it. */ value = d+match->key.j+m; if (value <= k && value < occ[match->key.j].value) { occ[match->key.j].value = value; occ[match->key.j].t = t; } match = match->next; } free(values); free(A); }
/* W will contain roots of unity so that W[bitrev(i,log2n-1)] = e^(2*pi*i/n) * n should be a power of 2 * Note: W is bit-reversal permuted because fft(..) goes faster if this is done. * see that function for more details on why we treat 'i' as a (log2n-1) bit number. */ void compute_W(int n, double *W_re, double *W_im) { int i, br; int log2n = log_2(n); for (i=0; i<(n/2); i++) { br = bitrev(i,log2n-1); W_re[br] = cos(((double)i*2.0*M_PI)/((double)n)); W_im[br] = sin(((double)i*2.0*M_PI)/((double)n)); } #ifdef COMMENT_ONLY for (i=0;i<(n/2);i++) { br = i; //bitrev(i,log2n-1); printf("(%g\t%g)\n", W_re[br], W_im[br]); } #endif }
/* W will contain roots of unity so that W[bitrev(i,log2n-1)] = e^(2*pi*i/n) * n should be a power of 2 * Note: W is bit-reversal permuted because fft(..) goes faster if this is done. * see that function for more details on why we treat 'i' as a (log2n-1) bit number. */ void compute_W(int idata n, int idata W_re[], int idata W_im[]) { int idata i; int idata br; int log2n = log_2(n); for (i=0; i<(n/2); i++) { br = bitrev(i,log2n-1); W_re[br] = cos((i*2*3)/(n)); W_im[br] = sin((i*2*3)/(n)); } //#ifdef COMMENT_ONLY // for (i=0;i<(n/2);i++) // { // br = i; //bitrev(i,log2n-1); // printf("(%g\t%g)\n", W_re[br], W_im[br]); // } //#endif }