Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default method precision to fp32, and add explicit _fp64 equivalent #20

Merged
merged 2 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 10 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,35 @@ jobs:
./compare_unifrac_matrix.py test500.weighted_unnormalized_fp32.h5 t1.h5 1.e-5
./compare_unifrac_pcoa.py test500.weighted_unnormalized_fp32.h5 t1.h5 3 0.1
rm -f t1.h5
# retry with default precision handling
time ssu -m weighted_unnormalized -i test500.biom -t test500.tre --pcoa 4 -r hdf5 -o t1.h5
./compare_unifrac_matrix.py test500.weighted_unnormalized_fp32.h5 t1.h5 1.e-5
./compare_unifrac_pcoa.py test500.weighted_unnormalized_fp32.h5 t1.h5 3 0.1
rm -f t1.h5
time ssu -f -m weighted_unnormalized_fp32 -i test500.biom -t test500.tre --pcoa 4 -r hdf5_fp32 -o t1.h5
# matrrix will be different, but PCOA similar
./compare_unifrac_pcoa.py test500.weighted_unnormalized_fp32.h5 t1.h5 3 0.1
rm -f t1.h5
time ssu -m weighted_unnormalized -i test500.biom -t test500.tre --pcoa 4 -r hdf5_fp64 -o t1.h5
time ssu -m weighted_unnormalized_fp64 -i test500.biom -t test500.tre --pcoa 4 -r hdf5_fp64 -o t1.h5
# minimal precision loss between fp32 and fp64
./compare_unifrac_matrix.py test500.weighted_unnormalized_fp32.h5 t1.h5 1.e-5
./compare_unifrac_pcoa.py test500.weighted_unnormalized_fp32.h5 t1.h5 3 0.1
rm -f t1.h5
# weighted_normalized
time ssu -f -m weighted_normalized_fp32 -i test500.biom -t test500.tre --pcoa 4 -r hdf5_fp32 -o t1.h5
time ssu -f -m weighted_normalized -i test500.biom -t test500.tre --pcoa 4 -r hdf5_fp32 -o t1.h5
./compare_unifrac_matrix.py test500.weighted_normalized_fp32.f.h5 t1.h5 1.e-5
./compare_unifrac_pcoa.py test500.weighted_normalized_fp32.f.h5 t1.h5 3 0.1
rm -f t1.h5
time ssu -f -m weighted_normalized -i test500.biom -t test500.tre --pcoa 4 -r hdf5_fp64 -o t1.h5
time ssu -f -m weighted_normalized_fp64 -i test500.biom -t test500.tre --pcoa 4 -r hdf5_fp64 -o t1.h5
./compare_unifrac_matrix.py test500.weighted_normalized_fp32.f.h5 t1.h5 1.e-5
./compare_unifrac_pcoa.py test500.weighted_normalized_fp32.f.h5 t1.h5 3 0.1
rm -f t1.h5
# unweighted
time ssu -f -m unweighted_fp32 -i test500.biom -t test500.tre --pcoa 4 -r hdf5_fp32 -o t1.h5
time ssu -f -m unweighted -i test500.biom -t test500.tre --pcoa 4 -r hdf5_fp32 -o t1.h5
./compare_unifrac_matrix.py test500.unweighted_fp32.f.h5 t1.h5 1.e-5
./compare_unifrac_pcoa.py test500.unweighted_fp32.f.h5 t1.h5 3 0.1
rm -f t1.h5
time ssu -f -m unweighted -i test500.biom -t test500.tre --pcoa 4 -r hdf5_fp64 -o t1.h5
time ssu -f -m unweighted_fp64 -i test500.biom -t test500.tre --pcoa 4 -r hdf5_fp64 -o t1.h5
./compare_unifrac_matrix.py test500.unweighted_fp32.f.h5 t1.h5 1.e-5
./compare_unifrac_pcoa.py test500.unweighted_fp32.f.h5 t1.h5 3 0.1
rm -f t1.h5
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ The methods can be used directly through the command line after install:
-i The input BIOM table.
-t The input phylogeny in newick.
-m The method, [unweighted | weighted_normalized | weighted_unnormalized | generalized |
unweighted_fp64 | weighted_normalized_fp64 | weighted_unnormalized_fp64 | generalized_fp64 |
unweighted_fp32 | weighted_normalized_fp32 | weighted_unnormalized_fp32 | generalized_fp32].
-o The output distance matrix.
-a [OPTIONAL] Generalized UniFrac alpha, default is 1.
Expand Down
32 changes: 21 additions & 11 deletions src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,23 @@
return err; \
}

