Skip to content

Commit

Permalink
refactor: define tilde_o functions
Browse files Browse the repository at this point in the history
  • Loading branch information
0fprod committed Mar 22, 2023
1 parent fabe67e commit 9e9a477
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions cryptographic_estimators/base_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ def complexity_type(self, input_type: Union[int, str]):
if self._complexity_type != new_type:
self.reset()
self._complexity_type = new_type

def memory_access_cost(self, mem: float):
"""
INPUT:
- ```mem`` -- memory consumption of an algorithm
- ```memory_access`` -- specifies the memory access cost model
(default: 0, choices:
Expand All @@ -134,7 +134,7 @@ def memory_access_cost(self, mem: float):
2 - square-root,
3 - cube-root or deploy custom function which takes as input the
logarithm of the total memory usage)
"""
if self._memory_access == 0:
return 0
Expand Down Expand Up @@ -217,6 +217,28 @@ def _compute_memory_complexity(self, parameters: dict):
"""
raise NotImplementedError

def _compute_tilde_o_time_complexity(self, parameters):
"""
Compute and return the tilde-O time complexity of the algorithm for a given set of parameters
INPUT:
- ``parameters`` -- dictionary including the parameters
"""
raise NotImplementedError

def _compute_tilde_o_memory_complexity(self, parameters):
"""
Compute and return the tilde-O memory complexity of the algorithm for a given set of parameters
INPUT:
- ``parameters`` -- dictionary including the parameters
"""
raise NotImplementedError

def _get_optimal_parameter_methods_(self):
"""
Return a list of methods decorated with @optimal_parameter ordered by linenumber of appearance
Expand Down Expand Up @@ -260,7 +282,7 @@ def _find_optimal_parameters(self):
tmp_memory = self._compute_memory_complexity(params)
if self.bit_complexities:
tmp_memory = self.problem.to_bitcomplexity_memory(tmp_memory)

tmp_time += self.memory_access_cost(tmp_memory)

if tmp_time < time and tmp_memory <= self.problem.memory_bound:
Expand Down Expand Up @@ -400,9 +422,10 @@ def time_complexity(self, **kwargs):
if self.bit_complexities:
self._time_complexity = self.problem.to_bitcomplexity_time(
self._time_complexity)

if self._memory_access != 0:
self._time_complexity += self.memory_access_cost(self.memory_complexity())
self._time_complexity += self.memory_access_cost(
self.memory_complexity())
else:
self._time_complexity = self._compute_tilde_o_time_complexity(
params)
Expand Down

0 comments on commit 9e9a477

Please sign in to comment.