Skip to content

Commit f8ae480

Browse files
committed
Merge branch 'develop' into Kokkos
2 parents eb45c5d + b563c6f commit f8ae480

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

cmake/presets/all.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"displayName": "All available backends",
88
"inherits": "build",
99
"cacheVariables": {
10-
"CMAKE_CXX_COMPILER": "clang++",
1110
"PLSSVM_ENABLE_OPENMP_BACKEND": "AUTO",
1211
"PLSSVM_ENABLE_HPX_BACKEND": "AUTO",
1312
"PLSSVM_ENABLE_STDPAR_BACKEND": "OFF",
@@ -23,7 +22,6 @@
2322
"displayName": "All available backends + Python bindings",
2423
"inherits": "build",
2524
"cacheVariables": {
26-
"CMAKE_CXX_COMPILER": "clang++",
2725
"PLSSVM_ENABLE_OPENMP_BACKEND": "AUTO",
2826
"PLSSVM_ENABLE_HPX_BACKEND": "AUTO",
2927
"PLSSVM_ENABLE_STDPAR_BACKEND": "OFF",
@@ -41,7 +39,6 @@
4139
"displayName": "All available backends tests",
4240
"inherits": "test",
4341
"cacheVariables": {
44-
"CMAKE_CXX_COMPILER": "clang++",
4542
"PLSSVM_ENABLE_OPENMP_BACKEND": "AUTO",
4643
"PLSSVM_ENABLE_HPX_BACKEND": "AUTO",
4744
"PLSSVM_ENABLE_STDPAR_BACKEND": "OFF",

include/plssvm/matrix.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ matrix<T, layout_>::matrix(const plssvm::shape shape, const std::vector<value_ty
496496
template <typename T, layout_type layout_>
497497
matrix<T, layout_>::matrix(const plssvm::shape shape, const_pointer data) :
498498
matrix{ shape } {
499+
if (data == nullptr && this->size() > 0) {
500+
throw matrix_exception{ "The provided data pointer may not be a nullptr if the matrix size is greater than 0!" };
501+
}
499502
if (this->size() > 0) {
500503
// memcpy data to matrix
501504
std::memcpy(this->data(), data, this->size() * sizeof(value_type));
@@ -505,6 +508,9 @@ matrix<T, layout_>::matrix(const plssvm::shape shape, const_pointer data) :
505508
template <typename T, layout_type layout_>
506509
matrix<T, layout_>::matrix(const plssvm::shape shape, const_pointer data, const plssvm::shape padding) :
507510
matrix{ shape, padding } {
511+
if (data == nullptr && this->size() > 0) {
512+
throw matrix_exception{ "The provided data pointer may not be a nullptr if the matrix size is greater than 0!" };
513+
}
508514
if (this->size() > 0) {
509515
// memcpy data row- or column-wise depending on the layout type to the matrix
510516
this->opt_mismatched_padding_copy(this->data(), this->shape_padded(), data, this->shape());

tests/matrix.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,16 @@ TYPED_TEST(Matrix, construct_with_size_and_ptr_empty) {
533533
EXPECT_EQ(matr.shape_padded(), (plssvm::shape{ 0, 0 }));
534534
}
535535

536+
TYPED_TEST(Matrix, construct_with_size_and_nullptr_ptr) {
537+
using real_type = typename TestFixture::fixture_real_type;
538+
constexpr plssvm::layout_type layout = TestFixture::fixture_layout;
539+
540+
// construct a matrix with a specific size and a nullptr
541+
EXPECT_THROW_WHAT((plssvm::matrix<real_type, layout>{ plssvm::shape{ 2, 3 }, nullptr }),
542+
plssvm::matrix_exception,
543+
"The provided data pointer may not be a nullptr if the matrix size is greater than 0!");
544+
}
545+
536546
TYPED_TEST(Matrix, construct_with_size_and_ptr_value_zero_num_rows) {
537547
using real_type = typename TestFixture::fixture_real_type;
538548
constexpr plssvm::layout_type layout = TestFixture::fixture_layout;
@@ -603,6 +613,16 @@ TYPED_TEST(Matrix, construct_with_size_and_ptr_empty_and_padding) {
603613
EXPECT_TRUE(std::all_of(matr.data(), matr.data() + matr.size_padded(), [](const real_type val) { return val == real_type{ 0.0 }; }));
604614
}
605615

616+
TYPED_TEST(Matrix, construct_with_size_and_nullptr_empty_and_padding) {
617+
using real_type = typename TestFixture::fixture_real_type;
618+
constexpr plssvm::layout_type layout = TestFixture::fixture_layout;
619+
620+
// construct a matrix with a specific size, padding and a nullptr
621+
EXPECT_THROW_WHAT((plssvm::matrix<real_type, layout>{ plssvm::shape{ 2, 3 }, nullptr, plssvm::shape{ 4, 5 } }),
622+
plssvm::matrix_exception,
623+
"The provided data pointer may not be a nullptr if the matrix size is greater than 0!");
624+
}
625+
606626
TYPED_TEST(Matrix, construct_with_size_and_ptr_empty_and_zero_padding) {
607627
using real_type = typename TestFixture::fixture_real_type;
608628
constexpr plssvm::layout_type layout = TestFixture::fixture_layout;

0 commit comments

Comments
 (0)