Commit a3befd28 authored by Martin Larralde's avatar Martin Larralde
Browse files

Implement `TrainingInfo.__sizeof__` as a `cpdef` function

parent 01f1b84f
......@@ -38,6 +38,7 @@ cdef class Masks:
) nogil except NULL
cdef int _clear(self) nogil
cpdef size_t __sizeof__(self)
cpdef list __getstate__(self)
cpdef object __setstate__(self, list state)
......@@ -76,6 +77,7 @@ cdef class Sequence:
const int strand
) nogil
cpdef size_t __sizeof__(self)
cpdef dict __getstate__(self)
cpdef object __setstate__(self, dict state)
......@@ -181,6 +183,7 @@ cdef class Nodes:
cdef size_t capacity
cdef size_t length
cpdef size_t __sizeof__(self)
cpdef list __getstate__(self)
cpdef object __setstate__(self, list state)
......@@ -268,6 +271,8 @@ cdef class Genes:
cdef readonly Sequence sequence
cdef readonly TrainingInfo training_info
cpdef size_t __sizeof__(self)
cdef inline _gene* _add_gene(
self,
const int begin,
......@@ -296,6 +301,7 @@ cdef class TrainingInfo:
cdef bint owned
cdef _training* tinf
cpdef size_t __sizeof__(self)
cpdef dict __getstate__(self)
cpdef object __setstate__(self, dict state)
......
......@@ -180,6 +180,7 @@ class Genes(typing.Sequence[Gene]):
def __getitem__(self, index: int) -> Gene: ...
def __iter__(self) -> Iterator[Gene]: ...
def __reversed__(self) -> Iterator[Gene]: ...
def __sizeof__(self) -> int: ...
def clear(self) -> None: ...
def write_gff(self, file: TextIO, prefix: str = "gene_") -> int: ...
def write_genes(self, file: TextIO, prefix: str ="gene_", width: typing.Optional[int] = 70) -> int: ...
......@@ -196,6 +197,7 @@ class TrainingInfo:
def __repr__(self) -> str: ...
def __getstate__(self) -> Dict[str, object]: ...
def __setstate__(self, state: Dict[str, object]) -> None: ...
def __sizeof__(self) -> int: ...
@property
def translation_table(self) -> int: ...
@translation_table.setter
......
......@@ -171,7 +171,7 @@ cdef class Masks:
mask.mask = &self.masks[index]
return mask
def __sizeof__(self):
cpdef size_t __sizeof__(self):
return self.capacity * sizeof(_mask) + sizeof(self)
cpdef list __getstate__(self):
......@@ -403,7 +403,7 @@ cdef class Sequence:
def __len__(self):
return self.slen
def __sizeof__(self):
cpdef size_t __sizeof__(self):
return self.slen * sizeof(uint8_t) + sizeof(self)
def __str__(self):
......@@ -1519,7 +1519,7 @@ cdef class Nodes:
node.node = &self.nodes[index]
return node
def __sizeof__(self):
cpdef size_t __sizeof__(self):
return self.capacity * sizeof(_node) + sizeof(self)
cpdef list __getstate__(self):
......@@ -2487,8 +2487,8 @@ cdef class Nodes:
# NOTE: Use a custom structure to store the gene data instead of the one
# declared in `gene.h` to save some memory; in Prodigal, gene structures
# each allocated 1,000 bytes of string data for each gene. In Pyrodigal,
# we build these on request through a property, so we don't have to
# reserve extract memory for anymore.
# we build these strings on request through a property, so we don't have
# to reserve extra memory anymore.
cdef struct _gene:
int begin
int end
......@@ -2957,7 +2957,7 @@ cdef class Genes:
gene.gene = &self.genes[index]
return gene
def __sizeof__(self):
cpdef size_t __sizeof__(self):
return self.capacity * sizeof(_gene) + sizeof(self)
# --- C interface --------------------------------------------------------
......@@ -3447,15 +3447,10 @@ cdef class TrainingInfo:
.. versionadded:: 0.6.4
"""
cdef char[:] contents
cdef object mem
cdef ssize_t n
cdef TrainingInfo tinf = TrainingInfo.__new__(TrainingInfo)
tinf.owned = True
tinf.tinf = <_training*> PyMem_Malloc(sizeof(_training))
if tinf.tinf == NULL:
raise MemoryError("Failed to allocate training info")
cdef ssize_t n
cdef object mem
cdef char[:] contents
cdef TrainingInfo tinf = cls(50.0)
if hasattr(fp, "readinto"):
mem = PyMemoryView_FromMemory(<char*> tinf.tinf, sizeof(_training), MVIEW_WRITE)
......@@ -3506,6 +3501,9 @@ cdef class TrainingInfo:
self.uses_sd,
)
cpdef size_t __sizeof__(self):
return sizeof(_training) + sizeof(self)
cpdef dict __getstate__(self):
"""__getstate__(self)\n--
"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment