Skip to content

Commit

Permalink
Convert clip_max from static constexpr to const member.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlmelville committed Oct 13, 2018
1 parent c021488 commit 6f9ec0f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/gradient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
// UMAP

umap_gradient::umap_gradient(const double a, const double b, const double gamma) :
a(a), b(b), a_b_m2(-2.0 * a * b), gamma_b_2(2.0 * gamma * b) { }
clip_max(4.0), a(a), b(b), a_b_m2(-2.0 * a * b), gamma_b_2(2.0 * gamma * b)
{ }

// The Python implementation does two pow calls: one for d^b, and one for
// d^(b-1) I have replaced the second call with (d^b) / d, which saves on the
Expand Down Expand Up @@ -73,7 +74,8 @@ double fastPrecisePow(double a, double b) {

// Approximate-Power UMAP: UMAP with an approximation to the slow pow calculation
apumap_gradient::apumap_gradient(const double a, const double b, const double gamma) :
a(a), b(b), a_b_m2(-2.0 * a * b), gamma_b_2(2.0 * gamma * b) { }
clip_max(4.0), a(a), b(b), a_b_m2(-2.0 * a * b), gamma_b_2(2.0 * gamma * b)
{ }

const double apumap_gradient::grad_attr(const double dist_squared) const {
const double pd2b = fastPrecisePow(dist_squared, b);
Expand All @@ -87,7 +89,7 @@ const double apumap_gradient::grad_rep(const double dist_squared) const {

// t-UMAP

tumap_gradient::tumap_gradient() {}
tumap_gradient::tumap_gradient() : clip_max(4.0) {}

const double tumap_gradient::grad_attr(const double dist_squared) const {
return -2.0 / (dist_squared + 1.0);
Expand All @@ -100,7 +102,8 @@ const double tumap_gradient::grad_rep(const double dist_squared) const {

// LargeVis

largevis_gradient::largevis_gradient(const double gamma) : gamma_2(gamma * 2.0) {}
largevis_gradient::largevis_gradient(const double gamma) : clip_max(5.0),
gamma_2(gamma * 2.0) {}

const double largevis_gradient::grad_attr(const double dist_squared) const {
return -2.0 / (dist_squared + 1.0);
Expand Down
12 changes: 8 additions & 4 deletions src/gradient.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class umap_gradient {
umap_gradient(const double a, const double b, const double gamma);
const double grad_attr(const double dist_squared) const;
const double grad_rep(const double dist_squared) const;
static const constexpr double clip_max = 4.0;
// static const constexpr double clip_max = 4.0;
const double clip_max;
private:
const double a;
const double b;
Expand All @@ -41,7 +42,8 @@ class apumap_gradient {
apumap_gradient(const double a, const double b, const double gamma);
const double grad_attr(const double dist_squared) const;
const double grad_rep(const double dist_squared) const;
static const constexpr double clip_max = 4.0;
// static const constexpr double clip_max = 4.0;
const double clip_max;
private:
const double a;
const double b;
Expand All @@ -60,15 +62,17 @@ class tumap_gradient {
tumap_gradient();
const double grad_attr(const double dist_squared) const;
const double grad_rep(const double dist_squared) const;
static const constexpr double clip_max = 4.0;
// static const constexpr double clip_max = 4.0;
const double clip_max;
};

class largevis_gradient {
public:
largevis_gradient(const double gamma);
const double grad_attr(const double dist_squared) const;
const double grad_rep(const double dist_squared) const;
static const constexpr double clip_max = 5.0;
// static const constexpr double clip_max = 5.0;
const double clip_max;

private:
const double gamma_2;
Expand Down

0 comments on commit 6f9ec0f

Please sign in to comment.