VL_EXPORT void vl_homogeneouskernelmap_delete (VlHomogeneousKernelMap * self) { vl_free(self->table) ; self->table = NULL ; vl_free(self) ; }
void vl_kdforestsearcher_delete (VlKDForestSearcher * self) { vl_free(self->searchHeapArray) ; vl_free(self->searchIdBook) ; vl_free(self) ; }
static void vl_hog_prepare_buffers (VlHog * self, vl_size width, vl_size height, vl_size cellSize) { vl_size hogWidth = (width + cellSize/2) / cellSize ; vl_size hogHeight = (height + cellSize/2) / cellSize ; assert(width > 3) ; assert(height > 3) ; assert(hogWidth > 0) ; assert(hogHeight > 0) ; if (self->hog && self->hogWidth == hogWidth && self->hogHeight == hogHeight) { /* a suitable buffer is already allocated */ memset(self->hog, 0, sizeof(float) * hogWidth * hogHeight * self->numOrientations * 2) ; memset(self->hogNorm, 0, sizeof(float) * hogWidth * hogHeight) ; return ; } if (self->hog) { vl_free(self->hog) ; self->hog = NULL ; } if (self->hogNorm) { vl_free(self->hogNorm) ; self->hogNorm = NULL ; } self->hog = vl_calloc(hogWidth * hogHeight * self->numOrientations * 2, sizeof(float)) ; self->hogNorm = vl_calloc(hogWidth * hogHeight, sizeof(float)) ; self->hogWidth = hogWidth ; self->hogHeight = hogHeight ; }
void vl_ikm_delete (VlIKMFilt* f) { if (f) { if (f-> centers) vl_free (f-> centers) ; if (f-> inter_dist) vl_free (f-> inter_dist) ; vl_free (f) ; } }
void vl_svmdataset_delete (VlSvmDataset *self) { if (self->homBuffer) { vl_free(self->homBuffer) ; self->homBuffer = 0 ; } vl_free (self) ; }
VL_EXPORT void vl_dsift_delete (VlDsiftFilter * self) { _vl_dsift_free_buffers (self) ; if (self->convTmp2) vl_free (self->convTmp2) ; if (self->convTmp1) vl_free (self->convTmp1) ; vl_free (self) ; }
void vl_quickshift_delete(VlQS * q) { if (q) { if (q->parents) vl_free(q->parents); if (q->dists) vl_free(q->dists); if (q->density) vl_free(q->density); vl_free(q); } }
VL_EXPORT void vl_kmeans_reset (VlKMeans * self) { self->numCenters = 0 ; self->dimension = 0 ; if (self->centers) vl_free(self->centers) ; if (self->centerDistances) vl_free(self->centerDistances) ; self->centers = NULL ; self->centerDistances = NULL ; }
static void VL_XCAT(_vl_kmeans_seed_centers_with_rand_data_, SFX) (VlKMeans * self, TYPE const * data, vl_size dimension, vl_size numData, vl_size numCenters) { vl_uindex i, j, k ; VlRand * rand = vl_get_rand () ; self->dimension = dimension ; self->numCenters = numCenters ; self->centers = vl_malloc (sizeof(TYPE) * dimension * numCenters) ; { vl_uindex * perm = vl_malloc (sizeof(vl_uindex) * numData) ; #if (FLT == VL_TYPE_FLOAT) VlFloatVectorComparisonFunction distFn = vl_get_vector_comparison_function_f(self->distance) ; #else VlDoubleVectorComparisonFunction distFn = vl_get_vector_comparison_function_d(self->distance) ; #endif TYPE * distances = vl_malloc (sizeof(TYPE) * numCenters) ; /* get a random permutation of the data point */ for (i = 0 ; i < numData ; ++i) perm[i] = i ; _vl_kmeans_shuffle (perm, numData, rand) ; for (k = 0, i = 0 ; k < numCenters ; ++ i) { /* compare the next data point to all centers collected so far to detect duplicates (if there are enough left) */ if (numCenters - k < numData - i) { vl_bool duplicateDetected = VL_FALSE ; VL_XCAT(vl_eval_vector_comparison_on_all_pairs_, SFX)(distances, dimension, data + dimension * perm[i], 1, (TYPE*)self->centers, k, distFn) ; for (j = 0 ; j < k ; ++j) { duplicateDetected |= (distances[j] == 0) ; } if (duplicateDetected) continue ; } /* ok, it is not a duplicate so we can accept it! */ memcpy ((TYPE*)self->centers + dimension * k, data + dimension * perm[i], sizeof(TYPE) * dimension) ; k ++ ; } vl_free(distances) ; vl_free(perm) ; } }
static void xdelete (VlHIKMNode *node) { if(node) { int k ; if (node->children) { for(k = 0 ; k < vl_ikm_get_K (node->filter) ; ++k) xdelete (node->children[k]) ; vl_free (node->children) ; } if (node->filter) vl_ikm_delete (node->filter) ; vl_free(node); } }
static int libvirt_hostlist(hostlist_callback callback, void *arg, void *priv) { struct libvirt_info *info = (struct libvirt_info *)priv; virt_list_t *vl; int x; dbg_printf(5, "%s\n", __FUNCTION__); VALIDATE(info); vl = vl_get(info->vp, 1); if (!vl) return 1; for (x = 0; x < vl->vm_count; x++) { dbg_printf(10, "Sending %s\n", vl->vm_states[x].v_uuid); callback(vl->vm_states[x].v_name, vl->vm_states[x].v_uuid, vl->vm_states[x].v_state.s_state, arg); } vl_free(vl); return 0; }
Sift::~Sift() { /* release image data */ if (fdata) { vl_free (fdata); fdata = 0; } /* release image data */ if (data) { vl_free (data) ; data = 0 ; } }
VL_EXPORT void vl_kdforest_delete (VlKDForest * self) { vl_uindex ti ; if (self->searchIdBook) vl_free (self->searchIdBook) ; if (self->trees) { for (ti = 0 ; ti < self->numTrees ; ++ ti) { if (self->trees[ti]) { if (self->trees[ti]->nodes) vl_free (self->trees[ti]->nodes) ; if (self->trees[ti]->dataIndex) vl_free (self->trees[ti]->dataIndex) ; } } vl_free (self->trees) ; } vl_free (self) ; }
static void VL_XCAT(_vl_kmeans_quantize_, SFX) (VlKMeans * self, vl_uint32 * assignments, TYPE * distances, TYPE const * data, vl_size numData) { vl_uindex i ; #if (FLT == VL_TYPE_FLOAT) VlFloatVectorComparisonFunction distFn = vl_get_vector_comparison_function_f(self->distance) ; #else VlDoubleVectorComparisonFunction distFn = vl_get_vector_comparison_function_d(self->distance) ; #endif TYPE * distanceToCenters = vl_malloc (sizeof(TYPE) * self->numCenters) ; for (i = 0 ; i < numData ; ++i) { vl_size k ; TYPE bestDistance = (TYPE) VL_INFINITY_D ; VL_XCAT(vl_eval_vector_comparison_on_all_pairs_, SFX)(distanceToCenters, self->dimension, data + self->dimension * i, 1, (TYPE*)self->centers, self->numCenters, distFn) ; for (k = 0 ; k < self->numCenters ; ++k) { if (distanceToCenters[k] < bestDistance) { bestDistance = distanceToCenters[k] ; assignments[i] = k ; } } if (distances) distances[i] = bestDistance ; } vl_free(distanceToCenters) ; }
VL_EXPORT int vl_pgm_write_f (char const *name, float const* data, int width, int height) { int err = 0 ; int k ; float min = + VL_INFINITY_F ; float max = - VL_INFINITY_F ; float scale ; vl_uint8 * buffer = (vl_uint8*)vl_malloc (sizeof(float) * width * height) ; for (k = 0 ; k < width * height ; ++k) { min = VL_MIN(min, data [k]) ; max = VL_MAX(max, data [k]) ; } scale = 255 / (max - min + VL_EPSILON_F) ; for (k = 0 ; k < width * height ; ++k) { buffer [k] = (vl_uint8) ((data [k] - min) * scale) ; } err = vl_pgm_write (name, buffer, width, height) ; vl_free (buffer) ; return err ; }
void test_query_from_file(int verbose) { VlKDForest *forest; int i; float *data, *query; vl_size dim; vl_size num; /* * load */ data = load_data("data.bin", &dim, &num); forest = load_VlKDForest("forest.bin"); forest->data = data; if((query = (float *)malloc(dim * sizeof(float))) == NULL){ printf("not enough memoey\n"); exit(1); } for(i = 0;i < dim; i++) query[i] = 0.5; if(verbose) printf("has created a query\n"); /* * search neighbors */ vl_size numNeighbors = 10; unsigned int numComparisons = 0 ; unsigned int maxNumComparisons = 0 ; VlKDForestNeighbor * neighbors ; vl_kdforest_set_max_num_comparisons (forest, maxNumComparisons) ; neighbors = vl_malloc (sizeof(VlKDForestNeighbor) * numNeighbors) ; numComparisons = vl_kdforest_query (forest, neighbors, numNeighbors, query); for(i = 0;i < numNeighbors; i++){ printf("%d %f\n", neighbors[i].index + 1, neighbors[i].distance); /* check distance */ if(fabs( dist_l2(dim, query, &data[neighbors[i].index * dim]) - neighbors[i].distance) > 1e-6){ printf("%d distance is different. %f\n", dist_l2(dim, query, &data[neighbors[i].index * dim]) ); } /* check order */ if(i != 0 && neighbors[i-1].distance > neighbors[i].distance){ printf("order is wrong.\n"); } } vl_free(neighbors); vl_kdforest_delete(forest); free(data); free(query); }
static int libvirt_hostlist(hostlist_callback callback, void *arg, void *priv) { struct libvirt_info *info = (struct libvirt_info *)priv; int i; dbg_printf(5, "ENTER %s\n", __FUNCTION__); VALIDATE(info); for (i = 0 ; i < info->vp_count ; i++) { int x; virt_list_t *vl; vl = vl_get(info->vp[i], 1); if (!vl) continue; for (x = 0; x < vl->vm_count; x++) { callback(vl->vm_states[x].v_name, vl->vm_states[x].v_uuid, vl->vm_states[x].v_state.s_state, arg); dbg_printf(10, "[libvirt:HOSTLIST] Sent %s %s %d\n", vl->vm_states[x].v_name, vl->vm_states[x].v_uuid, vl->vm_states[x].v_state.s_state); } vl_free(vl); } return 0; }
void vl_scalespace_delete (VlScaleSpace * self) { if (self) { if (self->octaves) { vl_index o ; for (o = self->geom.firstOctave ; o <= self->geom.lastOctave ; ++o) { if (self->octaves[o - self->geom.firstOctave]) { vl_free(self->octaves[o - self->geom.firstOctave]) ; } } vl_free(self->octaves) ; } vl_free(self) ; } }
static VlHIKMNode * xmeans (VlHIKMTree *tree, vl_uint8 const *data, int N, int K, int height) { VlHIKMNode *node = vl_malloc (sizeof(VlHIKMNode)) ; vl_uint *ids = vl_malloc (sizeof(vl_uint) * N) ; node-> filter = vl_ikm_new (tree -> method) ; node-> children = (height == 1) ? 0 : vl_malloc (sizeof(VlHIKMNode*) * K) ; vl_ikm_set_max_niters (node->filter, tree->max_niters) ; vl_ikm_set_verbosity (node->filter, tree->verb - 1 ) ; vl_ikm_init_rand_data (node->filter, data, tree->M, N, K) ; vl_ikm_train (node->filter, data, N) ; vl_ikm_push (node->filter, ids, data, N) ; /* recurse for each child */ if (height > 1) { int k ; for (k = 0 ; k < K ; k ++) { int partition_N ; int partition_K ; vl_uint8 *partition ; partition = vl_hikm_copy_subset (data, ids, N, tree->M, k, &partition_N) ; partition_K = VL_MIN (K, partition_N) ; node->children [k] = xmeans (tree, partition, partition_N, partition_K, height - 1) ; vl_free (partition) ; if (tree->verb > tree->depth - height) { VL_PRINTF("hikmeans: branch at depth %d: %6.1f %% completed\n", tree->depth - height, (double) (k+1) / K * 100) ; } } } vl_free (ids) ; return node ; }
void vl_hog_delete (VlHog * self) { if (self->orientationX) { vl_free(self->orientationX) ; self->orientationX = NULL ; } if (self->orientationY) { vl_free(self->orientationY) ; self->orientationY = NULL ; } if (self->glyphs) { vl_free(self->glyphs) ; self->glyphs = NULL ; } if (self->permutation) { vl_free(self->permutation) ; self->permutation = NULL ; } if (self->hog) { vl_free(self->hog) ; self->hog = NULL ; } if (self->hogNorm) { vl_free(self->hogNorm) ; self->hogNorm = NULL ; } vl_free(self) ; }
VL_EXPORT void vl_hikm_delete (VlHIKMTree *f) { if (f) { xdelete (f -> root) ; vl_free (f) ; } }
void vl_kdforest_delete (VlKDForest * self) { vl_uindex ti ; VlKDForestSearcher * searcher ; if (self->trees) { for (ti = 0 ; ti < self->numTrees ; ++ ti) { if (self->trees[ti]) { if (self->trees[ti]->nodes) vl_free (self->trees[ti]->nodes) ; if (self->trees[ti]->dataIndex) vl_free (self->trees[ti]->dataIndex) ; vl_free (self->trees[ti]) ; } } vl_free (self->trees) ; } vl_free (self) ; }
void r3d_vl_liopdesc_delete (VlLiopDesc * self) { vl_free (self->neighPermutation) ; vl_free (self->neighIntensities) ; vl_free (self->patchPixels) ; vl_free (self->patchIntensities) ; vl_free (self->patchPermutation) ; vl_free (self->neighSamplesX) ; vl_free (self->neighSamplesY) ; vl_free (self) ; }
VL_EXPORT void vl_array_dealloc (VlArray * self) { if (! self->isEnvelope) { if (self->data) { vl_free(self->data) ; self->data = NULL ; } } }
VL_EXPORT char * vl_configuration_to_string_copy () { char * string = 0 ; int length = 0 ; char * staticString = vl_static_configuration_to_string_copy() ; char * cpuString = #if defined(VL_ARCH_IX86) || defined(VL_ARCH_X64) || defined(VL_ARCH_IA64) _vl_x86cpu_info_to_string_copy(&vl_get_state()->cpuInfo) ; #else "Generic CPU" ; #endif #if defined(DEBUG) int const debug = 1 ; #else int const debug = 0 ; #endif while (string == 0) { if (length > 0) { string = vl_malloc(sizeof(char) * length) ; if (string == NULL) break ; } length = snprintf(string, length, "VLFeat version %s\n" " Static config: %s\n" " %d CPU(s): %s\n" " Debug: %s\n", vl_get_version_string (), staticString, vl_get_num_cpus(), cpuString, VL_YESNO(debug)) ; length += 1 ; } if (staticString) vl_free(staticString) ; if (cpuString) vl_free(cpuString) ; return string ; }
static void _vl_dsift_free_buffers (VlDsiftFilter* self) { if (self->frames) { vl_free(self->frames) ; self->frames = NULL ; } if (self->descrs) { vl_free(self->descrs) ; self->descrs = NULL ; } if (self->grads) { int t ; for (t = 0 ; t < self->numGradAlloc ; ++t) if (self->grads[t]) vl_free(self->grads[t]) ; vl_free(self->grads) ; self->grads = NULL ; } self->numFrameAlloc = 0 ; self->numBinAlloc = 0 ; self->numGradAlloc = 0 ; }
VlScaleSpace * vl_scalespace_new_with_geometry (VlScaleSpaceGeometry geom) { vl_index o ; vl_size numSublevels = geom.octaveLastSubdivision - geom.octaveFirstSubdivision + 1 ; vl_size numOctaves = geom.lastOctave - geom.firstOctave + 1 ; VlScaleSpace *self ; assert(is_valid_geometry(geom)) ; numOctaves = geom.lastOctave - geom.firstOctave + 1 ; numSublevels = geom.octaveLastSubdivision - geom.octaveFirstSubdivision + 1 ; self = vl_calloc(1, sizeof(VlScaleSpace)) ; if (self == NULL) goto err_alloc_self ; self->geom = geom ; self->octaves = vl_calloc(numOctaves, sizeof(float*)) ; if (self->octaves == NULL) goto err_alloc_octave_list ; for (o = self->geom.firstOctave ; o <= self->geom.lastOctave ; ++o) { VlScaleSpaceOctaveGeometry ogeom = vl_scalespace_get_octave_geometry(self,o) ; vl_size octaveSize = ogeom.width * ogeom.height * numSublevels ; self->octaves[o - self->geom.firstOctave] = vl_malloc(octaveSize * sizeof(float)) ; if (self->octaves[o - self->geom.firstOctave] == NULL) goto err_alloc_octaves; } return self ; err_alloc_octaves: for (o = self->geom.firstOctave ; o <= self->geom.lastOctave ; ++o) { if (self->octaves[o - self->geom.firstOctave]) { vl_free(self->octaves[o - self->geom.firstOctave]) ; } } err_alloc_octave_list: vl_free(self) ; err_alloc_self: return NULL ; }
int main (int argc, char** argv) { float * X ; float * Y ; vl_size numDimensions = 1000 ; vl_size numSamples = 2000 ; float * result = vl_malloc (sizeof(float) * numSamples * numSamples) ; VlFloatVectorComparisonFunction f ; init_data (numDimensions, numSamples, &X, &Y) ; X+=1 ; Y+=1 ; vl_set_simd_enabled (VL_FALSE) ; f = vl_get_vector_comparison_function_f (VlDistanceL2) ; vl_tic () ; vl_eval_vector_comparison_on_all_pairs_f (result, numDimensions, X, numSamples, Y, numSamples, f) ; VL_PRINTF("Float L2 distnace: %.3f s\n", vl_toc ()) ; vl_set_simd_enabled (VL_TRUE) ; f = vl_get_vector_comparison_function_f (VlDistanceL2) ; vl_tic () ; vl_eval_vector_comparison_on_all_pairs_f (result, numDimensions, X, numSamples, Y, numSamples, f) ; VL_PRINTF("Float L2 distance (SIMD): %.3f s\n", vl_toc ()) ; X-- ; Y-- ; vl_free (X) ; vl_free (Y) ; vl_free (result) ; return 0 ; }
void vl_svmdataset_set_homogeneous_kernel_map (VlSvmDataset * self, VlHomogeneousKernelMap * hom) { assert(self) ; self->hom = hom ; self->homDimension = 0 ; if (self->homBuffer) { vl_free (self->homBuffer) ; self->homBuffer = 0 ; } if (self->hom) { self->homDimension = vl_homogeneouskernelmap_get_dimension(self->hom) ; self->homBuffer = vl_calloc(self->homDimension, vl_get_type_size(self->dataType)) ; } }
VL_EXPORT int vl_pgm_insert(FILE* f, VlPgmImage const *im, void const *data) { vl_size bpp = vl_pgm_get_bpp (im) ; vl_size data_size = vl_pgm_get_npixels (im) ; size_t c ; VlThreadSpecificState * threadState = vl_get_thread_specific_state() ; /* write preamble */ fprintf(f, "P5\n%d\n%d\n%d\n", (signed)im->width, (signed)im->height, (signed)im->max_value) ; /* take care of endianness */ #if defined(VL_ARCH_LITTLE_ENDIAN) if (bpp == 2) { vl_uindex i ; vl_uint8* temp = (vl_uint8* )vl_malloc (2 * data_size) ; memcpy(temp, data, 2 * data_size) ; for(i = 0 ; i < 2 * data_size ; i += 2) { vl_uint8 tmp = temp [i] ; temp [i] = temp [i+1] ; temp [i+1] = tmp ; } c = fwrite(temp, 2, data_size, f) ; vl_free (temp) ; } else { #endif c = fwrite(data, bpp, data_size, f) ; #if defined(VL_ARCH_LITTLE_ENDIAN) } #endif if(c != data_size) { snprintf(threadState->lastErrorMessage, VL_ERR_MSG_LEN, "Error writing PGM data") ; return (threadState->lastError = VL_ERR_PGM_IO) ; } return 0 ; }