diff --git a/ChangeLog b/ChangeLog index cb582cc3f..7ec6570b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2026-09-22 Iñaki Ucar + + * inst/include/Rcpp/sugar/matrix/col.h: Fix Col constructor using ncol() + instead of nrow() to set the number of rows + * inst/tinytest/test_sugar.R: Add a non-square matrix test case for the + row()/col() sugar functions + 2026-09-05 Iñaki Ucar * .github/workflows/werror.yaml: Add -Wconversion diff --git a/inst/include/Rcpp/sugar/matrix/col.h b/inst/include/Rcpp/sugar/matrix/col.h index 6575720e5..80d0f129c 100644 --- a/inst/include/Rcpp/sugar/matrix/col.h +++ b/inst/include/Rcpp/sugar/matrix/col.h @@ -35,7 +35,7 @@ class Col : public MatrixBase< public: typedef Rcpp::MatrixBase LHS_TYPE ; - Col( const LHS_TYPE& lhs) : nr( static_cast(lhs.ncol()) ), nc( static_cast(lhs.ncol()) ) {} + Col( const LHS_TYPE& lhs) : nr( static_cast(lhs.nrow()) ), nc( static_cast(lhs.ncol()) ) {} inline int operator()( int /*i*/, int j ) const { return j + 1 ; diff --git a/inst/tinytest/test_sugar.R b/inst/tinytest/test_sugar.R index c6fc58993..1115dced7 100644 --- a/inst/tinytest/test_sugar.R +++ b/inst/tinytest/test_sugar.R @@ -592,6 +592,14 @@ target <- list( row = row(m), col = col(m) ) expect_equal( res, target ) +# test.sugar.matrix.row.nonsquare <- function( ){ +fx <- runit_row +m <- matrix(1:24, nrow = 6, ncol = 4) +res <- fx(m) +target <- list(row = row(m), col = col(m)) +expect_equal(res, target) + + # test.sugar.diag <- function( ){ fx <- runit_diag