power_index_factory.py 945 Bytes
Newer Older
1
# -*- coding: utf-8 -*-
2
from power_indices import PowerIndices
3
4
5
6
7
8


class _PowerIndexFactory(object):
    def __init__(self):
        self.power_indices_storage = {}

theos's avatar
theos committed
9
10
    def get_power_indices(self, domain, distribution_strategy,
                          log=False, nbin=None, binbounds=None):
11
        current_hash = domain.__hash__() ^ (111*hash(distribution_strategy))
12
13

        if current_hash not in self.power_indices_storage:
14
15
16
            self.power_indices_storage[current_hash] = \
                PowerIndices(domain, distribution_strategy,
                             log=log, nbin=nbin, binbounds=binbounds)
17
18
19
20
21
22
23
24
        power_indices = self.power_indices_storage[current_hash]
        power_index = power_indices.get_index_dict(log=log,
                                                   nbin=nbin,
                                                   binbounds=binbounds)
        return power_index


PowerIndexFactory = _PowerIndexFactory()