Exemple #1
0
    def generate_next_block(
            self,
            batch_size: int) -> SearchMetadata[SuperabundantEnumerationIndex]:
        starting_index = deepcopy(self._search_index)
        '''
        Because a block can cross multiple levels, we need to possibly split
        the block into pieces.
        '''
        ending_level_index = self._search_index.index_in_level + batch_size - 1
        while ending_level_index >= len(self.current_level):
            ending_level_index -= len(self.current_level)
            self._search_index = SuperabundantEnumerationIndex(
                level=self._search_index.level + 1, index_in_level=0)
            self.__maybe_reset_current_level__()  # definitely

        ending_index = SuperabundantEnumerationIndex(
            level=self._search_index.level, index_in_level=ending_level_index)

        if (ending_level_index == len(self.current_level) - 1):
            self._search_index = SuperabundantEnumerationIndex(
                level=self._search_index.level + 1, index_in_level=0)
            self.__maybe_reset_current_level__()  # definitely
        else:
            self._search_index = SuperabundantEnumerationIndex(
                level=self._search_index.level,
                index_in_level=ending_level_index + 1)

        return SearchMetadata(
            starting_search_index=starting_index,
            ending_search_index=ending_index,
            search_index_type='SuperabundantEnumerationIndex',
        )
    def next_batch(self, batch_size: int) -> List[RiemannDivisorSum]:
        sums = []
        '''
        Because a batch can cross multiple levels, we need to possibly split
        the batch into pieces.
        '''
        ending_level_index = self.search_index.index_in_level + batch_size - 1
        while ending_level_index >= len(self.current_level):
            for i in range(self.search_index.index_in_level,
                           len(self.current_level)):
                fac = partition_to_prime_factorization(self.current_level[i])
                sums.append(superabundant.compute_riemann_divisor_sum(fac))

            ending_level_index -= len(self.current_level)
            self.search_index = SuperabundantEnumerationIndex(
                level=self.search_index.level + 1, index_in_level=0)
            self.__maybe_reset_current_level__()  # definitely

        for i in range(self.search_index.index_in_level,
                       ending_level_index + 1):
            fac = partition_to_prime_factorization(self.current_level[i])
            sums.append(superabundant.compute_riemann_divisor_sum(fac))
            self.search_index = SuperabundantEnumerationIndex(
                level=self.search_index.level,
                index_in_level=self.search_index.index_in_level + 1)

        return sums
Exemple #3
0
    def process_block(
        self, block: SearchMetadata[SuperabundantEnumerationIndex]
    ) -> List[RiemannDivisorSum]:
        sums = []
        current_index = block.starting_search_index
        ending_index = block.ending_search_index
        current_level = CachedPartitionsOfN(current_index.level)

        while current_index.level < ending_index.level:
            for i in range(current_index.index_in_level, len(current_level)):
                fac = partition_to_prime_factorization(current_level[i])
                sums.append(superabundant.compute_riemann_divisor_sum(fac))

            current_index = SuperabundantEnumerationIndex(
                level=current_index.level + 1,
                index_in_level=0,
            )
            current_level = CachedPartitionsOfN(current_index.level)

        for i in range(current_index.index_in_level,
                       ending_index.index_in_level + 1):
            fac = partition_to_prime_factorization(current_level[i])
            sums.append(superabundant.compute_riemann_divisor_sum(fac))

        return sums
Exemple #4
0
    def test_search_block_with_mpz_values(self, db):
        metadatas = [
            SearchMetadata(search_index_type='SuperabundantEnumerationIndex',
                           starting_search_index=SuperabundantEnumerationIndex(
                               level=i, index_in_level=0),
                           ending_search_index=SuperabundantEnumerationIndex(
                               level=i + 1, index_in_level=0))
            for i in range(1, 10, 2)
        ]
        db.insert_search_blocks(metadatas)

        block = db.claim_next_search_block(
            search_index_type='SuperabundantEnumerationIndex')

        records = [
            RiemannDivisorSum(n=mpz(1), divisor_sum=mpz(1), witness_value=1),
            RiemannDivisorSum(n=mpz(2), divisor_sum=mpz(2), witness_value=2),
        ]

        db.finish_search_block(block, records)
        stored = list(db.load())
        assert len(stored) == 1
        assert stored[0].n == 2
from riemann.search_strategy import SuperabundantSearchStrategy
from riemann.types import SuperabundantEnumerationIndex
import tracemalloc

tracemalloc.start()

search_strategy = SuperabundantSearchStrategy().starting_from(
    SuperabundantEnumerationIndex(71, 196047))
batch = search_strategy.next_batch(250000)

snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.statistics('lineno')

print("[ Top 10 ]")
for stat in top_stats[:10]:
    print(stat)
Exemple #6
0
 def __init__(self):
     self._search_index = SuperabundantEnumerationIndex(level=1,
                                                        index_in_level=0)
     self.current_level = CachedPartitionsOfN(1)
     self.__maybe_reset_current_level__()
     self._index_name = self._search_index.__class__.__name__
 def __init__(self):
     self.search_index = SuperabundantEnumerationIndex(level=1,
                                                       index_in_level=0)
     self.current_level = [[1]]
     self.__maybe_reset_current_level__()