Skip to content

Commit 9f3a54a

Browse files
committed
Use std::optional to represent unset a/b options.
This is more self-documenting than a sentinel value of zero.
1 parent 2b57cba commit 9f3a54a

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

include/umappp/Options.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ struct Options {
6868
* Positive value for the \f$a\f$ parameter for the fuzzy set membership strength calculations.
6969
* Larger values yield a sharper decay in membership strength with increasing distance between observations.
7070
*
71-
* If this or `Options::b` is set to zero, a suitable value for this parameter is automatically determined from `Options::spread` and `Options::min_dist`.
71+
* If this or `Options::b` are unset, a suitable value for this parameter is automatically determined from `Options::spread` and `Options::min_dist`.
7272
*/
73-
double a = 0;
73+
std::optional<double> a;
7474

7575
/**
7676
* Value in \f$(0, 1)\f$ for the \f$b\f$ parameter for the fuzzy set membership strength calculations.
7777
* Larger values yield an earlier decay in membership strength with increasing distance between observations.
7878
*
79-
* If this or `Options::a` is set to zero, a suitable value for this parameter is automatically determined from `Options::spread` and `Options::min_dist`.
79+
* If this or `Options::a` are unset, a suitable value for this parameter is automatically determined from `Options::spread` and `Options::min_dist`.
8080
*/
81-
double b = 0;
81+
std::optional<double> b;
8282

8383
/**
8484
* Modifier for the repulsive force.

include/umappp/Status.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ class Status {
104104
my_num_dim,
105105
embedding,
106106
my_epochs,
107-
my_options.a,
108-
my_options.b,
107+
*(my_options.a),
108+
*(my_options.b),
109109
my_options.repulsion_strength,
110110
my_options.learning_rate,
111111
my_engine,
@@ -116,8 +116,8 @@ class Status {
116116
my_num_dim,
117117
embedding,
118118
my_epochs,
119-
my_options.a,
120-
my_options.b,
119+
*(my_options.a),
120+
*(my_options.b),
121121
my_options.repulsion_strength,
122122
my_options.learning_rate,
123123
my_engine,

include/umappp/initialize.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Status<Index_, Float_> initialize(NeighborList<Index_, Float_> x, const std::siz
107107
}
108108

109109
// Finding a good a/b pair.
110-
if (options.a <= 0 || options.b <= 0) {
110+
if (!options.a.has_value() || !options.b.has_value()) {
111111
const auto found = internal::find_ab(options.spread, options.min_dist);
112112
options.a = found.first;
113113
options.b = found.second;

0 commit comments

Comments
 (0)