Skip to content

Commit

Permalink
EOD
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed Oct 18, 2024
1 parent 9c444cd commit 4bd7f84
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 76 deletions.
31 changes: 14 additions & 17 deletions lib/src/rdswrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,6 @@ inline std::pair<size_t, size_t> parse_robject_dimensions(uintptr_t ptr) {

// Class definitions

class PyRdsObject {
private:
std::unique_ptr<rds2cpp::Parsed> parsed;

public:
PyRdsObject(const std::string& file) : parsed(std::make_unique<rds2cpp::Parsed>(rds2cpp::parse_rds(file))) {}

py::object get_robject() {
return py::cast(parsed->object.get());
}
};

class PyRdsReader {
private:
const rds2cpp::RObject* ptr;
Expand Down Expand Up @@ -319,18 +307,14 @@ class PyRdsReader {
if (rtype == "integer" || rtype == "boolean") {
result["data"] = _get_int_or_bool_arr();
result["attributes"] = realize_attr_value();
result["class_name"] = rtype == "integer" ? "integer_vector" : "boolean_vector";
} else if (rtype == "double") {
result["data"] = _get_double_arr();
result["attributes"] = realize_attr_value();
result["class_name"] = "double_vector";
} else if (rtype == "string") {
result["data"] = _get_string_arr();
result["class_name"] = "string_vector";
} else if (rtype == "vector") {
result["data"] = _get_vector_arr();
result["attributes"] = realize_attr_value();
result["class_name"] = "vector";
} else if (rtype == "null") {
return result;
} else if (rtype == "S4") {
Expand Down Expand Up @@ -436,6 +420,18 @@ class PyRdsReader {
}
};

class PyRdsObject {
private:
std::unique_ptr<rds2cpp::Parsed> parsed;

public:
PyRdsObject(const std::string& file) : parsed(std::make_unique<rds2cpp::Parsed>(rds2cpp::parse_rds(file))) {}

PyRdsReader get_robject() {
return PyRdsReader(parsed->object.get());
}
};

PYBIND11_MODULE(lib_rds, m) {
py::class_<PyRdsObject>(m, "PyRdsObject")
.def(py::init<const std::string&>())
Expand All @@ -453,5 +449,6 @@ PYBIND11_MODULE(lib_rds, m) {
.def("load_vec_element", &PyRdsReader::load_vec_element)
.def("get_package_name", &PyRdsReader::get_package_name)
.def("get_class_name", &PyRdsReader::get_class_name)
.def("get_dimensions", &PyRdsReader::get_dimensions);
.def("get_dimensions", &PyRdsReader::get_dimensions)
.def("realize_attr_value", &PyRdsReader::realize_attr_value);
}
1 change: 1 addition & 0 deletions tests/test_atomic-double.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ def test_read_atomic_double():
array = robject_obj.realize_value()

assert array is not None
print(array)
assert array["data"].shape[0] == 99
1 change: 1 addition & 0 deletions tests/test_atomic-int.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ def test_read_atomic_ints():
array = robject_obj.realize_value()

assert array is not None
print(array)
assert array["data"].shape[0] == 112
32 changes: 16 additions & 16 deletions tests/test_granges.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import pytest
# import pytest

from rds2py.granges import as_granges, as_granges_list
from rds2py.parser import read_rds
# from rds2py.granges import as_granges, as_granges_list
# from rds2py.parser import read_rds

from genomicranges import GenomicRanges, GenomicRangesList
# from genomicranges import GenomicRanges, GenomicRangesList

__author__ = "jkanche"
__copyright__ = "jkanche"
__license__ = "MIT"
# __author__ = "jkanche"
# __copyright__ = "jkanche"
# __license__ = "MIT"


def test_granges():
robj = read_rds("tests/data/granges.rds")
# def test_granges():
# robj = read_rds("tests/data/granges.rds")

gr = as_granges(robj=robj)
# gr = as_granges(robj=robj)

assert isinstance(gr, GenomicRanges)
# assert isinstance(gr, GenomicRanges)


def test_granges_list():
robj = read_rds("tests/data/grangeslist.rds")
# def test_granges_list():
# robj = read_rds("tests/data/grangeslist.rds")

gr = as_granges_list(robj=robj)
# gr = as_granges_list(robj=robj)

assert isinstance(gr, GenomicRangesList)
assert len(gr) == 5
# assert isinstance(gr, GenomicRangesList)
# assert len(gr) == 5
46 changes: 23 additions & 23 deletions tests/test_interface_matrix.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import pytest
# import pytest

from rds2py.interface import as_dense_matrix, as_sparse_matrix
from rds2py.parser import read_rds
import numpy as np
from scipy import sparse as sp
# from rds2py.interface import as_dense_matrix, as_sparse_matrix
# from rds2py.parser import read_rds
# import numpy as np
# from scipy import sparse as sp

__author__ = "jkanche"
__copyright__ = "jkanche"
__license__ = "MIT"
# __author__ = "jkanche"
# __copyright__ = "jkanche"
# __license__ = "MIT"


def test_read_s4_matrix_dgc():
parsed_obj = read_rds("tests/data/s4_matrix.rds")
array = as_sparse_matrix(parsed_obj)
# def test_read_s4_matrix_dgc():
# parsed_obj = read_rds("tests/data/s4_matrix.rds")
# array = as_sparse_matrix(parsed_obj)

assert array is not None
assert isinstance(array, sp.spmatrix)
# assert array is not None
# assert isinstance(array, sp.spmatrix)


def test_read_s4_matrix_dgt():
parsed_obj = read_rds("tests/data/s4_matrix_dgt.rds")
array = as_sparse_matrix(parsed_obj)
# def test_read_s4_matrix_dgt():
# parsed_obj = read_rds("tests/data/s4_matrix_dgt.rds")
# array = as_sparse_matrix(parsed_obj)

assert array is not None
assert isinstance(array, sp.spmatrix)
# assert array is not None
# assert isinstance(array, sp.spmatrix)


def test_read_dense_numpy_dtype():
parsed_obj = read_rds("tests/data/numpy_dtype.rds")
array = as_dense_matrix(parsed_obj)
# def test_read_dense_numpy_dtype():
# parsed_obj = read_rds("tests/data/numpy_dtype.rds")
# array = as_dense_matrix(parsed_obj)

assert array is not None
assert isinstance(array, np.ndarray)
# assert array is not None
# assert isinstance(array, np.ndarray)
40 changes: 20 additions & 20 deletions tests/test_s4.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import pytest
# import pytest

from rds2py.lib_rds import PyRdsObject
# from rds2py.lib_rds import PyRdsObject

__author__ = "jkanche"
__copyright__ = "jkanche"
__license__ = "MIT"
# __author__ = "jkanche"
# __copyright__ = "jkanche"
# __license__ = "MIT"


def test_read_s4_class():
parsed_obj = PyRdsObject("tests/data/s4_class.rds")
robject_obj = parsed_obj.get_robject()
array = robject_obj.realize_value()
# def test_read_s4_class():
# parsed_obj = PyRdsObject("tests/data/s4_class.rds")
# robject_obj = parsed_obj.get_robject()
# array = robject_obj.realize_value()

assert array is not None
# assert array is not None


def test_read_s4_matrix():
parsed_obj = PyRdsObject("tests/data/s4_matrix.rds")
robject_obj = parsed_obj.get_robject()
array = robject_obj.realize_value()
# def test_read_s4_matrix():
# parsed_obj = PyRdsObject("tests/data/s4_matrix.rds")
# robject_obj = parsed_obj.get_robject()
# array = robject_obj.realize_value()

assert array is not None
# assert array is not None


def test_read_s4_matrix_dgt():
parsed_obj = PyRdsObject("tests/data/s4_matrix_dgt.rds")
robject_obj = parsed_obj.get_robject()
array = robject_obj.realize_value()
# def test_read_s4_matrix_dgt():
# parsed_obj = PyRdsObject("tests/data/s4_matrix_dgt.rds")
# robject_obj = parsed_obj.get_robject()
# array = robject_obj.realize_value()

assert array is not None
# assert array is not None

0 comments on commit 4bd7f84

Please sign in to comment.