Skip to content

Commit

Permalink
Merge pull request #161 from ExaScience/release-1.0
Browse files Browse the repository at this point in the history
Release 1.0
  • Loading branch information
tvandera authored Feb 28, 2025
2 parents 0283dd4 + 4ca267e commit 470b63b
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 60 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build_linux.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build on linux
name: CMake on linux
on:
push:
branches:
Expand All @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
build.type:
build_type:
- Debug
- Release
- RelNoOpenMP
Expand Down Expand Up @@ -53,15 +53,15 @@ jobs:
- name: Run CMake
run: |-
cmake -S . -B build.${{ matrix.build.type }} -DCMAKE_BUILD_TYPE=${{ matrix.build.type }} -DENABLE_PYTHON=OFF
cmake -S . -B build.${{ matrix.build_type }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DENABLE_PYTHON=OFF
- name: Build
run: |-
cmake --build build.${{ matrix.build.type }}
cmake --build build.${{ matrix.build_type }}
- name: Install
run: |-
sudo cmake --install build.${{ matrix.build.type }}
sudo cmake --install build.${{ matrix.build_type }}
- name: Run tests
run: |-
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
push:
branches:
- master
tags:
release:

jobs:
conda-build:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
push:
branches:
- master
tags:
release:

jobs:
build_wheels:
Expand Down
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ endif()

message("Initializing versioning...")

if (SKBUILD)

set(SMURFF_VERSION "${SKBUILD_PROJECT_VERSION_FULL}")

message(STATUS "SKBUILD version: ${SMURFF_VERSION}")

elseif(SMURFF_VERSION)

message(STATUS "SMURFF from commandline: ${SMURFF_VERSION}")

else()

#get GIT commit count we can later use as patch level
execute_process(
COMMAND git rev-list HEAD --count
Expand Down Expand Up @@ -214,6 +226,8 @@ endif()

message(STATUS "GIT describe ${SMURFF_VERSION}")

endif()

string(REGEX REPLACE "-[^-]+$"
"" SMURFF_VERSION_CLEAN
${SMURFF_VERSION})
Expand Down
26 changes: 14 additions & 12 deletions cpp/SmurffCpp/Configs/DataConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static const std::string SN_INIT_TAG = "sn_init";
static const std::string SN_MAX_TAG = "sn_max";
static const std::string NOISE_THRESHOLD_TAG = "noise_threshold";

DataConfig::DataConfig ()
DataConfig::DataConfig ()
: m_hasData(false) {}

DataConfig::DataConfig ( const Matrix &m
Expand Down Expand Up @@ -90,6 +90,8 @@ void DataConfig::check() const
// other methods
//

const std::string NON_FINITE_MSG = "Found nan/infinite in input data";

void DataConfig::setData(const Matrix &m)
{
m_dense_matrix_data = m;
Expand All @@ -98,7 +100,7 @@ void DataConfig::setData(const Matrix &m)
m_isScarce = false;
m_isMatrix = true;

THROWERROR_ASSERT(m.array().isFinite().all());
THROWERROR_ASSERT_MSG(m.array().isFinite().all(), NON_FINITE_MSG);

check();
}
Expand All @@ -112,7 +114,7 @@ void DataConfig::setData(const SparseMatrix &m, bool isScarce)
m_isMatrix = true;

const Eigen::Map<const Vector> values(m.valuePtr(), m.nonZeros());
THROWERROR_ASSERT(values.array().isFinite().all());
THROWERROR_ASSERT_MSG(values.array().isFinite().all(), NON_FINITE_MSG);

check();
}
Expand All @@ -125,7 +127,7 @@ void DataConfig::setData(const DenseTensor &m)
m_isMatrix = false;

const Eigen::Map<const Vector> values(m.getValues().data(), m.getValues().size());
THROWERROR_ASSERT(values.array().isFinite().all());
THROWERROR_ASSERT_MSG(values.array().isFinite().all(), NON_FINITE_MSG);;

check();
}
Expand All @@ -139,7 +141,7 @@ void DataConfig::setData(const SparseTensor &m, bool isScarce)
m_isMatrix = false;

const Eigen::Map<const Vector> values(m.getValues().data(), m.getValues().size());
THROWERROR_ASSERT(values.array().isFinite().all());
THROWERROR_ASSERT_MSG(values.array().isFinite().all(), NON_FINITE_MSG);;

check();
}
Expand Down Expand Up @@ -180,13 +182,13 @@ SparseMatrix &DataConfig::getSparseMatrixData()
return m_sparse_matrix_data;
}

SparseTensor &DataConfig::getSparseTensorData()
SparseTensor &DataConfig::getSparseTensorData()
{
THROWERROR_ASSERT(!hasData());
return m_sparse_tensor_data;
}

