Skip to content

Commit

Permalink
Refactor segment() and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
gvinciguerra committed Apr 2, 2024
1 parent 73f4ef6 commit 750baa1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pygm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__all__ = ['SortedList', 'SortedSet']
__version__ = '1.0'
__version__ = '1.0.1'
__author__ = 'Giorgio Vinciguerra'

import os as _os
Expand Down
22 changes: 8 additions & 14 deletions pygm/pygm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,25 +272,19 @@ template <typename K> class PGMWrapper : private pgm::PGMIndex<K, IGNORED_PARAME
return this->levels_offsets[level_num + 1] - this->levels_offsets[level_num] - 1;
}

std::unordered_map<std::string, double> segment(size_t level_num, size_t segment_num) {
py::dict segment(size_t level_num, size_t segment_num) {
if (level_num >= this->height())
throw std::invalid_argument("level can't be >= index height");
if (segment_num >= num_segments(level_num))
throw std::invalid_argument("segment can't be >= number of segments in level");

std::unordered_map<std::string, double> segment;
segment["epsilon"] = level_num == 0 ? get_epsilon() : get_epsilon_recursive();

auto segment_it = this->segments.begin() + this->levels_offsets[level_num];
for (int sn = segment_num; sn > 0; --sn) {
++segment_it;
}

segment["key"] = segment_it->key;
segment["slope"] = segment_it->slope;
segment["intercept"] = segment_it->intercept;

return segment;
auto &s = this->segments[this->levels_offsets[level_num] + segment_num];
py::dict out;
out["key"] = s.key;
out["slope"] = s.slope;
out["intercept"] = s.intercept;
out["epsilon"] = level_num == 0 ? get_epsilon() : get_epsilon_recursive();
return out;
}

K operator[](size_t i) const { return data[i]; }
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import setuptools
from setuptools.command.build_ext import build_ext

__version__ = '1.0'
__version__ = '1.0.1'


class get_pybind_include(object):
Expand Down Expand Up @@ -117,7 +117,7 @@ def gcc_sort_key(p):
zip_safe=False,
classifiers=[
'License :: OSI Approved :: Apache Software License',
'Development Status :: 3 - Alpha',
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: Science/Research',
Expand All @@ -131,6 +131,9 @@ def gcc_sort_key(p):
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Topic :: Database',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
Expand Down

0 comments on commit 750baa1

Please sign in to comment.