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

Fix: test compile and run #89

Merged
merged 11 commits into from
Jul 22, 2024
15 changes: 9 additions & 6 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,24 @@ env:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
ubuntu-container-test:
ubuntu-test:
# The type of runner that the job will run on
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
# Steps represent a sequence of tasks that will be executed as part of the job
container:
image: ghcr.io/gwmodel-lab/libgwmodel-docker4test:latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt-get -qq update
sudo apt-get -qq install libarmadillo-dev libopenblas-dev libgsl-dev libopenmpi-dev catch2
# Runs the test container to run test scripts
- name: Build and Install Package
run: |
cmake -B build -S . -DCMAKE_BUILD_TYPE:STRING=Release -DWITH_TESTS:BOOL=OFF
cmake --build build --config Release
cmake --install build
sudo cmake --install build
- name: Test Find
run: |
cmake -B build/CMakeFind -S test/CMakeFind
Expand Down
20 changes: 13 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,27 @@ env:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
ubuntu-container-test:
ubuntu-test:
# The type of runner that the job will run on
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
strategy:
matrix:
openmp: [TRUE, FALSE]
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt-get -qq update
sudo apt-get -qq install libarmadillo-dev libopenblas-dev libgsl-dev libopenmpi-dev catch2
# Runs the test container to run test scripts
- uses: docker://ghcr.io/gwmodel-lab/libgwmodel-docker4test:latest
with:
entrypoint: /bin/bash
args: -c "cmake -B build -S . -DCMAKE_BUILD_TYPE:STRING=Debug -DENABLE_OpenMP=${{ matrix.openmp }} && cmake --build build --config Debug && ctest --test-dir build --output-on-failure"
- name: CMake test
run: |
cmake -B build -S . -DCMAKE_BUILD_TYPE:STRING=Debug -DENABLE_OpenMP=${{ matrix.openmp }}
cmake --build build --config Debug
ctest --test-dir build --output-on-failure

