Skip to content
Open
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 DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Version: 1.2.0
Date: 2024-02-29
Maintainer: Vissarion Fisikopoulos <vissarion.fisikopoulos@gmail.com>
Depends: Rcpp (>= 0.12.17)
Imports: methods, stats, Matrix
Imports: methods, stats, Matrix, Rcpp
LinkingTo: Rcpp, RcppEigen, BH
Suggests: testthat
Encoding: UTF-8
Expand Down
2 changes: 1 addition & 1 deletion R/HpolytopeClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Hpolytope <- setClass (

# Defining slot type
representation (
A = "matrix",
A = "ANY",
b = "numeric",
volume = "numeric",
type = "character"
Expand Down
5 changes: 3 additions & 2 deletions R/HpolytopeSparseClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#'
#' \item{bineq}{An \eqn{m}-dimensional vector for the ineqaulities.}
#'
#' \item{Aineq}{An \eqn{m'\times d} sparse numerical matrix for the equalities.}
#' \item{Aeq}{An m'×d sparse numerical matrix for the equalities.}
#'
#' \item{bineq}{An \eqn{m'}-dimensional vector for the eqaulities.}
#' \item{beq}{An m'-dimensional vector for the equalities.}
#'
#' \item{lb}{\eqn{d}-dimensional vector lb.}
#'
Expand All @@ -20,6 +20,7 @@
#' \item{type}{A character with default value 'HpolytopeSparse', to declare the representation of the polytope.}
#' }
#'
#' @import Matrix
#' @examples
#' library(Matrix)
#' bineq=c(10,10,10,10,10)
Expand Down
23 changes: 23 additions & 0 deletions src/sparse_hpolytope.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// [[Rcpp::depends(RcppEigen)]]
#include <RcppEigen.h>

using namespace Rcpp;
using Eigen::SparseMatrix;
using Eigen::VectorXd;

// [[Rcpp::export]]
SEXP create_sparse_hpolytope(const SparseMatrix<double> &A,
const VectorXd &b) {

// Get dimensions
int m = A.rows();
int n = A.cols();

// Proof that sparse matrix arrived correctly
return List::create(
Named("rows") = m,
Named("cols") = n,
Named("nonzeros") = A.nonZeros(),
Named("b_length") = b.size()
);
}
12 changes: 12 additions & 0 deletions tests/testthat/test-sparse.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
library(Matrix)
library(Rvolesti)

test_that("Sparse Hpolytope works", {

A <- rsparsematrix(10, 5, density = 0.2)
b <- rep(1, 10)

P <- Hpolytope(A, b)

expect_true(inherits(P, "Hpolytope_sparse"))
})