#define SET_METHOD(requested_method, err) Method method; \
if(std::strcmp(requested_method, "unweighted") == 0) \
method = unweighted; \
else if(std::strcmp(requested_method, "weighted_normalized") == 0) \
method = weighted_normalized; \
else if(std::strcmp(requested_method, "weighted_unnormalized") == 0) \
method = weighted_unnormalized; \
else if(std::strcmp(requested_method, "generalized") == 0) \
method = generalized; \
#define SET_METHOD(requested_method, err) Method method; \
if(std::strcmp(requested_method, "unweighted") == 0) \
method = unweighted_fp32; \
else if(std::strcmp(requested_method, "weighted_normalized") == 0) \
method = weighted_normalized_fp32; \
else if(std::strcmp(requested_method, "weighted_unnormalized") == 0) \
method = weighted_unnormalized_fp32; \
else if(std::strcmp(requested_method, "generalized") == 0) \
method = generalized_fp32; \
else if(std::strcmp(requested_method, "unweighted_fp64") == 0) \
method = unweighted; \
else if(std::strcmp(requested_method, "weighted_normalized_fp64") == 0) \
method = weighted_normalized; \
else if(std::strcmp(requested_method, "weighted_unnormalized_fp64") == 0) \
method = weighted_unnormalized; \
else if(std::strcmp(requested_method, "generalized_fp64") == 0) \
method = generalized; \
else if(std::strcmp(requested_method, "unweighted_fp32") == 0) \
method = unweighted_fp32; \
else if(std::strcmp(requested_method, "weighted_normalized_fp32") == 0) \
Expand Down Expand Up @@ -166,10 +174,12 @@ void initialize_mat_no_biom(mat_t* &result, char** sample_ids, unsigned int n_sa
}

inline compute_status is_fp64_method(const std::string &method_string, bool &fp64) {
if ((method_string=="unweighted_fp32") || (method_string=="weighted_normalized_fp32") || (method_string=="weighted_unnormalized_fp32") || (method_string=="generalized_fp32")) {
if ((method_string=="unweighted") || (method_string=="weighted_normalized") || (method_string=="weighted_unnormalized") || (method_string=="generalized")) {
fp64 = false;
} else if ((method_string=="unweighted") || (method_string=="weighted_normalized") || (method_string=="weighted_unnormalized") || (method_string=="generalized")) {
} else if ((method_string=="unweighted_fp64") || (method_string=="weighted_normalized_fp64") || (method_string=="weighted_unnormalized_fp64") || (method_string=="generalized_fp64")) {
fp64 = true;
} else if ((method_string=="unweighted_fp32") || (method_string=="weighted_normalized_fp32") || (method_string=="weighted_unnormalized_fp32") || (method_string=="generalized_fp32")) {
fp64 = false;
} else {
return unknown_method;
}
Expand Down
10 changes: 6 additions & 4 deletions src/su.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ void usage() {
std::cout << std::endl;
std::cout << " -i\t\tThe input BIOM table." << std::endl;
std::cout << " -t\t\tThe input phylogeny in newick." << std::endl;
std::cout << " -m\t\tThe method, [unweighted | weighted_normalized | weighted_unnormalized | generalized | unweighted_fp32 | weighted_normalized_fp32 | weighted_unnormalized_fp32 | generalized_fp32]." << std::endl;
std::cout << " -m\t\tThe method, [unweighted | weighted_normalized | weighted_unnormalized | generalized |" << std::endl;
std::cout << " unweighted_fp64 | weighted_normalized_fp64 | weighted_unnormalized_fp64 | generalized_fp64 |" << std::endl;
std::cout << " unweighted_fp32 | weighted_normalized_fp32 | weighted_unnormalized_fp32 | generalized_fp32]." << std::endl;
std::cout << " -o\t\tThe output distance matrix." << std::endl;
std::cout << " -a\t\t[OPTIONAL] Generalized UniFrac alpha, default is 1." << std::endl;
std::cout << " -f\t\t[OPTIONAL] Bypass tips, reduces compute by about 50%." << std::endl;
Expand Down Expand Up @@ -430,10 +432,10 @@ Format get_format(const std::string &format_string, const std::string &method_st
} else if (format_string == "hdf5_fp64") {
format_val = format_hdf5_fp64;
} else if (format_string == "hdf5") {
if ((method_string=="unweighted_fp32") || (method_string=="weighted_normalized_fp32") || (method_string=="weighted_unnormalized_fp32") || (method_string=="generalized_fp32"))
format_val = format_hdf5_fp32;
else
if ((method_string=="unweighted_fp64") || (method_string=="weighted_normalized_fp64") || (method_string=="weighted_unnormalized_fp64") || (method_string=="generalized_fp64"))
format_val = format_hdf5_fp64;
else
format_val = format_hdf5_fp32;
}

return format_val;
Expand Down