Skip to content

Commit

Permalink
Merge pull request #50 from szhorvat/pre-release-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ntamas authored Nov 17, 2024
2 parents 52141e2 + d96c2ac commit 409d7c2
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 139 deletions.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ endif(POLICY CMP0086)
# Add etc/cmake to CMake's search path so we can put our private stuff there
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/etc/cmake)

# Set a default build type if none was specified
# This must precede the project() line, which would set the CMAKE_BUILD_TYPE
# to 'Debug' with single-config generators on Windows.
# Note that we must do this only if PROJECT_NAME is not set at this point. If
# it is set, it means that plfit is being used as a subproject of another
# project.
if(NOT PROJECT_NAME)
include(BuildType)
endif()

project(
plfit
VERSION 0.9.6
Expand Down Expand Up @@ -82,6 +92,9 @@ else()
FIND_LIBRARY(MATH_LIBRARY NAMES m)
endif()

# Set default symbol visibility to hidden
set(CMAKE_C_VISIBILITY_PRESET hidden)

# Add version information
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/plfit_version.h.in
Expand Down
12 changes: 12 additions & 0 deletions etc/cmake/BuildType.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Taken from https://blog.kitware.com/cmake-and-the-default-build-type/

# Set the default build type to "Release"
set(default_build_type "Release")

get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT isMultiConfig AND NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
9 changes: 9 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
set_target_properties(plfit PROPERTIES LINK_DEPENDS ${PROJECT_SOURCE_DIR}/src/plfit.map)
endif()

# Generate export header
include(GenerateExportHeader)
generate_export_header(plfit
STATIC_DEFINE PLFIT_STATIC
EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/src/plfit_export.h
)

join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}")
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
configure_file(${PROJECT_SOURCE_DIR}/libplfit.pc.in ${PROJECT_BINARY_DIR}/libplfit.pc @ONLY)
Expand All @@ -32,7 +39,9 @@ install(TARGETS plfit LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(
FILES
${PROJECT_SOURCE_DIR}/src/plfit.h
${PROJECT_SOURCE_DIR}/src/plfit_decls.h
${PROJECT_SOURCE_DIR}/src/plfit_error.h
${PROJECT_BINARY_DIR}/src/plfit_export.h
${PROJECT_SOURCE_DIR}/src/plfit_mt.h
${PROJECT_SOURCE_DIR}/src/plfit_sampling.h
${PROJECT_BINARY_DIR}/src/plfit_version.h
Expand Down
12 changes: 3 additions & 9 deletions src/getopt.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@
#ifndef GETOPT_H_
#define GETOPT_H_

#include "plfit_decls.h"

#ifdef __cplusplus
extern "C" {
#endif

__BEGIN_DECLS

extern char* optarg;
extern int optind;
Expand All @@ -50,11 +48,7 @@ extern int optopt;

int getopt(int argc, char** argv, char* optstr);


#ifdef __cplusplus
}
#endif

__END_DECLS

#endif /* GETOPT_H_ */

Expand Down
10 changes: 1 addition & 9 deletions src/gss.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,7 @@
#ifndef __GSS_H__
#define __GSS_H__

#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
#else
# define __BEGIN_DECLS /* empty */
# define __END_DECLS /* empty */
#endif
#include "plfit_decls.h"

__BEGIN_DECLS

Expand Down
10 changes: 1 addition & 9 deletions src/hzeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@
#ifndef __HZETA_H__
#define __HZETA_H__

#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
#else
# define __BEGIN_DECLS /* empty */
# define __END_DECLS /* empty */
#endif
#include "plfit_decls.h"

__BEGIN_DECLS

Expand Down
11 changes: 1 addition & 10 deletions src/kolmogorov.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,8 @@
#ifndef __KOLMOGOROV_H__
#define __KOLMOGOROV_H__

#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
#else
# define __BEGIN_DECLS /* empty */
# define __END_DECLS /* empty */
#endif

#include <stdlib.h>
#include "plfit_decls.h"

__BEGIN_DECLS

Expand Down
10 changes: 4 additions & 6 deletions src/lbfgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#ifndef __LBFGS_H__
#define __LBFGS_H__

#ifdef __cplusplus
extern "C" {
#endif/*__cplusplus*/
#include "plfit_decls.h"

__BEGIN_DECLS

/*
* The default precision of floating point values is 64bit (double).
Expand Down Expand Up @@ -517,9 +517,7 @@ void lbfgs_free(lbfgsfloatval_t *x);

/** @} */

#ifdef __cplusplus
}
#endif/*__cplusplus*/
__END_DECLS



Expand Down
47 changes: 19 additions & 28 deletions src/plfit.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#ifndef __PLFIT_H__
#define __PLFIT_H__
#ifndef PLFIT_H
#define PLFIT_H

#include <stdlib.h>
#include "plfit_decls.h"
#include "plfit_mt.h"
#include "plfit_version.h"

#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
#else
# define __BEGIN_DECLS /* empty */
# define __END_DECLS /* empty */
#endif

__BEGIN_DECLS

typedef unsigned short int plfit_bool_t;
Expand Down Expand Up @@ -91,50 +82,50 @@ typedef struct _plfit_discrete_options_t {
plfit_mt_rng_t* rng;
} plfit_discrete_options_t;

int plfit_continuous_options_init(plfit_continuous_options_t* options);
int plfit_discrete_options_init(plfit_discrete_options_t* options);
PLFIT_EXPORT int plfit_continuous_options_init(plfit_continuous_options_t* options);
PLFIT_EXPORT int plfit_discrete_options_init(plfit_discrete_options_t* options);

extern const plfit_continuous_options_t plfit_continuous_default_options;
extern const plfit_discrete_options_t plfit_discrete_default_options;
PLFIT_EXPORT extern const plfit_continuous_options_t plfit_continuous_default_options;
PLFIT_EXPORT extern const plfit_discrete_options_t plfit_discrete_default_options;

/********** continuous power law distribution fitting **********/

int plfit_log_likelihood_continuous(const double* xs, size_t n, double alpha,
PLFIT_EXPORT int plfit_log_likelihood_continuous(const double* xs, size_t n, double alpha,
double xmin, double* l);
int plfit_estimate_alpha_continuous(const double* xs, size_t n, double xmin,
PLFIT_EXPORT int plfit_estimate_alpha_continuous(const double* xs, size_t n, double xmin,
const plfit_continuous_options_t* options, plfit_result_t* result);
int plfit_continuous(const double* xs, size_t n,
PLFIT_EXPORT int plfit_continuous(const double* xs, size_t n,
const plfit_continuous_options_t* options, plfit_result_t* result);

/*********** discrete power law distribution fitting ***********/

int plfit_estimate_alpha_discrete(const double* xs, size_t n, double xmin,
PLFIT_EXPORT int plfit_estimate_alpha_discrete(const double* xs, size_t n, double xmin,
const plfit_discrete_options_t* options, plfit_result_t *result);
int plfit_log_likelihood_discrete(const double* xs, size_t n, double alpha, double xmin, double* l);
int plfit_discrete(const double* xs, size_t n, const plfit_discrete_options_t* options,
PLFIT_EXPORT int plfit_log_likelihood_discrete(const double* xs, size_t n, double alpha, double xmin, double* l);
PLFIT_EXPORT int plfit_discrete(const double* xs, size_t n, const plfit_discrete_options_t* options,
plfit_result_t* result);

/***** resampling routines to generate synthetic replicates ****/

int plfit_resample_continuous(const double* xs, size_t n, double alpha, double xmin,
PLFIT_EXPORT int plfit_resample_continuous(const double* xs, size_t n, double alpha, double xmin,
size_t num_samples, plfit_mt_rng_t* rng, double* result);
int plfit_resample_discrete(const double* xs, size_t n, double alpha, double xmin,
PLFIT_EXPORT int plfit_resample_discrete(const double* xs, size_t n, double alpha, double xmin,
size_t num_samples, plfit_mt_rng_t* rng, double* result);

/******** calculating the p-value of a fitted model only *******/

int plfit_calculate_p_value_continuous(const double* xs, size_t n,
PLFIT_EXPORT int plfit_calculate_p_value_continuous(const double* xs, size_t n,
const plfit_continuous_options_t* options, plfit_bool_t xmin_fixed,
plfit_result_t *result);
int plfit_calculate_p_value_discrete(const double* xs, size_t n,
PLFIT_EXPORT int plfit_calculate_p_value_discrete(const double* xs, size_t n,
const plfit_discrete_options_t* options, plfit_bool_t xmin_fixed,
plfit_result_t *result);

/************* calculating descriptive statistics **************/

int plfit_moments(const double* data, size_t n, double* mean, double* variance,
PLFIT_EXPORT int plfit_moments(const double* data, size_t n, double* mean, double* variance,
double* skewness, double* kurtosis);

__END_DECLS

#endif /* __PLFIT_H__ */
#endif /* PLFIT_H */
36 changes: 36 additions & 0 deletions src/plfit_decls.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* plfit_decls.h
*
* Copyright (C) 2024 Tamas Nepusz
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#ifndef PLFIT_DECLS_H
#define PLFIT_DECLS_H

#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
#define __BEGIN_DECLS extern "C" {
#define __END_DECLS }
#else
#define __BEGIN_DECLS /* empty */
#define __END_DECLS /* empty */
#endif

/* Include the definition of macros controlling symbol visibility */
#include "plfit_export.h"

#endif /* PLFIT_DECLS_H */
35 changes: 10 additions & 25 deletions src/plfit_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#ifndef __ERROR_H__
#define __ERROR_H__
#ifndef PLFIT_ERROR_H
#define PLFIT_ERROR_H

#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
#else
# define __BEGIN_DECLS /* empty */
# define __END_DECLS /* empty */
#endif
#include "plfit_decls.h"

__BEGIN_DECLS

Expand Down Expand Up @@ -66,22 +58,15 @@ enum {

typedef void plfit_error_handler_t(const char*, const char*, int, int);

extern plfit_error_handler_t plfit_error_handler_abort;
extern plfit_error_handler_t plfit_error_handler_ignore;
extern plfit_error_handler_t plfit_error_handler_printignore;

plfit_error_handler_t* plfit_set_error_handler(plfit_error_handler_t* new_handler);
PLFIT_EXPORT extern plfit_error_handler_t plfit_error_handler_abort;
PLFIT_EXPORT extern plfit_error_handler_t plfit_error_handler_ignore;
PLFIT_EXPORT extern plfit_error_handler_t plfit_error_handler_printignore;

void plfit_error(const char *reason, const char *file, int line, int plfit_errno);
const char* plfit_strerror(const int plfit_errno);
PLFIT_EXPORT plfit_error_handler_t* plfit_set_error_handler(plfit_error_handler_t* new_handler);

void plfit_error_handler_abort(const char *reason, const char *file, int line,
int plfit_errno);
void plfit_error_handler_ignore(const char *reason, const char *file, int line,
int plfit_errno);
void plfit_error_handler_printignore(const char *reason, const char *file, int line,
int plfit_errno);
PLFIT_EXPORT void plfit_error(const char *reason, const char *file, int line, int plfit_errno);
PLFIT_EXPORT const char* plfit_strerror(const int plfit_errno);

__END_DECLS

#endif /* __ERROR_H__ */
#endif /* PLFIT_ERROR_H */
Loading

0 comments on commit 409d7c2

Please sign in to comment.