DenseTensor &DataConfig::getDenseTensorData()
DenseTensor &DataConfig::getDenseTensorData()
{
THROWERROR_ASSERT(!hasData());
return m_dense_tensor_data;
Expand Down Expand Up @@ -237,7 +239,7 @@ const std::vector<std::uint64_t> DataConfig::getDims() const
const auto &m = getDenseMatrixData();
return std::vector<std::uint64_t>{ (std::uint64_t)m.rows(), (std::uint64_t)m.cols() };
}
else if (isMatrix() && !isDense())
else if (isMatrix() && !isDense())
{
const auto &m = getSparseMatrixData();
return std::vector<std::uint64_t>{ (std::uint64_t)m.rows(), (std::uint64_t)m.cols() };
Expand All @@ -252,7 +254,7 @@ const std::vector<std::uint64_t> DataConfig::getDims() const
const auto &m = getDenseTensorData();
return m.getDims();
}
else
else
THROWERROR_NOTIMPL();
}

Expand Down Expand Up @@ -337,15 +339,15 @@ void DataConfig::save(HDF5Group& cfg_file, const std::string& sectionName) const
cfg_file.put(sectionName, POS_TAG, ss.str());
}

if (isMatrix() && isDense())
if (isMatrix() && isDense())
cfg_file.write(sectionName, DATA_TAG, getDenseMatrixData());
else if (isMatrix() && !isDense())
else if (isMatrix() && !isDense())
cfg_file.write(sectionName, DATA_TAG, getSparseMatrixData());
else if (!isMatrix() && !isDense())
cfg_file.write(sectionName, DATA_TAG, getSparseTensorData());
else if (!isMatrix() && isDense())
cfg_file.write(sectionName, DATA_TAG, getDenseTensorData());
else
else
THROWERROR_NOTIMPL();

//write tensor config type
Expand Down
4 changes: 2 additions & 2 deletions cpp/SmurffCpp/Utils/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ inline void show_internal(const char *name, const int& variable)
#define THROWERROR_FILE_NOT_EXIST(file) THROWERROR_BASE_COND((std::string("File '") + file + std::string("' not found")), CONCAT_VAR(ss, __LINE__), std::runtime_error, smurff::generic_io::file_exists(file))


#define THROWERROR_ASSERT(cond) THROWERROR_COND("assert: ", cond)
#define THROWERROR_ASSERT(cond) THROWERROR_COND("assert failed: " STRINGIFY(cond), cond)

#define THROWERROR_ASSERT_MSG(cond, msg) THROWERROR_COND((std::string("assert: ") + msg), cond)
#define THROWERROR_ASSERT_MSG(cond, msg) THROWERROR_COND((std::string("assert failed: " STRINGIFY(cond) "\n") + msg), cond)
1 change: 1 addition & 0 deletions cpp/Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ FILE (GLOB SOURCE_FILES "tests.cpp"
"TestsSparseSideInfo.cpp"
"TestsSmurff.cpp"
"TestsRandom.cpp"
"TestsInputValidation.cpp"
)

include_directories("expected_${SMURFF_FLOAT_TYPE}")
Expand Down
29 changes: 29 additions & 0 deletions cpp/Tests/Tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,35 @@ Config genConfig(const Train &train, const Test &test, std::vector<PriorTypes> p
return config;
}

struct SmurffTest {
Config config;

SmurffTest(const Matrix &train, const SparseMatrix &test, std::vector<PriorTypes> priors)
: config(genConfig(train, test, priors)) {}

SmurffTest(const SparseMatrix &train, const SparseMatrix &test, std::vector<PriorTypes> priors)
: config(genConfig(train, test, priors)) {}

SmurffTest(const DenseTensor &train, const SparseTensor &test, std::vector<PriorTypes> priors)
: config(genConfig(train, test, priors)) {}

SmurffTest(const SparseTensor &train, const SparseTensor &test, std::vector<PriorTypes> priors)
: config(genConfig(train, test, priors)) {}

template<class M>
SmurffTest &addSideInfo(int m, const M &c, bool direct = true) {
config.addSideInfo(m, makeSideInfoConfig(c, direct));
return *this;
}

SmurffTest &addAuxData(const DataConfig &c) {
config.addData() = c;
return *this;
}

void runAndCheck(int nr);
};

void checkValue(double actualValue, double expectedValue, double epsilon);

} // namespace test
Expand Down
73 changes: 73 additions & 0 deletions cpp/Tests/TestsInputValidation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <catch2/catch_test_macros.hpp>

#include <iostream>
#include <string>
#include <sstream>

#include <SmurffCpp/Types.h>
#include <SmurffCpp/Configs/Config.h>

#include "Tests.h"

