Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
63e1ddb
introduce stateful API
May 26, 2021
77a7e1b
add API to free memory, use it
May 26, 2021
1be20c4
safer free_tsne API
May 26, 2021
00bc9fc
fix elapsed time reporting
May 27, 2021
86ba173
fix reviewer comments
May 27, 2021
05be25f
constify all the things
Jun 9, 2021
5bef9a1
use move and rvalue refs for TSNEState initializer
Jun 9, 2021
ae57d41
Update clang-format config to match cellranger.
adam-azarchs Jun 17, 2021
48300a0
clang-tidy google-readability-braces-around-statements
adam-azarchs Jun 17, 2021
68cd3ce
clang-tidy google-readability-casting
adam-azarchs Jun 17, 2021
30422ff
clang-tidy modernize-use-equals-delete
adam-azarchs Jun 17, 2021
ed93c6b
clang-tidy bugprone-reserved-identifier
adam-azarchs Jun 17, 2021
22a0a06
clang-tidy modernize-use-nodiscard
adam-azarchs Jun 17, 2021
6bc1ec3
clang-tidy bugprone-narrowing-conversions and deadcode.
adam-azarchs Jun 17, 2021
2f968b6
clang-tidy: Adjust types and add constructors.
adam-azarchs Jun 17, 2021
101f7b1
clang-tidy readability-isolate-declaration
adam-azarchs Jun 17, 2021
af80d6a
clang-tidy readability-simplify-boolean-expr
adam-azarchs Jun 17, 2021
8910a41
clang-tidy readability-static-definition-in-anonymous-namespace
adam-azarchs Jun 17, 2021
f44c5a4
clang-tidy readability-inconsistent-declaration-parameter-name
adam-azarchs Jun 17, 2021
b6b4f53
clang-tidy readability-redundant-access-specifiers
adam-azarchs Jun 17, 2021
89a3dc8
clang-tidy readability-implicit-bool-conversion
adam-azarchs Jun 17, 2021
91ec292
clang-tidy readability-non-const-parameter
adam-azarchs Jun 17, 2021
b70fe08
Merge #12: Mostly-automatic fixups with clang-tidy.
adam-azarchs Jun 17, 2021
70bb526
hide GCC pragmas behind ifdef __GNUC__
Aug 19, 2021
5f71f74
Merge pull request #13 from 10XDev/lh/vs-fixes
Aug 20, 2021
86beed0
Run clang-tidy --fix with clang15.
adam-azarchs Dec 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Language: Cpp
Language: Cpp
BasedOnStyle: Google
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
PenaltyBreakComment: 100
BinPackArguments: false
BinPackParameters: false
ReflowComments: false
8 changes: 8 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,bugprone-*,cert-*,-cert-msc*,performance-*,modernize-*,-modernize-use-trailing-return-type,google-*,-modernize-avoid-c-arrays,cppcoreguidelines-*,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-pro-*,-cppcoreguidelines-init-*,-cppcoreguidelines-owning-memory,-cppcoreguidelines-avoid-c-arrays,readability-*,-readability-magic-numbers,-readability-function-cognitive-complexity,-readability-function-size,-readability-identifier-naming'
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
FormatStyle: file
...

2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'tsne/bh_sne_src/tsne.cpp', 'tsne/bh_sne.pyx'],
include_dirs=[
numpy.get_include(), 'tsne/bh_sne_src/'],
define_macros=[('BUILDING_TSNE_DLL', None)],
extra_compile_args=extra_compile_args +
['-ffast-math', '-O3', '-std=c++14'],
extra_link_args=['-Wl,-framework',
Expand All @@ -63,6 +64,7 @@
'tsne/bh_sne_src/tsne.cpp', 'tsne/bh_sne.pyx'],
include_dirs=[
numpy.get_include(), 'tsne/bh_sne_src/'],
define_macros=[('BUILDING_TSNE_DLL', None)],
extra_compile_args=opt_flags +
['-Wall', '-fPIC', '-std=c++14', '-w'],
extra_link_args=ldflags,
Expand Down
2 changes: 1 addition & 1 deletion tsne/bh_sne_src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#CFLAGS = -march=haswell -ffast-math -O3

CXX?=g++
CFLAGS?=-ffast-math -O3 -Wall -std=c++14
CFLAGS?=-ffast-math -O3 -Wall -std=c++17

all: bh_tsne

Expand Down
67 changes: 52 additions & 15 deletions tsne/bh_sne_src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,25 @@

#include "tsne.h"

using namespace std;
using std::fclose;
using std::feof;
using std::fprintf;
using std::fread;
using std::vector;

// Function that loads data from a t-SNE file
bool load_data(const char* dat_file, vector<double>* data, int* n, int* d,
int* no_dims, double* theta, double* perplexity, int* rand_seed,
bool load_data(const char* dat_file,
vector<double>* data,
int* n,
int* d,
int* no_dims,
double* theta,
double* perplexity,
int* rand_seed,
int* max_iter) {
// Open file, read first 2 integers, allocate memory, and read the data
FILE* h;
if ((h = fopen(dat_file, "r+b")) == nullptr) {
auto* h = fopen(dat_file, "r+b");
if (h == nullptr) {
fprintf(stderr, "Error: could not open data file.\n");
return false;
}
Expand All @@ -57,16 +67,20 @@ bool load_data(const char* dat_file, vector<double>* data, int* n, int* d,
fread(max_iter, sizeof(int), 1, h); // maximum number of iterations
data->resize(*d * *n);
fread(data->data(), sizeof(double), *n * *d, h); // the data
if (!feof(h))
if (feof(h) == 0) {
fread(rand_seed, sizeof(int), 1, h); // random seed
}
fclose(h);
fprintf(stderr, "Read the %i x %i data matrix successfully!\n", *n, *d);
return true;
}

// Function that saves map to a t-SNE file
void save_data(const char* res_file, const vector<double>& data,
const vector<int>& landmarks, const vector<double>& costs, int n,
void save_data(const char* res_file,
const vector<double>& data,
const vector<int>& landmarks,
const vector<double>& costs,
int n,
int d) {
// Open file, write first 2 integers and then the data
FILE* h;
Expand Down Expand Up @@ -116,25 +130,48 @@ int main(int argc, char* argv[]) {
const char* res_file_c = res_file.c_str();

// Define some variables
int origN, N, D, no_dims, max_iter;
double perplexity, theta;
int origN;
int N;
int D;
int no_dims;
int max_iter;
double perplexity;
double theta;
vector<double> data;
int rand_seed = -1;

// Read the parameters and the dataset
if (load_data(dat_file_c, &data, &origN, &D, &no_dims, &theta, &perplexity,
&rand_seed, &max_iter)) {
if (load_data(dat_file_c,
&data,
&origN,
&D,
&no_dims,
&theta,
&perplexity,
&rand_seed,
&max_iter)) {
// Make dummy landmarks
N = origN;
vector<int> landmarks(N);
for (int n = 0; n < N; n++)
for (int n = 0; n < N; n++) {
landmarks[n] = n;
}

// Now fire up the SNE implementation
vector<double> Y(N * no_dims);
vector<double> costs(N);
run(data.data(), N, D, Y.data(), no_dims, perplexity, theta, rand_seed,
false, nullptr, false, max_iter);
run(data.data(),
N,
D,
Y.data(),
no_dims,
perplexity,
theta,
rand_seed,
false,
nullptr,
false,
max_iter);

// Save the results
save_data(res_file_c, Y, landmarks, costs, N, no_dims);
Expand Down
Loading