Skip to content

Commit

Permalink
Fixes for memmap compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
softwaredoug committed Jul 7, 2024
1 parent 93cf0a6 commit 8d35eda
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions searcharray/phrase/memmap_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def from_arrays(arrays: List[np.ndarray]):
@staticmethod
def from_array_with_boundaries(data: np.ndarray,
ids: np.ndarray,
boundaries):
boundaries: np.ndarray):
metadata = {}
for idx, (beg, end) in enumerate(zip(boundaries[:-1], boundaries[1:])):
offset = beg
length = end - beg
offset = int(beg)
length = int(end - beg)
actual_id = ids[idx]
metadata[actual_id] = {'offset': offset, 'length': length}
metadata[int(actual_id)] = {'offset': offset, 'length': length}
arr = ArrayDict()
arr.data = data
arr.metadata = metadata
Expand Down Expand Up @@ -109,17 +109,18 @@ def __init__(self,
self.fp = None
self.metadata_file = root_filename + '.metadata.json'
if arrays is not None:
self._initialize_file(arrays)
self.arrays = arrays
self._initialize_file()
self._save_metadata()
else:
self._load_metadata()
self._load_fp()

def _initialize_file(self, arrays_dict):
def _initialize_file(self):
"""Memmap underlying array in ArrayDict."""
self.metadata = {}
with open(self.filename, 'wb') as f:
self.array.data.astype(self.dtype).tofile(f)
self.arrays.data.tofile(f)

def _save_metadata(self):
with open(self.metadata_file, 'w') as f:
Expand Down

0 comments on commit 8d35eda

Please sign in to comment.