Skip to content

Commit

Permalink
Update to recent R package Matrix.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgautier committed Feb 24, 2024
1 parent d111717 commit 49e2580
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 18 deletions.
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = '---'

# The full version, including alpha/beta/rc tags
release = '0.1.0'
release = '0.0.3'


# -- General configuration ---------------------------------------------------
Expand Down
49 changes: 34 additions & 15 deletions rpy2_Matrix/Matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
warnings.simplefilter("ignore")
Matrix_pack = importr('Matrix', on_conflict="warn")

TARGET_VERSION = '1.4-'
TARGET_VERSION = '1.6-'

if not Matrix_pack.__version__.startswith(TARGET_VERSION):
warnings.warn(
Expand Down Expand Up @@ -50,20 +50,13 @@ def _setExtractDelegators(self):
self.rx2 = vectors.DoubleExtractDelegator(self)


class mMatrix(metaclass=rpy2.robjects.methods.RS4Auto_Type):
"""Mapping for the RS4 class Matrix::mMatrix."""
__rname__ = 'mMatrix'
__rpackagename__ = 'Matrix'


class replValueSp(metaclass=rpy2.robjects.methods.RS4Auto_Type):
"""Mapping for the RS4 class Matrix::replValueSp."""
__rname__ = 'replValueSp'
__rpackagename__ = 'Matrix'


class Matrix(mMatrix, replValueSp):
"""Mapping for the RS4 class Matrix::Matrix."""
class Matrix(replValueSp):
__rname__ = 'Matrix'
__rpackagename__ = 'Matrix'

Expand Down Expand Up @@ -159,7 +152,7 @@ def new(i=vectors.MissingArg, j=vectors.MissingArg,
unclassed_obj = Matrix_pack.sparseMatrix(
i=i, j=j, p=p, x=x, dims=dims, dimnames=dimnames,
symmetric=symmetric, triangular=triangular, index1=index1,
giveCsparse=giveCsparse, check=check, use_last_ij=use_last_ij)
repr=repr, check=check, use_last_ij=use_last_ij)
wrapcls = _classmap.get(unclassed_obj.rclass[0])
if wrapcls is None:
# TODO: issue a warning if no class map ?
Expand Down Expand Up @@ -216,24 +209,46 @@ class CsparseMatrix(sparseMatrix):
__rname__ = 'CsparseMatrix'


class ddenseMatrix(dMatrix, denseMatrix):
__rname__ = 'ddenseMatrix'


class unpackedMatrix(denseMatrix):
__rname__ = 'denseMatrix'


class dgeMatrix(unpackedMatrix, ddenseMatrix, generalMatrix):
__rname__ = 'dgeMatrix'


class dsparseMatrix(dMatrix, sparseMatrix):
"""Mapping for the RS4 class Matrix::dsparseMatrix."""
__rname__ = 'dsparseMatrix'


class dsyMatrix(symmetricMatrix, ddenseMatrix):
__rname__ = 'dsyMatrix'


class dpoMatrix(dsyMatrix):
__rname__ = 'dpoMatrix'


class corMatrix(dpoMatrix):
__rname__ = 'corMatrix'


class dgCMatrix(dsparseMatrix, generalMatrix,
RS4Vector):
"""Mapping for the RS4 class Matrix::dcgMatrix."""
__rname__ = 'dgCMatrix'


class dCsparseMatrix(sparseMatrix):
"""Mapping for the RS4 class Matrix::dCsparseMatrix."""
__rname__ = 'dCsparseMatrix'

class CsparseMatrix(sparseMatrix):
__rname__ = 'CsparseMatrix'


class dsCMatrix(CsparseMatrix, dsparseMatrix, symmetricMatrix,
dCsparseMatrix,
RS4Vector):
"""Mapping for the RS4 class Matrix::dsCMatrix."""
__rname__ = 'dsCMatrix'
Expand Down Expand Up @@ -280,6 +295,10 @@ class dgTMatrix(TsparseMatrix, dsparseMatrix, generalMatrix,
'lgCMatrix': lgCMatrix,
'ngCMatrix': ngCMatrix,
'dgTMatrix': dgTMatrix,
'dgTMatrix': dgTMatrix,
'dsyMatrix': dsyMatrix,
'dpoMatrix': dpoMatrix,
'corMatrix': corMatrix,
}

nameclassmap = (rpy2.robjects
Expand Down
2 changes: 1 addition & 1 deletion rpy2_Matrix/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.2'
__version__ = '0.0.3'
17 changes: 16 additions & 1 deletion rpy2_Matrix/test_Matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@

@pytest.mark.parametrize(
'args,expected_cls',
<<<<<<< Updated upstream
[((0, 2, 3), Matrix.generalMatrix),
((0, 2, 2), Matrix.ddiMatrix),
((IntVector([0, 1, 2, 3]), 2, 2), Matrix.dgeMatrix)]
=======
[(((0, ), 2, 3), Matrix.generalMatrix),
(((0, 1, 1, 0), 2, 2), Matrix.symmetricMatrix)]
>>>>>>> Stashed changes
)
def test_Matrix(args, expected_cls):
m = Matrix.Matrix.new(*args)
final_args = (robjects.baseenv['c'](*(args[0])),
args[1], args[2])
m = Matrix.Matrix.new(*final_args)
assert isinstance(m, expected_cls)


@pytest.mark.parametrize(
'args,kwargs,expected_cls',
[((IntVector([1, 3, 4]), IntVector([2, 3, 5])),
<<<<<<< Updated upstream
{'x': IntVector([3, 9, 21])},
Matrix.dgCMatrix),
((IntVector([1, 2, 3]), IntVector([2, 3, 4])),
Expand All @@ -29,6 +37,13 @@ def test_Matrix(args, expected_cls):
IntVector([7, 6, 5, 4, 3, 2])),
{},
Matrix.ngCMatrix)]
=======
{'x': IntVector([3, 9, 21]), 'repr': 'C'},
Matrix.sparseMatrix),
((IntVector([1, 3, 4]), IntVector([2, 3, 5])),
{'x': IntVector([3, 9, 21]), 'repr': 'T'},
Matrix.sparseMatrix)]
>>>>>>> Stashed changes
)
def test_sparseMatrix(args, kwargs, expected_cls):
m = Matrix.sparseMatrix.new(*args, **kwargs)
Expand Down

0 comments on commit 49e2580

Please sign in to comment.