windows-test:
runs-on: windows-2019
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ if(ENABLE_OpenMP)
find_package(OpenMP)
if(OpenMP_FOUND AND OpenMP_C_FOUND AND OpenMP_CXX_FOUND)
if(ENABLE_OpenMP)
if(MSVC)
set(OpenMP_C_FLAGS "${OpenMP_C_FLAGS} -openmp:llvm")
set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS} -openmp:llvm")
endif(MSVC)
add_definitions(-DENABLE_OPENMP)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
Expand Down
8 changes: 4 additions & 4 deletions src/gwmodelpp/GTWR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ mat GTWR::predictOmp(const mat& locations, const mat& x, const vec& y)
bool success = true;
std::exception except;
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = 0; (uword)i < nRp; i++)
for (uword i = 0; i < nRp; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
if (success)
Expand Down Expand Up @@ -328,7 +328,7 @@ mat GTWR::fitOmp(const mat& x, const vec& y, mat& betasSE, vec& shat, vec& qDiag
bool success = true;
std::exception except;
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = 0; (uword)i < nDp; i++)
for (uword i = 0; i < nDp; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
if (success)
Expand Down Expand Up @@ -379,7 +379,7 @@ double GTWR::bandwidthSizeCriterionCVOmp(BandwidthWeight* bandwidthWeight)
vec cv_all(mOmpThreadNum, fill::zeros);
bool flag = true;
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = 0; (uword)i < nDp; i++)
for (uword i = 0; i < nDp; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
if (flag)
Expand Down Expand Up @@ -425,7 +425,7 @@ double GTWR::bandwidthSizeCriterionAICOmp(BandwidthWeight* bandwidthWeight)
mat shat_all(2, mOmpThreadNum, fill::zeros);
bool flag = true;
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = 0; (uword)i < nDp; i++)
for (uword i = 0; i < nDp; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
if (flag)
Expand Down
2 changes: 1 addition & 1 deletion src/gwmodelpp/GWDA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void GWDA::discriminantAnalysisOmp()
vector<string> lev = levels(mY);
mat wt(nRp, nRp, fill::zeros);
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = 0; (uword)i < nRp; i++)
for (uword i = 0; i < nRp; i++)
{
wt.col(i) = mSpatialWeight.weightVector(i);
}
Expand Down
8 changes: 4 additions & 4 deletions src/gwmodelpp/GWDR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ mat GWDR::predictOmp(const mat& locations, const mat& x, const vec& y)
bool success = true;
std::exception except;
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = 0; (uword)i < nDp; i++)
for (uword i = 0; i < nDp; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
if (success)
Expand Down Expand Up @@ -268,7 +268,7 @@ mat GWDR::fitOmp(const mat& x, const vec& y, mat& betasSE, vec& shat, vec& qdiag
bool success = true;
std::exception except;
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = 0; (uword)i < nDp; i++)
for (uword i = 0; i < nDp; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
int thread = omp_get_thread_num();
Expand Down Expand Up @@ -474,7 +474,7 @@ double GWDR::bandwidthCriterionAICOmp(const vector<BandwidthWeight*>& bandwidths
bool success = true;
std::exception except;
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = 0; (uword)i < nDp; i++)
for (uword i = 0; i < nDp; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
int thread = omp_get_thread_num();
Expand Down Expand Up @@ -644,7 +644,7 @@ double GWDR::indepVarCriterionOmp(const vector<size_t>& indepVars)
{
vec trS_all(mOmpThreadNum, arma::fill::zeros);
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = 0; (uword)i < nDp; i++)
for (uword i = 0; i < nDp; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
int thread = omp_get_thread_num();
Expand Down
8 changes: 4 additions & 4 deletions src/gwmodelpp/GWRBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ mat GWRBasic::predictOmp(const mat& locations, const mat& x, const vec& y)
bool success = true;
std::exception except;
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = 0; (uword)i < nRp; i++)
for (uword i = 0; i < nRp; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
if (success)
Expand Down Expand Up @@ -469,7 +469,7 @@ mat GWRBasic::fitCoreOmp(const mat& x, const vec& y, const SpatialWeight& sw)
bool success = true;
std::exception except;
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = int(workRange.first); (uword)i < workRange.second; i++)
for (uword i = workRange.first; i < workRange.second; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
if (success)
Expand Down Expand Up @@ -520,7 +520,7 @@ arma::mat GWRBasic::fitCoreCVOmp(const arma::mat& x, const arma::vec& y, const S
bool flag = true;
std::pair<uword, uword> workRange = mWorkRange.value_or(make_pair(0, nDp));
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = int(workRange.first); (uword)i < workRange.second; i++)
for (uword i = workRange.first; i < workRange.second; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
if (flag)
Expand Down Expand Up @@ -553,7 +553,7 @@ arma::mat GWRBasic::fitCoreSHatOmp(const arma::mat& x, const arma::vec& y, const
int flag = true;
std::pair<uword, uword> workRange = mWorkRange.value_or(make_pair(0, nDp));
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = int(workRange.first); (uword)i < workRange.second; i++)
for (uword i = workRange.first; i < workRange.second; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
if (flag)
Expand Down
8 changes: 4 additions & 4 deletions src/gwmodelpp/GWRMultiscale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ vec GWRMultiscale::fitVarCoreOmp(const vec &x, const vec &y, const SpatialWeight
uword rangeSize = workRange.second - workRange.first;
S = mat(rangeSize, nDp, fill::zeros);
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = int(workRange.first); (uword)i < workRange.second; i++)
for (uword i = workRange.first; i < workRange.second; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
vec w = sw.weightVector(i);
Expand All @@ -651,7 +651,7 @@ vec GWRMultiscale::fitVarCoreOmp(const vec &x, const vec &y, const SpatialWeight
else
{
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = int(workRange.first); (uword)i < workRange.second; i++)
for (uword i = workRange.first; i < workRange.second; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
vec w = sw.weightVector(i);
Expand Down Expand Up @@ -686,7 +686,7 @@ vec GWRMultiscale::fitVarCoreCVOmp(const vec &x, const vec &y, const SpatialWeig
bool flag = true;
std::pair<uword, uword> workRange = mWorkRange.value_or(make_pair(0, nDp));
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = workRange.first; (uword)i < workRange.second; i++)
for (uword i = workRange.first; i < workRange.second; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
if (flag)
Expand Down Expand Up @@ -719,7 +719,7 @@ vec GWRMultiscale::fitVarCoreSHatOmp(const vec &x, const vec &y, const SpatialWe
bool flag = true;
std::pair<uword, uword> workRange = mWorkRange.value_or(make_pair(0, nDp));
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = workRange.first; (uword)i < workRange.second; i++)
for (uword i = workRange.first; i < workRange.second; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
if (flag)
Expand Down
4 changes: 2 additions & 2 deletions src/gwmodelpp/GWSS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void GWSS::GWAverageOmp()
uword nVar = mX.n_cols;
uword nRp = mCoords.n_rows;
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = 0; (uword) i < nRp; i++)
for (uword i = 0; i < nRp; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
vec w = mSpatialWeight.weightVector(i);
Expand Down Expand Up @@ -219,7 +219,7 @@ void GWSS::GWCorrelationOmp()
if (nVar >= 2)
{
#pragma omp parallel for num_threads(mOmpThreadNum)
for (int i = 0; (uword) i < nRp; i++)
for (uword i = 0; i < nRp; i++)
{
GWM_LOG_STOP_CONTINUE(mStatus);
vec w = mSpatialWeight.weightVector(i);
Expand Down
66 changes: 35 additions & 31 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ if(ENABLE_OpenMP)
find_package(OpenMP)
if(OpenMP_FOUND AND OpenMP_C_FOUND AND OpenMP_CXX_FOUND)
if(ENABLE_OpenMP)
if(MSVC)
set(OpenMP_C_FLAGS "${OpenMP_C_FLAGS} -openmp:llvm")
set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS} -openmp:llvm")
endif(MSVC)
add_definitions(-DENABLE_OPENMP)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
Expand All @@ -28,94 +32,94 @@ include_directories(
set(SAMPLE_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data)
add_definitions(-DSAMPLE_DATA_DIR="${SAMPLE_DATA_DIR}")

set(ADDON_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/data/londonhp100.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TerminateCheckTelegram.cpp
${CMAKE_CURRENT_SOURCE_DIR}/FileTelegram.cpp
)
add_library(londonhp100 data/londonhp100.cpp)
target_link_libraries(londonhp100 ${ARMADILLO_LIBRARIES})

add_definitions(-DSAMPLE_DATA_DIR="${SAMPLE_DATA_DIR}")
set(SAMPL_LONDONHP ${CMAKE_CURRENT_SOURCE_DIR}/data/londonhp.cpp)
add_library(londonhp data/londonhp.cpp)
target_link_libraries(londonhp ${ARMADILLO_LIBRARIES})

add_library(telegram TerminateCheckTelegram.cpp FileTelegram.cpp)
target_link_libraries(telegram Catch2::Catch2WithMain)

add_executable(testGWRBasic testGWRBasic.cpp ${ADDON_SOURCES})
target_link_libraries(testGWRBasic PRIVATE gwmodel ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_executable(testGWRBasic testGWRBasic.cpp)
target_link_libraries(testGWRBasic PRIVATE gwmodel londonhp100 telegram ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_test(
NAME testGWRBasic
COMMAND $<TARGET_FILE:testGWRBasic> --success --skip-benchmarks
)

add_executable(testGWSS testGWSS.cpp ${ADDON_SOURCES})
target_link_libraries(testGWSS PRIVATE gwmodel ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_executable(testGWSS testGWSS.cpp)
target_link_libraries(testGWSS PRIVATE gwmodel londonhp100 telegram ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_test(
NAME testGWSS
COMMAND $<TARGET_FILE:testGWSS> --success
)

add_executable(testGWPCA testGWPCA.cpp ${ADDON_SOURCES})
target_link_libraries(testGWPCA PRIVATE gwmodel ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_executable(testGWPCA testGWPCA.cpp)
target_link_libraries(testGWPCA PRIVATE gwmodel londonhp100 telegram ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_test(
NAME testGWPCA
COMMAND $<TARGET_FILE:testGWPCA> --success
)

add_executable(testGWDR testGWDR.cpp ${ADDON_SOURCES})
target_link_libraries(testGWDR PRIVATE gwmodel ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_executable(testGWDR testGWDR.cpp)
target_link_libraries(testGWDR PRIVATE gwmodel londonhp100 telegram ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_test(
NAME testGWDR
COMMAND $<TARGET_FILE:testGWDR> --success
)

add_executable(testGWRMultiscale testGWRMultiscale.cpp ${ADDON_SOURCES})
target_link_libraries(testGWRMultiscale PRIVATE gwmodel ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_executable(testGWRMultiscale testGWRMultiscale.cpp)
target_link_libraries(testGWRMultiscale PRIVATE gwmodel londonhp100 telegram ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_test(
NAME testGWRMultiscale
COMMAND $<TARGET_FILE:testGWRMultiscale> --success
)

add_executable(testLogger testLogger.cpp ${ADDON_SOURCES})
target_link_libraries(testLogger PRIVATE gwmodel ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_executable(testLogger testLogger.cpp)
target_link_libraries(testLogger PRIVATE gwmodel londonhp100 telegram ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_test(
NAME testLogger
COMMAND $<TARGET_FILE:testLogger> --success
)

add_executable(testGWRRobust testGWRRobust.cpp ${ADDON_SOURCES})
target_link_libraries(testGWRRobust PRIVATE gwmodel ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_executable(testGWRRobust testGWRRobust.cpp)
target_link_libraries(testGWRRobust PRIVATE gwmodel londonhp100 telegram ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_test(
NAME testGWRRobust
COMMAND $<TARGET_FILE:testGWRRobust> --success
)

add_executable(testGWRGeneralized testGWRGeneralized.cpp ${ADDON_SOURCES} ${SAMPL_LONDONHP})
target_link_libraries(testGWRGeneralized PRIVATE gwmodel ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_executable(testGWRGeneralized testGWRGeneralized.cpp)
target_link_libraries(testGWRGeneralized PRIVATE gwmodel londonhp londonhp100 telegram ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_test(
NAME testGWRGeneralized
COMMAND $<TARGET_FILE:testGWRGeneralized> --success
)

add_executable(testGWRScalable testGWRScalable.cpp ${ADDON_SOURCES})
target_link_libraries(testGWRScalable PRIVATE gwmodel ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_executable(testGWRScalable testGWRScalable.cpp)
target_link_libraries(testGWRScalable PRIVATE gwmodel londonhp100 telegram ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_test(
NAME testGWRScalable
COMMAND $<TARGET_FILE:testGWRScalable> --success
)

add_executable(testGWRLocalCollinearity testGWRLocalCollinearity.cpp ${ADDON_SOURCES})
target_link_libraries(testGWRLocalCollinearity PRIVATE gwmodel ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_executable(testGWRLocalCollinearity testGWRLocalCollinearity.cpp)
target_link_libraries(testGWRLocalCollinearity PRIVATE gwmodel londonhp100 telegram ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_test(
NAME testGWRLocalCollinearity
COMMAND $<TARGET_FILE:testGWRLocalCollinearity> --success
)

add_executable(testGTWR testGTWR.cpp ${ADDON_SOURCES})
target_link_libraries(testGTWR PRIVATE gwmodel ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_executable(testGTWR testGTWR.cpp)
target_link_libraries(testGTWR PRIVATE gwmodel londonhp100 telegram ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_test(
NAME testGTWR
COMMAND $<TARGET_FILE:testGTWR> --success
)

add_executable(testGWDA testGWDA.cpp ${SAMPL_LONDONHP})
target_link_libraries(testGWDA PRIVATE gwmodel ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_executable(testGWDA testGWDA.cpp)
target_link_libraries(testGWDA PRIVATE gwmodel londonhp ${ARMADILLO_LIBRARIES} Catch2::Catch2WithMain)
add_test(
NAME testGWDA
COMMAND $<TARGET_FILE:testGWDA> --success
Expand Down
Loading
Loading