From 99e19e236de237afc71ca9313b6625a36a7da42e Mon Sep 17 00:00:00 2001 From: Jesse Krijthe Date: Thu, 1 Nov 2018 17:21:24 +0100 Subject: [PATCH] Addresses some signed vs. unsigned integer warnings --- src/sptree.cpp | 4 +- src/sptree.h | 2 +- src/tsne.cpp | 137 +++++++++++++++++++++++++------------------------ src/tsne.h | 34 ++++++------ src/vptree.h | 2 +- 5 files changed, 90 insertions(+), 89 deletions(-) diff --git a/src/sptree.cpp b/src/sptree.cpp index 6b3d3d2..e2457d1 100644 --- a/src/sptree.cpp +++ b/src/sptree.cpp @@ -396,7 +396,7 @@ double SPTree::computeNonEdgeForces(unsigned int point_index, double thet // Computes edge forces template -void SPTree::computeEdgeForces(unsigned int* row_P, unsigned int* col_P, double* val_P, int N, double* pos_f, int num_threads) const +void SPTree::computeEdgeForces(unsigned int* row_P, unsigned int* col_P, double* val_P, unsigned int N, double* pos_f, int num_threads) const { // Loop over all edges in the graph @@ -436,7 +436,7 @@ void SPTree::print() if(is_leaf) { Rprintf("Leaf node; data = ["); - for(int i = 0; i < size; i++) { + for(unsigned int i = 0; i < size; i++) { double* point = data + index[i] * NDims; for(int d = 0; d < NDims; d++) Rprintf("%f, ", point[d]); Rprintf(" (index = %d)", index[i]); diff --git a/src/sptree.h b/src/sptree.h index 09eed36..6c8f73a 100644 --- a/src/sptree.h +++ b/src/sptree.h @@ -101,7 +101,7 @@ class SPTree void getAllIndices(unsigned int* indices); unsigned int getDepth(); double computeNonEdgeForces(unsigned int point_index, double theta, double neg_f[]) const; - void computeEdgeForces(unsigned int* row_P, unsigned int* col_P, double* val_P, int N, double* pos_f, int num_threads) const; + void computeEdgeForces(unsigned int* row_P, unsigned int* col_P, double* val_P, unsigned int N, double* pos_f, int num_threads) const; void print(); private: diff --git a/src/tsne.cpp b/src/tsne.cpp index e2db064..3636cab 100644 --- a/src/tsne.cpp +++ b/src/tsne.cpp @@ -77,7 +77,7 @@ TSNE::TSNE(double Perplexity, double Theta, bool Verbose, int Max_iter, b // Perform t-SNE template -void TSNE::run(double* X, int N, int D, double* Y, bool distance_precomputed, double* cost, double* itercost) { +void TSNE::run(double* X, unsigned int N, int D, double* Y, bool distance_precomputed, double* cost, double* itercost) { if(N - 1 < 3 * perplexity) { Rcpp::stop("Perplexity too large for the number of data points!\n"); } if (verbose) Rprintf("Using no_dims = %d, perplexity = %f, and theta = %f\n", NDims, perplexity, theta); if (verbose) Rprintf("Computing input similarities...\n"); @@ -116,8 +116,8 @@ void TSNE::run(double* X, int N, int D, double* Y, bool distance_precompu // Symmetrize input similarities symmetrizeMatrix(N); double sum_P = .0; - for(int i = 0; i < row_P[N]; i++) sum_P += val_P[i]; - for(int i = 0; i < row_P[N]; i++) val_P[i] /= sum_P; + for(unsigned int i = 0; i < row_P[N]; i++) sum_P += val_P[i]; + for(unsigned int i = 0; i < row_P[N]; i++) val_P[i] /= sum_P; } if (verbose) { @@ -132,7 +132,7 @@ void TSNE::run(double* X, int N, int D, double* Y, bool distance_precompu // Perform t-SNE with nearest neighbor results. template -void TSNE::run(const int* nn_index, const double* nn_dist, int N, int K, double* Y, double* cost, double* itercost) { +void TSNE::run(const int* nn_index, const double* nn_dist, unsigned int N, int K, double* Y, double* cost, double* itercost) { if(N - 1 < 3 * perplexity) { Rcpp::stop("Perplexity too large for the number of data points!\n"); } if (verbose) Rprintf("Using no_dims = %d, perplexity = %f, and theta = %f\n", NDims, perplexity, theta); if (verbose) Rprintf("Computing input similarities...\n"); @@ -144,8 +144,8 @@ void TSNE::run(const int* nn_index, const double* nn_dist, int N, int K, // Symmetrize input similarities symmetrizeMatrix(N); double sum_P = .0; - for(int i = 0; i < row_P[N]; i++) sum_P += val_P[i]; - for(int i = 0; i < row_P[N]; i++) val_P[i] /= sum_P; + for(unsigned int i = 0; i < row_P[N]; i++) sum_P += val_P[i]; + for(unsigned int i = 0; i < row_P[N]; i++) val_P[i] /= sum_P; if (verbose) { clock_t end = clock(); @@ -159,21 +159,21 @@ void TSNE::run(const int* nn_index, const double* nn_dist, int N, int K, // Perform main training loop template -void TSNE::trainIterations(int N, double* Y, double* cost, double* itercost) { +void TSNE::trainIterations(unsigned int N, double* Y, double* cost, double* itercost) { // Allocate some memory double* dY = (double*) malloc(N * NDims * sizeof(double)); double* uY = (double*) malloc(N * NDims * sizeof(double)); double* gains = (double*) malloc(N * NDims * sizeof(double)); if(dY == NULL || uY == NULL || gains == NULL) { Rcpp::stop("Memory allocation failed!\n"); } - for(int i = 0; i < N * NDims; i++) uY[i] = .0; - for(int i = 0; i < N * NDims; i++) gains[i] = 1.0; + for(unsigned int i = 0; i < N * NDims; i++) uY[i] = .0; + for(unsigned int i = 0; i < N * NDims; i++) gains[i] = 1.0; // Lie about the P-values - if(exact) { for(unsigned long i = 0; i < (long)N * N; i++) P[i] *= exaggeration_factor; } + if(exact) { for(unsigned long i = 0; i < (unsigned long)N * N; i++) P[i] *= exaggeration_factor; } else { for(unsigned long i = 0; i < row_P[N]; i++) val_P[i] *= exaggeration_factor; } // Initialize solution (randomly), if not already done - if (!init) { for(int i = 0; i < N * NDims; i++) Y[i] = randn() * .0001; } + if (!init) { for(unsigned int i = 0; i < N * NDims; i++) Y[i] = randn() * .0001; } clock_t start = clock(), end; float total_time=0; @@ -183,8 +183,8 @@ void TSNE::trainIterations(int N, double* Y, double* cost, double* iterco // Stop lying about the P-values after a while, and switch momentum if(iter == stop_lying_iter) { - if(exact) { for(unsigned long i = 0; i < (long)N * N; i++) P[i] /= exaggeration_factor; } - else { for(int i = 0; i < row_P[N]; i++) val_P[i] /= exaggeration_factor; } + if(exact) { for(unsigned long i = 0; i < (unsigned long)N * N; i++) P[i] /= exaggeration_factor; } + else { for(unsigned int i = 0; i < row_P[N]; i++) val_P[i] /= exaggeration_factor; } } if(iter == mom_switch_iter) momentum = final_momentum; @@ -193,12 +193,12 @@ void TSNE::trainIterations(int N, double* Y, double* cost, double* iterco else computeGradient(P.data(), row_P.data(), col_P.data(), val_P.data(), Y, N, NDims, dY, theta); // Update gains - for(int i = 0; i < N * NDims; i++) gains[i] = (sign_tsne(dY[i]) != sign_tsne(uY[i])) ? (gains[i] + .2) : (gains[i] * .8); - for(int i = 0; i < N * NDims; i++) if(gains[i] < .01) gains[i] = .01; + for(unsigned int i = 0; i < N * NDims; i++) gains[i] = (sign_tsne(dY[i]) != sign_tsne(uY[i])) ? (gains[i] + .2) : (gains[i] * .8); + for(unsigned int i = 0; i < N * NDims; i++) if(gains[i] < .01) gains[i] = .01; // Perform gradient update (with momentum and gains) - for(int i = 0; i < N * NDims; i++) uY[i] = momentum * uY[i] - eta * gains[i] * dY[i]; - for(int i = 0; i < N * NDims; i++) Y[i] = Y[i] + uY[i]; + for(unsigned int i = 0; i < N * NDims; i++) uY[i] = momentum * uY[i] - eta * gains[i] * dY[i]; + for(unsigned int i = 0; i < N * NDims; i++) Y[i] = Y[i] + uY[i]; // Make solution zero-mean zeroMean(Y, N, NDims); @@ -236,7 +236,7 @@ void TSNE::trainIterations(int N, double* Y, double* cost, double* iterco // Compute gradient of the t-SNE cost function (using Barnes-Hut algorithm) template -void TSNE::computeGradient(double* P, unsigned int* inp_row_P, unsigned int* inp_col_P, double* inp_val_P, double* Y, int N, int D, double* dC, double theta) +void TSNE::computeGradient(double* P, unsigned int* inp_row_P, unsigned int* inp_col_P, double* inp_val_P, double* Y, unsigned int N, int D, double* dC, double theta) { // Construct space-partitioning tree on current map SPTree* tree = new SPTree(Y, N); @@ -251,17 +251,17 @@ void TSNE::computeGradient(double* P, unsigned int* inp_row_P, unsigned i std::vector output(N); #pragma omp parallel for schedule(guided) num_threads(num_threads) - for (int n = 0; n < N; n++) { + for (unsigned int n = 0; n < N; n++) { output[n]=tree->computeNonEdgeForces(n, theta, neg_f + n * D); } double sum_Q = .0; - for (int n=0; n::computeGradient(double* P, unsigned int* inp_row_P, unsigned i // Compute gradient of the t-SNE cost function (exact) template -void TSNE::computeExactGradient(double* P, double* Y, int N, int D, double* dC) { +void TSNE::computeExactGradient(double* P, double* Y, unsigned int N, int D, double* dC) { // Make sure the current gradient contains zeros - for(int i = 0; i < N * D; i++) dC[i] = 0.0; + for(unsigned int i = 0; i < N * D; i++) dC[i] = 0.0; // Compute the squared Euclidean distance matrix - double* DD = (double*) malloc((long)N * N * sizeof(double)); + double* DD = (double*) malloc((unsigned long)N * N * sizeof(double)); if(DD == NULL) { Rcpp::stop("Memory allocation failed!\n"); } computeSquaredEuclideanDistance(Y, N, D, DD); // Compute Q-matrix and normalization sum - double* Q = (double*) malloc((long)N * N * sizeof(double)); + double* Q = (double*) malloc((unsigned long)N * N * sizeof(double)); if(Q == NULL) { Rcpp::stop("Memory allocation failed!\n"); } double sum_Q = .0; for(unsigned long n = 0; n < N; n++) { @@ -315,11 +315,11 @@ void TSNE::computeExactGradient(double* P, double* Y, int N, int D, doubl // Evaluate t-SNE cost function (exactly) template -double TSNE::evaluateError(double* P, double* Y, int N, int D) { +double TSNE::evaluateError(double* P, double* Y, unsigned int N, int D) { // Compute the squared Euclidean distance matrix - double* DD = (double*) malloc((long)N * N * sizeof(double)); - double* Q = (double*) malloc((long)N * N * sizeof(double)); + double* DD = (double*) malloc((unsigned long)N * N * sizeof(double)); + double* Q = (double*) malloc((unsigned long)N * N * sizeof(double)); if(DD == NULL || Q == NULL) { Rcpp::stop("Memory allocation failed!\n"); } computeSquaredEuclideanDistance(Y, N, D, DD); @@ -334,7 +334,7 @@ double TSNE::evaluateError(double* P, double* Y, int N, int D) { else Q[n * N + m] = DBL_MIN; } } - for(unsigned long i = 0; i < (long)N * N; i++) Q[i] /= sum_Q; + for(unsigned long i = 0; i < (unsigned long)N * N; i++) Q[i] /= sum_Q; // Sum t-SNE error double C = .0; @@ -352,21 +352,21 @@ double TSNE::evaluateError(double* P, double* Y, int N, int D) { // Evaluate t-SNE cost function (approximately) template -double TSNE::evaluateError(unsigned int* row_P, unsigned int* col_P, double* val_P, double* Y, int N, int D, double theta) +double TSNE::evaluateError(unsigned int* row_P, unsigned int* col_P, double* val_P, double* Y, unsigned int N, int D, double theta) { // Get estimate of normalization term SPTree* tree = new SPTree(Y, N); double* buff = (double*) calloc(D, sizeof(double)); double sum_Q = .0; - for(int n = 0; n < N; n++) sum_Q += tree->computeNonEdgeForces(n, theta, buff); + for(unsigned int n = 0; n < N; n++) sum_Q += tree->computeNonEdgeForces(n, theta, buff); // Loop over all edges to compute t-SNE error int ind1, ind2; double C = .0, Q; - for(int n = 0; n < N; n++) { + for(unsigned int n = 0; n < N; n++) { ind1 = n * D; - for(int i = row_P[n]; i < row_P[n + 1]; i++) { + for(unsigned int i = row_P[n]; i < row_P[n + 1]; i++) { Q = .0; ind2 = col_P[i] * D; for(int d = 0; d < D; d++) buff[d] = Y[ind1 + d]; @@ -385,11 +385,11 @@ double TSNE::evaluateError(unsigned int* row_P, unsigned int* col_P, doub // Evaluate t-SNE cost function (exactly) template -void TSNE::getCost(double* P, double* Y, int N, int D, double* costs) { +void TSNE::getCost(double* P, double* Y, unsigned int N, int D, double* costs) { // Compute the squared Euclidean distance matrix - double* DD = (double*) malloc((long)N * N * sizeof(double)); - double* Q = (double*) malloc((long)N * N * sizeof(double)); + double* DD = (double*) malloc((unsigned long)N * N * sizeof(double)); + double* Q = (double*) malloc((unsigned long)N * N * sizeof(double)); if(DD == NULL || Q == NULL) { Rcpp::stop("Memory allocation failed!\n"); } computeSquaredEuclideanDistance(Y, N, D, DD); @@ -404,7 +404,7 @@ void TSNE::getCost(double* P, double* Y, int N, int D, double* costs) { else Q[n * N + m] = DBL_MIN; } } - for(unsigned long i = 0; i < (long)N * N; i++) Q[i] /= sum_Q; + for(unsigned long i = 0; i < (unsigned long)N * N; i++) Q[i] /= sum_Q; // Sum t-SNE error for(unsigned long n = 0; n < N; n++) { @@ -421,22 +421,22 @@ void TSNE::getCost(double* P, double* Y, int N, int D, double* costs) { // Evaluate t-SNE cost function (approximately) template -void TSNE::getCost(unsigned int* row_P, unsigned int* col_P, double* val_P, double* Y, int N, int D, double theta, double* costs) +void TSNE::getCost(unsigned int* row_P, unsigned int* col_P, double* val_P, double* Y, unsigned int N, int D, double theta, double* costs) { // Get estimate of normalization term SPTree* tree = new SPTree(Y, N); double* buff = (double*) calloc(D, sizeof(double)); double sum_Q = .0; - for(int n = 0; n < N; n++) sum_Q += tree->computeNonEdgeForces(n, theta, buff); + for(unsigned int n = 0; n < N; n++) sum_Q += tree->computeNonEdgeForces(n, theta, buff); // Loop over all edges to compute t-SNE error int ind1, ind2; double Q; - for(int n = 0; n < N; n++) { + for(unsigned int n = 0; n < N; n++) { ind1 = n * D; costs[n] = 0.0; - for(int i = row_P[n]; i < row_P[n + 1]; i++) { + for(unsigned int i = row_P[n]; i < row_P[n + 1]; i++) { Q = .0; ind2 = col_P[i] * D; for(int d = 0; d < D; d++) buff[d] = Y[ind1 + d]; @@ -455,7 +455,7 @@ void TSNE::getCost(unsigned int* row_P, unsigned int* col_P, double* val_ // Compute input similarities with a fixed perplexity template -void TSNE::computeGaussianPerplexity(double* X, int N, int D, bool distance_precomputed) { +void TSNE::computeGaussianPerplexity(double* X, unsigned int N, int D, bool distance_precomputed) { size_t N2=N; N2*=N; P.resize(N2); @@ -540,7 +540,7 @@ void TSNE::computeGaussianPerplexity(double* X, int N, int D, bool distan // Compute input similarities with a fixed perplexity using ball trees (this function allocates memory another function should free) template template -void TSNE::computeGaussianPerplexity(double* X, int N, int D, int K) { +void TSNE::computeGaussianPerplexity(double* X, unsigned int N, int D, int K) { if(perplexity > K) Rprintf("Perplexity should be lower than K!\n"); @@ -550,7 +550,7 @@ void TSNE::computeGaussianPerplexity(double* X, int N, int D, int K) { // Build ball tree on data set VpTree* tree = new VpTree(); vector obj_X(N, DataPoint(D, -1, X)); - for(int n = 0; n < N; n++) obj_X[n] = DataPoint(D, n, X + n * D); + for(unsigned int n = 0; n < N; n++) obj_X[n] = DataPoint(D, n, X + n * D); tree->create(obj_X); // Loop over all points to find nearest neighbors @@ -558,7 +558,7 @@ void TSNE::computeGaussianPerplexity(double* X, int N, int D, int K) { int steps_completed = 0; #pragma omp parallel for schedule(guided) num_threads(num_threads) - for(int n = 0; n < N; n++) { + for(unsigned int n = 0; n < N; n++) { vector indices; vector distances; @@ -591,7 +591,7 @@ void TSNE::computeGaussianPerplexity(double* X, int N, int D, int K) { // Compute input similarities with a fixed perplexity from nearest-neighbour results. template -void TSNE::computeGaussianPerplexity(const int* nn_idx, const double* nn_dist, int N, int K) { +void TSNE::computeGaussianPerplexity(const int* nn_idx, const double* nn_dist, unsigned int N, int K) { if(perplexity > K) Rprintf("Perplexity should be lower than K!\n"); @@ -601,7 +601,7 @@ void TSNE::computeGaussianPerplexity(const int* nn_idx, const double* nn_ // Loop over all points to find nearest neighbors int steps_completed = 0; #pragma omp parallel for schedule(guided) num_threads(num_threads) - for(int n = 0; n < N; n++) { + for(unsigned int n = 0; n < N; n++) { double * cur_P = val_P.data() + row_P[n]; computeProbabilities(perplexity, K, nn_dist + row_P[n], cur_P); @@ -621,12 +621,12 @@ void TSNE::computeGaussianPerplexity(const int* nn_idx, const double* nn_ } template -void TSNE::setupApproximateMemory(int N, int K) { +void TSNE::setupApproximateMemory(unsigned int N, int K) { row_P.resize(N+1); col_P.resize(N*K); val_P.resize(N*K); row_P[0] = 0; - for(int n = 0; n < N; n++) row_P[n + 1] = row_P[n] + K; + for(unsigned int n = 0; n < N; n++) row_P[n + 1] = row_P[n] + K; return; } @@ -681,23 +681,23 @@ void TSNE::computeProbabilities (const double perplexity, const int K, co } // Row-normalize current row of P. - for(unsigned int m = 0; m < K; m++) { + for(int m = 0; m < K; m++) { cur_P[m] /= sum_P; } return; } template -void TSNE::symmetrizeMatrix(int N) { +void TSNE::symmetrizeMatrix(unsigned int N) { // Count number of elements and row counts of symmetric matrix int* row_counts = (int*) calloc(N, sizeof(int)); if(row_counts == NULL) { Rcpp::stop("Memory allocation failed!\n"); } - for(int n = 0; n < N; n++) { - for(int i = row_P[n]; i < row_P[n + 1]; i++) { + for(unsigned int n = 0; n < N; n++) { + for(unsigned int i = row_P[n]; i < row_P[n + 1]; i++) { // Check whether element (col_P[i], n) is present bool present = false; - for(int m = row_P[col_P[i]]; m < row_P[col_P[i] + 1]; m++) { + for(unsigned int m = row_P[col_P[i]]; m < row_P[col_P[i] + 1]; m++) { if(col_P[m] == n) present = true; } if(present) row_counts[n]++; @@ -708,7 +708,7 @@ void TSNE::symmetrizeMatrix(int N) { } } int no_elem = 0; - for(int n = 0; n < N; n++) no_elem += row_counts[n]; + for(unsigned int n = 0; n < N; n++) no_elem += row_counts[n]; // Allocate memory for symmetrized matrix std::vector sym_row_P(N+1), sym_col_P(no_elem); @@ -716,17 +716,17 @@ void TSNE::symmetrizeMatrix(int N) { // Construct new row indices for symmetric matrix sym_row_P[0] = 0; - for(int n = 0; n < N; n++) sym_row_P[n + 1] = sym_row_P[n] + row_counts[n]; + for(unsigned int n = 0; n < N; n++) sym_row_P[n + 1] = sym_row_P[n] + row_counts[n]; // Fill the result matrix int* offset = (int*) calloc(N, sizeof(int)); if(offset == NULL) { Rcpp::stop("Memory allocation failed!\n"); } - for(int n = 0; n < N; n++) { - for(int i = row_P[n]; i < row_P[n + 1]; i++) { // considering element(n, col_P[i]) + for(unsigned int n = 0; n < N; n++) { + for(unsigned int i = row_P[n]; i < row_P[n + 1]; i++) { // considering element(n, col_P[i]) // Check whether element (col_P[i], n) is present bool present = false; - for(int m = row_P[col_P[i]]; m < row_P[col_P[i] + 1]; m++) { + for(unsigned int m = row_P[col_P[i]]; m < row_P[col_P[i] + 1]; m++) { if(col_P[m] == n) { present = true; if(n <= col_P[i]) { // make sure we do not add elements twice @@ -769,10 +769,10 @@ void TSNE::symmetrizeMatrix(int N) { // Compute squared Euclidean distance matrix (using BLAS) template -void TSNE::computeSquaredEuclideanDistance(double* X, int N, int D, double* DD) { +void TSNE::computeSquaredEuclideanDistance(double* X, unsigned int N, int D, double* DD) { double* dataSums = (double*) calloc(N, sizeof(double)); if(dataSums == NULL) { Rcpp::stop("Memory allocation failed!\n"); } - for(int n = 0; n < N; n++) { + for(unsigned int n = 0; n < N; n++) { for(int d = 0; d < D; d++) { dataSums[n] += (X[n * D + d] * X[n * D + d]); } @@ -784,20 +784,21 @@ void TSNE::computeSquaredEuclideanDistance(double* X, int N, int D, doubl } double a1 = -2.0; double a2 = 1.0; - dgemm_("T", "N", &N, &N, &D, &a1, X, &D, X, &D, &a2, DD, &N); + int Nsigned = N; + dgemm_("T", "N", &Nsigned, &Nsigned, &D, &a1, X, &D, X, &D, &a2, DD, &Nsigned); free(dataSums); dataSums = NULL; } // Compute squared Euclidean distance matrix (No BLAS) template -void TSNE::computeSquaredEuclideanDistanceDirect(double* X, int N, int D, double* DD) { +void TSNE::computeSquaredEuclideanDistanceDirect(double* X, unsigned int N, int D, double* DD) { const double* XnD = X; - for(int n = 0; n < N; ++n, XnD += D) { + for(unsigned int n = 0; n < N; ++n, XnD += D) { const double* XmD = XnD + D; double* curr_elem = &DD[n*N + n]; *curr_elem = 0.0; double* curr_elem_sym = curr_elem + N; - for(int m = n + 1; m < N; ++m, XmD+=D, curr_elem_sym+=N) { + for(unsigned int m = n + 1; m < N; ++m, XmD+=D, curr_elem_sym+=N) { *(++curr_elem) = 0.0; for(int d = 0; d < D; ++d) { *curr_elem += (XnD[d] - XmD[d]) * (XnD[d] - XmD[d]); @@ -810,13 +811,13 @@ void TSNE::computeSquaredEuclideanDistanceDirect(double* X, int N, int D, // Makes data zero-mean template -void TSNE::zeroMean(double* X, int N, int D) { +void TSNE::zeroMean(double* X, unsigned int N, int D) { // Compute data mean double* mean = (double*) calloc(D, sizeof(double)); if(mean == NULL) { Rcpp::stop("Memory allocation failed!\n"); } int nD = 0; - for(int n = 0; n < N; n++) { + for(unsigned int n = 0; n < N; n++) { for(int d = 0; d < D; d++) { mean[d] += X[nD + d]; } @@ -828,7 +829,7 @@ void TSNE::zeroMean(double* X, int N, int D) { // Subtract data mean nD = 0; - for(int n = 0; n < N; n++) { + for(unsigned int n = 0; n < N; n++) { for(int d = 0; d < D; d++) { X[nD + d] -= mean[d]; } diff --git a/src/tsne.h b/src/tsne.h index 3583f6e..8ed462c 100644 --- a/src/tsne.h +++ b/src/tsne.h @@ -46,30 +46,30 @@ class TSNE TSNE(double perplexity, double theta, bool verbose, int max_iter, bool init, int stop_lying_iter, int mom_switch_iter, double momentum, double final_momentum, double eta, double exaggeration_factor,int num_threads); - void run(double* X, int N, int D, double* Y, bool distance_precomputed, double* cost, double* itercost); - void run(const int* nn_index, const double* nn_dist, int N, int K, double* Y, double* cost, double* itercost); + void run(double* X, unsigned int N, int D, double* Y, bool distance_precomputed, double* cost, double* itercost); + void run(const int* nn_index, const double* nn_dist, unsigned int N, int K, double* Y, double* cost, double* itercost); private: - void symmetrizeMatrix(int N); - void trainIterations(int N, double* Y, double* cost, double* itercost); + void symmetrizeMatrix(unsigned int N); + void trainIterations(unsigned int N, double* Y, double* cost, double* itercost); - void computeGradient(double* P, unsigned int* inp_row_P, unsigned int* inp_col_P, double* inp_val_P, double* Y, int N, int D, double* dC, double theta); - void computeExactGradient(double* P, double* Y, int N, int D, double* dC); - double evaluateError(double* P, double* Y, int N, int D); - double evaluateError(unsigned int* row_P, unsigned int* col_P, double* val_P, double* Y, int N, int D, double theta); - void getCost(double* P, double* Y, int N, int D, double* costs); - void getCost(unsigned int* row_P, unsigned int* col_P, double* val_P, double* Y, int N, int D, double theta, double* costs); - void zeroMean(double* X, int N, int D); + void computeGradient(double* P, unsigned int* inp_row_P, unsigned int* inp_col_P, double* inp_val_P, double* Y, unsigned int N, int D, double* dC, double theta); + void computeExactGradient(double* P, double* Y, unsigned int N, int D, double* dC); + double evaluateError(double* P, double* Y, unsigned int N, int D); + double evaluateError(unsigned int* row_P, unsigned int* col_P, double* val_P, double* Y, unsigned int N, int D, double theta); + void getCost(double* P, double* Y, unsigned int N, int D, double* costs); + void getCost(unsigned int* row_P, unsigned int* col_P, double* val_P, double* Y, unsigned int N, int D, double theta, double* costs); + void zeroMean(double* X, unsigned int N, int D); - void computeGaussianPerplexity(double* X, int N, int D, bool distance_precomputed); + void computeGaussianPerplexity(double* X, unsigned int N, int D, bool distance_precomputed); template - void computeGaussianPerplexity(double* X, int N, int D, int K); - void computeGaussianPerplexity(const int* nn_dex, const double* nn_dist, int N, int K); - void setupApproximateMemory(int N, int K); + void computeGaussianPerplexity(double* X, unsigned int N, int D, int K); + void computeGaussianPerplexity(const int* nn_dex, const double* nn_dist, unsigned int N, int K); + void setupApproximateMemory(unsigned int N, int K); void computeProbabilities(const double perplexity, const int K, const double* distances, double* cur_P); - void computeSquaredEuclideanDistance(double* X, int N, int D, double* DD); - void computeSquaredEuclideanDistanceDirect(double* X, int N, int D, double* DD); + void computeSquaredEuclideanDistance(double* X, unsigned int N, int D, double* DD); + void computeSquaredEuclideanDistanceDirect(double* X, unsigned int N, int D, double* DD); double randn(); diff --git a/src/vptree.h b/src/vptree.h index a8e5ab7..7258765 100644 --- a/src/vptree.h +++ b/src/vptree.h @@ -185,7 +185,7 @@ class VpTree } // Helper function that searches the tree - void search(Node* node, const T& target, int k, std::priority_queue& heap, double* ptau) + void search(Node* node, const T& target, unsigned int k, std::priority_queue& heap, double* ptau) { if(node == NULL) return; // indicates that we're done here