int compute_all_sequences(struct params *fd, int tracksize, int sizecode, int gap, int mask, int biggest_last) { int offset, i; compute_sizes(fd, sectors*512,sizecode); offset = 0; for(i=MAX_SIZECODE - 1 ; i >= 0; i--) { compute_all_sequences_for_size(fd, &offset, tracksize, sizecode, gap, mask, i); if(biggest_last && offset) break; } if(! offset){ fprintf(stderr, "Not enough raw space on this disk for this format\n"); exit(1); } return offset; }
static Tensor new_from_sequence(ScalarType scalarType, PyObject* data) { if (!PySequence_Check(data)) { throw TypeError("new(): data must be a sequence (got %s)", Py_TYPE(data)->tp_name); } if (THPUtils_checkString(data)) { throw TypeError("new(): invalid data type '%s'", Py_TYPE(data)->tp_name); } #ifdef WITH_NUMPY if (PyArray_Check(data)) { return autograd::make_variable(tensor_from_numpy(data), false); } #endif auto sizes = compute_sizes(data); auto tensor = autograd::make_variable(CPU(scalarType).tensor(sizes), false); recursive_store( (char*)tensor.data_ptr(), tensor.sizes(), tensor.strides(), 0, scalarType, tensor.type().elementSizeInBytes(), data); return tensor; }
/* Create a random ball-shaped object */ static void create_polyball( int npts, REAL (*pts)[DIM], VertexID * rings) { double s, c, z, xyr; double radius; int p, q, r; int i, v, lower, upper, slice, firstv, nextv, nextr, lastv; double sines[MAX_POINTS], cosines[MAX_POINTS]; radius = MEAN_RADIUS * ( 1.0 - RADIUS_RATIO*radius_factor / 2.0 + RADIUS_RATIO*radius_factor * unit_random( &seed) ); (void) compute_sizes( npts, & p, & q, & r); /* debugging statements fprintf( stderr, "%d = %d * %d + %d\n", npts, p, q, r); first_time1 = 0; */ /* Force generation of blocks if n==8 */ if ( npts==8 ) { p = 4; q = 2; r = 0; } /**/ /* `normal' vertices are indexed in the range [firstv, lastv] (inclusive) */ firstv = ( r==2 ) ? 1 : 0; lastv = ( r>0 ) ? npts-2 : npts-1; /* compute vertex coordinates */ /* bottom vertex, if it exists */ if ( r==2 ) { pts[0][0] = pts[0][1] = 0; pts[0][2] = - radius; } /* normal vertices */ /* cache sines and cosines first */ sines[0] = 0; cosines[0] = 1; s = sin( 2*M_PI / p ); c = cos( 2*M_PI / p ); for ( i = 1 ; i < p ; i++ ) { sines[i] = cosines[i-1]*s + sines[i-1]*c; cosines[i] = cosines[i-1]*c - sines[i-1]*s; } nextv = firstv; for ( slice=1 ; slice<=q ; slice++ ) { z = radius * ((double) 2*slice - ( q+1) ) / (q+1); xyr = sqrt( radius * radius - z * z ); for ( i = 0 ; i < p ; i++ ) { pts[nextv][0] = xyr * cosines[i]; pts[nextv][1] = xyr * sines[i]; pts[nextv][2] = z; nextv++; } } /* top vertex, if it exists */ if ( r>0 ) { pts[npts-1][0] = pts[npts-1][1] = 0; pts[npts-1][2] = radius; } if ( rings==0 ) /* then no hill-climbing */ return; /* otherwise set up the edge lists. We process them in vertex number order. */ nextr = npts; if ( r==2 ) { /* then form an entry for the first, bottom vertex */ rings[0] = nextr; for ( i=0 ; i<p ; i++ ) rings[nextr++] = i+1; rings[nextr++] = TERMINATOR; } /* now the `normal' vertices */ for ( v=firstv ; v<=lastv ; v++ ) { rings[v] = nextr; slice = (v+p-firstv)/p; rings[v] = nextr; lower = v-p; if ( lower<firstv ) lower = ( r==2 ) ? 0 : -1; if ( lower>=0 ) rings[nextr++] = lower; rings[nextr++] = ( ((v+p+1-firstv)/p)==slice ) ? v+1 : v+1-p; upper = v+p; if ( upper>lastv ) upper = ( r>0 ) ? npts-1 : -1; if ( upper>=0 ) rings[nextr++] = upper; rings[nextr++] = ( ((v+p-1-firstv)/p)==slice ) ? v-1 : v-1+p; rings[nextr++] = TERMINATOR; } if ( r>0 ) { /* then form an entry for the last, top vertex */ rings[npts-1] = nextr; for ( i=0 ; i<p ; i++ ) rings[nextr++] = lastv - i; rings[nextr++] = TERMINATOR; } return; }
mem_pool::mem_pool(size_t max/*=32*1024*/, size_t factor/*=16*/) :_seg_cnt(0), _seg_linear_cnt(0) { compute_sizes(max, chunk_align, factor); }