Skip to content

modify choose method to make it faster#167

Merged
ElinaFF merged 1 commit into
mainfrom
166-make-split-markov-graph-faster
Apr 3, 2025
Merged

modify choose method to make it faster#167
ElinaFF merged 1 commit into
mainfrom
166-make-split-markov-graph-faster

Conversation

@MathieuBazinet

Copy link
Copy Markdown
Collaborator

j'ai testé la fonction choose du code vs la fonction math.comb

def choose(k, n):
      if n > k:
          return 0
      if n < 0:
          return 0
      if k < 0:
          return 0
      a = 1
      b = 1
      for i in range(1, n + 1):
          a = a * i
          b = b * (k - i + 1)
      return Decimal(b) / Decimal(a)

choose(1000,500)
def new_choose(k, n):
     if n > k:
         return 0
     if n < 0:
         return 0
     if k < 0:
         return 0
     return math.comb(k,n)

On a
choose(1000,10) = Decimal('263409560461970212832400')

et
new_choose(1000,10) = 263409560461970212832400

Voici les résultats que ça m'a donné quand j'ai fait les tests. On est passé de 2 minutes 30 secondes à 17 secondes (le tout sur un environnement colab)
graphique_faster

@MathieuBazinet MathieuBazinet linked an issue Feb 26, 2025 that may be closed by this pull request
@ElinaFF ElinaFF merged commit 6f74d39 into main Apr 3, 2025
@ElinaFF ElinaFF deleted the 166-make-split-markov-graph-faster branch April 3, 2025 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

make split Markov graph faster

2 participants