Skip to content

Commit

Permalink
Merge pull request #27 from ashvardanian/main-dev
Browse files Browse the repository at this point in the history
Reorganize repo and test shuffles
  • Loading branch information
ashvardanian authored Aug 29, 2023
2 parents 6ce22bd + 0ad0e76 commit e0a1466
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions stringzilla/pybind11.cpp → python/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ struct py_file_t : public py_span_t {
#endif
}

std::shared_ptr<py_str_t> load() const { return std::make_shared<py_str_t>(to_stl(*this)); }

using py_span_t::contains;
using py_span_t::count;
using py_span_t::find;
Expand Down Expand Up @@ -676,6 +678,7 @@ PYBIND11_MODULE(stringzilla, m) {
define_slice_ops(py_file);
py_file.def("open", &py_file_t::open, py::arg("path"));
py_file.def("open", &py_file_t::reopen);
py_file.def("load", &py_file_t::load);
py_file.def("close", &py_file_t::close);
py_file.def("__getitem__", [](py_file_t &s, py::slice slice) {
ssize_t start, stop, step, length;
Expand Down
5 changes: 5 additions & 0 deletions scripts/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ def test_strs_operations():
assert lines[8] == "line2"
assert lines[12] == "line6"

# Test that shuffles are reproducible with the same `seed`
a = [str(s) for s in lines.shuffled(seed=42)]
b = [str(s) for s in lines.shuffled(seed=42)]
assert a == b


@pytest.mark.parametrize("repetitions", range(1, 10))
def test_basic(repetitions: int):
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
ext_modules = [
Pybind11Extension(
"stringzilla",
["stringzilla/pybind11.cpp"],
["python/lib.cpp"],
include_dirs=["stringzilla"],
extra_compile_args=compile_args,
extra_link_args=link_args,
define_macros=macros_args,
Expand Down

0 comments on commit e0a1466

Please sign in to comment.