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

Add missing (local) kernel tests #730

Merged
merged 3 commits into from
Jun 10, 2024
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
2 changes: 1 addition & 1 deletion src/runtime/local/kernels/CondMatScaMat.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct CondMatScaMat<DenseMatrix<VTVal>, DenseMatrix<VTCond>, VTVal, DenseMatrix
// ----------------------------------------------------------------------------

template<typename VTVal, typename VTCond>
struct CondMatMatSca<Matrix<VTVal>, Matrix<VTCond>, VTVal, Matrix<VTVal>> {
struct CondMatScaMat<Matrix<VTVal>, Matrix<VTCond>, VTVal, Matrix<VTVal>> {
static void apply(
Matrix<VTVal> *& res,
const Matrix<VTCond> * cond,
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/local/kernels/CondMatScaSca.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct CondMatScaSca<DenseMatrix<VTVal>, DenseMatrix<VTCond>, VTVal, VTVal> {
// ----------------------------------------------------------------------------

template<typename VTVal, typename VTCond>
struct CondMatMatSca<Matrix<VTVal>, Matrix<VTCond>, VTVal, VTVal> {
struct CondMatScaSca<Matrix<VTVal>, Matrix<VTCond>, VTVal, VTVal> {
static void apply(
Matrix<VTVal> *& res,
const Matrix<VTCond> * cond,
Expand Down
6 changes: 6 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ set(TEST_SOURCES
runtime/local/kernels/CastScaObjTest.cpp
runtime/local/kernels/CheckEqTest.cpp
runtime/local/kernels/ColBindTest.cpp
runtime/local/kernels/CondMatMatMatTest.cpp
runtime/local/kernels/CondMatMatScaTest.cpp
runtime/local/kernels/CondMatScaMatTest.cpp
runtime/local/kernels/CondMatScaScaTest.cpp
runtime/local/kernels/CreateFrameTest.cpp
runtime/local/kernels/CTableTest.cpp
runtime/local/kernels/DiagMatrixTest.cpp
Expand All @@ -106,6 +110,7 @@ set(TEST_SOURCES
runtime/local/kernels/EwUnaryScaTest.cpp
runtime/local/kernels/ExtractColTest.cpp
runtime/local/kernels/ExtractRowTest.cpp
runtime/local/kernels/FillTest.cpp
runtime/local/kernels/FilterColTest.cpp
runtime/local/kernels/FilterRowTest.cpp
runtime/local/kernels/GroupJoinTest.cpp
Expand All @@ -130,6 +135,7 @@ set(TEST_SOURCES
runtime/local/kernels/ReverseTest.cpp
runtime/local/kernels/RowBindTest.cpp
runtime/local/kernels/SampleTest.cpp
runtime/local/kernels/SemiJoinTest.cpp
runtime/local/kernels/SeqTest.cpp
runtime/local/kernels/SetColLabelsTest.cpp
runtime/local/kernels/SetColLabelsPrefixTest.cpp
Expand Down
125 changes: 125 additions & 0 deletions test/runtime/local/kernels/CondMatMatMatTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright 2024 The DAPHNE Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <runtime/local/datagen/GenGivenVals.h>
#include <runtime/local/datastructures/DenseMatrix.h>
#include <runtime/local/kernels/CheckEq.h>
#include <runtime/local/kernels/CondMatMatMat.h>

#include <tags.h>

#include <catch.hpp>

#include <cstdint>

#define TEST_NAME(opName) "CondMatMatMat (" opName ")"
#define DATA_TYPES DenseMatrix, Matrix
#define VALUE_TYPES int64_t, double

TEMPLATE_PRODUCT_TEST_CASE(TEST_NAME("Matrix"), TAG_KERNELS, (DATA_TYPES), (VALUE_TYPES)) {
using DT = TestType;
using VT = typename DT::VT;

DT * argCond = nullptr;
DT * argThen = nullptr;
DT * argElse = nullptr;
DT * exp = nullptr;

SECTION("example 1") {
argCond = genGivenVals<DT>(3, {
true, false, false,
false, true, false,
false, false, true
});
argThen = genGivenVals<DT>(3, {
VT(1.5), 2, 3,
4, 5, 6,
7, 8, 9
});
argElse = genGivenVals<DT>(3, {
-1, -2, -3,
VT(-4.5), -5, -6,
-7, -8, -9
});
exp = genGivenVals<DT>(3, {
VT(1.5), -2, -3,
VT(-4.5), 5, -6,
-7, -8, 9
});
}

DT * res = nullptr;
condMatMatMat(res, argCond, argThen, argElse, nullptr);

CHECK(*res == *exp);

DataObjectFactory::destroy(argCond, argThen, argElse, exp, res);
}

TEMPLATE_PRODUCT_TEST_CASE(TEST_NAME("invalid shape"), TAG_KERNELS, (DATA_TYPES), (int64_t)) {
using DT = TestType;
using VT = typename DT::VT;

DT * argCond = genGivenVals<DT>(3, {
true, false, false,
false, true, false,
false, false, true
});

DT * argThen = nullptr;
DT * argElse = nullptr;

SECTION("then matrix too small") {
argThen = genGivenVals<DT>(2, {
VT(1.5), 2, 3,
4, 5, 6
});
argElse = genGivenVals<DT>(3, {
-1, -2, -3,
VT(-4.5), -5, -6,
-7, -8, -9
});
}
SECTION("else matrix too small") {
argThen = genGivenVals<DT>(3, {
VT(1.5), 2, 3,
4, 5, 6,
7, 8, 9
});
argElse = genGivenVals<DT>(2, {
-1, -2, -3,
VT(-4.5), -5, -6
});
}
SECTION("then/else matrices too small") {
argThen = genGivenVals<DT>(2, {
VT(1.5), 2, 3,
4, 5, 6
});
argElse = genGivenVals<DT>(2, {
-1, -2, -3,
VT(-4.5), -5, -6
});
}

DT * res = nullptr;

REQUIRE_THROWS_AS(condMatMatMat(res, argCond, argThen, argElse, nullptr), std::runtime_error);

DataObjectFactory::destroy(argCond, argThen, argElse);
if (res != nullptr)
DataObjectFactory::destroy(res);
}
99 changes: 99 additions & 0 deletions test/runtime/local/kernels/CondMatMatScaTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright 2024 The DAPHNE Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <runtime/local/datagen/GenGivenVals.h>
#include <runtime/local/datastructures/DenseMatrix.h>
#include <runtime/local/kernels/CheckEq.h>
#include <runtime/local/kernels/CondMatMatSca.h>

#include <tags.h>

#include <catch.hpp>

#include <cstdint>

#define TEST_NAME(opName) "CondMatMatSca (" opName ")"
#define DATA_TYPES DenseMatrix, Matrix
#define VALUE_TYPES int64_t, double

TEMPLATE_PRODUCT_TEST_CASE(TEST_NAME("Matrix"), TAG_KERNELS, (DATA_TYPES), (VALUE_TYPES)) {
using DT = TestType;
using VT = typename DT::VT;

DT * argCond = nullptr;
DT * argThen = nullptr;
VT argElse;
DT * exp = nullptr;

SECTION("example 1") {
argCond = genGivenVals<DT>(3, {
true, false, false,
false, true, false,
false, false, true
});
argThen = genGivenVals<DT>(3, {
VT(1.5), 2, 3,
4, 5, 6,
7, 8, 9
});

argElse = VT(-1.5);

exp = genGivenVals<DT>(3, {
VT(1.5), argElse, argElse,
argElse, 5, argElse,
argElse, argElse, 9
});
}

DT * res = nullptr;
condMatMatSca(res, argCond, argThen, argElse, nullptr);

CHECK(*res == *exp);

DataObjectFactory::destroy(argCond, argThen, exp, res);
}

TEMPLATE_PRODUCT_TEST_CASE(TEST_NAME("invalid shape"), TAG_KERNELS, (DATA_TYPES), (int64_t)) {
using DT = TestType;
using VT = typename DT::VT;

DT * argCond = genGivenVals<DT>(3, {
true, false, false,
false, true, false,
false, false, true
});

DT * argThen = nullptr;
VT argElse;

SECTION("then matrix too small") {
argThen = genGivenVals<DT>(2, {
VT(1.5), 2, 3,
4, 5, 6
});

argElse = VT(-1.5);
}

DT * res = nullptr;

REQUIRE_THROWS_AS(condMatMatSca(res, argCond, argThen, argElse, nullptr), std::runtime_error);

DataObjectFactory::destroy(argCond, argThen);
if (res != nullptr)
DataObjectFactory::destroy(res);
}
99 changes: 99 additions & 0 deletions test/runtime/local/kernels/CondMatScaMatTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright 2024 The DAPHNE Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <runtime/local/datagen/GenGivenVals.h>
#include <runtime/local/datastructures/DenseMatrix.h>
#include <runtime/local/kernels/CheckEq.h>
#include <runtime/local/kernels/CondMatScaMat.h>

#include <tags.h>

#include <catch.hpp>

#include <cstdint>

#define TEST_NAME(opName) "CondMatScaMat (" opName ")"
#define DATA_TYPES DenseMatrix, Matrix
#define VALUE_TYPES int64_t, double

TEMPLATE_PRODUCT_TEST_CASE(TEST_NAME("Matrix"), TAG_KERNELS, (DATA_TYPES), (VALUE_TYPES)) {
using DT = TestType;
using VT = typename DT::VT;

DT * argCond = nullptr;
VT argThen;
DT * argElse = nullptr;
DT * exp = nullptr;

SECTION("example 1") {
argCond = genGivenVals<DT>(3, {
true, false, false,
false, true, false,
false, false, true
});

argThen = VT(-1.5);

argElse = genGivenVals<DT>(3, {
1, 2, 3,
VT(4.5), 5, 6,
7, 8, 9
});
exp = genGivenVals<DT>(3, {
argThen, 2, 3,
VT(4.5), argThen, 6,
7, 8, argThen
});
}

DT * res = nullptr;
condMatScaMat(res, argCond, argThen, argElse, nullptr);

CHECK(*res == *exp);

DataObjectFactory::destroy(argCond, argElse, exp, res);
}

TEMPLATE_PRODUCT_TEST_CASE(TEST_NAME("invalid shape"), TAG_KERNELS, (DATA_TYPES), (int64_t)) {
using DT = TestType;
using VT = typename DT::VT;

DT * argCond = genGivenVals<DT>(3, {
true, false, false,
false, true, false,
false, false, true
});

VT argThen;
DT * argElse = nullptr;

SECTION("else matrix too small") {
argThen = VT(-1.5);

argElse = genGivenVals<DT>(2, {
1, 2, 3,
VT(4.5), 5, 6
});
}

DT * res = nullptr;

REQUIRE_THROWS_AS(condMatScaMat(res, argCond, argThen, argElse, nullptr), std::runtime_error);

DataObjectFactory::destroy(argCond, argElse);
if (res != nullptr)
DataObjectFactory::destroy(res);
}
Loading
Loading