namespace smurff {

namespace test {

template<typename Matrix, typename Func>
Matrix replaceWithNaN(const Matrix &input, Func f) {
Matrix output = input;
f(output);
return output;
}

template<typename Matrix>
Matrix replaceWithNaN(const Matrix &input);

template<>
Matrix replaceWithNaN(const Matrix &input) {
return replaceWithNaN(input, [](Matrix &m) { m.setConstant(std::nan("0")); });
}

template<>
SparseMatrix replaceWithNaN(const SparseMatrix &input) {
return replaceWithNaN(input, [](SparseMatrix &output) {
// Set all nonzero values to NaN
for (int k = 0; k < output.outerSize(); ++k)
for (SparseMatrix::InnerIterator it(output, k); it; ++it)
it.valueRef() = std::nan("0");
}
);
}

template<>
DenseTensor replaceWithNaN(const DenseTensor &input) {
return replaceWithNaN(input, [](DenseTensor &output) {
std::fill(output.getValues().begin(), output.getValues().end(), std::nan("0"));
});
}

template<>
SparseTensor replaceWithNaN(const SparseTensor &input) {
return replaceWithNaN(input, [](SparseTensor &output) {
std::fill(output.getValues().begin(), output.getValues().end(), std::nan("0"));
});
}

template<typename TrainMatrix, typename TestMatrix>
void testNaN(const TrainMatrix &train, const TestMatrix &test) {
SmurffTest(replaceWithNaN(train), test, {PriorTypes::normal, PriorTypes::normal});
}



TEST_CASE("test assert NA")
{
CHECK_THROWS(testNaN(trainSparseMatrix, testSparseMatrix));
CHECK_THROWS(testNaN(trainDenseMatrix, testSparseMatrix));
CHECK_THROWS(testNaN(trainDenseTensor2d, testSparseTensor2d));
CHECK_THROWS(testNaN(trainDenseTensor3d, testSparseTensor3d));
CHECK_THROWS(testNaN(trainSparseTensor2d, testSparseTensor2d));
CHECK_THROWS(testNaN(trainSparseTensor3d, testSparseTensor3d));
}
} // end namespace test
} // end namespace smurff
55 changes: 14 additions & 41 deletions cpp/Tests/TestsSmurff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,51 +101,24 @@ void checkResultItems(const std::vector<ResultItem> &actualResultItems,
}
}

struct SmurffTest {
Config config;

SmurffTest(const Matrix &train, const SparseMatrix &test, std::vector<PriorTypes> priors)
: config(genConfig(train, test, priors)) {}

SmurffTest(const SparseMatrix &train, const SparseMatrix &test, std::vector<PriorTypes> priors)
: config(genConfig(train, test, priors)) {}

SmurffTest(const DenseTensor &train, const SparseTensor &test, std::vector<PriorTypes> priors)
: config(genConfig(train, test, priors)) {}

SmurffTest(const SparseTensor &train, const SparseTensor &test, std::vector<PriorTypes> priors)
: config(genConfig(train, test, priors)) {}

template<class M>
SmurffTest &addSideInfo(int m, const M &c, bool direct = true) {
config.addSideInfo(m, makeSideInfoConfig(c, direct));
return *this;
}

SmurffTest &addAuxData(const DataConfig &c) {
config.addData() = c;
return *this;
}


void runAndCheck(int nr) {
std::shared_ptr<ISession> trainSession = std::make_shared<TrainSession>(config);
trainSession->run();
void SmurffTest::runAndCheck(int nr)
{
std::shared_ptr<ISession> trainSession = std::make_shared<TrainSession>(config);
trainSession->run();

double actualRmseAvg = trainSession->getRmseAvg();
const std::vector<ResultItem> &actualResults = trainSession->getResultItems();
double actualRmseAvg = trainSession->getRmseAvg();
const std::vector<ResultItem> &actualResults = trainSession->getResultItems();

printActualResults(nr, actualRmseAvg, actualResults);
if(expectedResults.find(nr) == expectedResults.end())
FAIL("Expected results for nr " << nr << " not found\n");
printActualResults(nr, actualRmseAvg, actualResults);
if (expectedResults.find(nr) == expectedResults.end())
FAIL("Expected results for nr " << nr << " not found\n");

double &expectedRmseAvg = expectedResults[nr].rmseAvg;
auto &expectedResultItems = expectedResults[nr].resultItems;
double &expectedRmseAvg = expectedResults[nr].rmseAvg;
auto &expectedResultItems = expectedResults[nr].resultItems;

checkValue(actualRmseAvg, expectedRmseAvg, rmse_epsilon);
checkResultItems(actualResults, expectedResultItems);
}
};
checkValue(actualRmseAvg, expectedRmseAvg, rmse_epsilon);
checkResultItems(actualResults, expectedResultItems);
}

///===========================================================================
TEST_CASE("train_dense_matrix_test_sparse_matrix_normal_normal_none_none",
Expand Down
Loading

0 comments on commit 470b63b

Please sign in to comment.