-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example client code for float and long double precisions.
- Loading branch information
stevencwilliams
committed
Jan 20, 2012
1 parent
9727cda
commit 9f98936
Showing
3 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
.PHONY: clean | ||
.PHONY: all clean | ||
|
||
all: example_float example example_long_double | ||
|
||
example_float: example_float.cpp | ||
$(CXX) $(CXXFLAGS) -lbct_float -lgsl -lgslcblas -o $@ $< | ||
|
||
example: example.cpp | ||
$(CXX) $(CXXFLAGS) -lbct -lgsl -lgslcblas -o $@ $< | ||
|
||
example_long_double: example_long_double.cpp | ||
$(CXX) $(CXXFLAGS) -lbct_long_double -lgsl -lgslcblas -o $@ $< | ||
|
||
clean: | ||
-rm example | ||
-rm example_float example example_long_double |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <bct/bct_float.h> | ||
#include <cstdio> | ||
#include <gsl/gsl_matrix_float.h> | ||
#include <gsl/gsl_vector_float.h> | ||
|
||
int main() { | ||
|
||
// Create an uninitialized 30-node square matrix | ||
gsl_matrix_float* m = gsl_matrix_float_alloc(30, 30); | ||
|
||
// Initialize the matrix with the data in example.dat | ||
FILE* f = std::fopen("example.dat", "r"); | ||
gsl_matrix_float_fscanf(f, m); | ||
std::fclose(f); | ||
|
||
// Display the matrix | ||
bct_float::printf(m, "%g"); | ||
|
||
// Declare variables for optional returns | ||
gsl_vector_float* id; // In-degree | ||
gsl_vector_float* od; // Out-degree | ||
|
||
// Calculate degree distribution | ||
gsl_vector_float* deg = bct_float::degrees_dir(m, &id, &od); | ||
|
||
// Display the results | ||
bct_float::printf(id, "%g"); | ||
bct_float::printf(od, "%g"); | ||
bct_float::printf(deg, "%g"); | ||
|
||
// Free all memory | ||
gsl_matrix_float_free(m); // Could use bct::gsl_free(m) | ||
gsl_vector_float_free(id); // Could use bct::gsl_free(id) | ||
gsl_vector_float_free(od); // ... | ||
gsl_vector_float_free(deg); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <bct/bct_long_double.h> | ||
#include <cstdio> | ||
#include <gsl/gsl_matrix_long_double.h> | ||
#include <gsl/gsl_vector_long_double.h> | ||
|
||
int main() { | ||
|
||
// Create an uninitialized 30-node square matrix | ||
gsl_matrix_long_double* m = gsl_matrix_long_double_alloc(30, 30); | ||
|
||
// Initialize the matrix with the data in example.dat | ||
FILE* f = std::fopen("example.dat", "r"); | ||
gsl_matrix_long_double_fscanf(f, m); | ||
std::fclose(f); | ||
|
||
// Display the matrix | ||
bct_long_double::printf(m, "%Lg"); | ||
|
||
// Declare variables for optional returns | ||
gsl_vector_long_double* id; // In-degree | ||
gsl_vector_long_double* od; // Out-degree | ||
|
||
// Calculate degree distribution | ||
gsl_vector_long_double* deg = bct_long_double::degrees_dir(m, &id, &od); | ||
|
||
// Display the results | ||
bct_long_double::printf(id, "%Lg"); | ||
bct_long_double::printf(od, "%Lg"); | ||
bct_long_double::printf(deg, "%Lg"); | ||
|
||
// Free all memory | ||
gsl_matrix_long_double_free(m); // Could use bct::gsl_free(m) | ||
gsl_vector_long_double_free(id); // Could use bct::gsl_free(id) | ||
gsl_vector_long_double_free(od); // ... | ||
gsl_vector_long_double_free(deg); | ||
|
||
return 0; | ||
} |