Changeset 1119


Ignore:
Timestamp:
03/31/21 03:06:34 (11 days ago)
Author:
Maciej Komosinski
Message:

Cache a function reference for better performance

File:
1 edited

Legend:

Unmodified
Added
Removed
  • framspy/FramsticksLib.py

    r1116 r1119  
    143143                n = len(genotype_list)
    144144                square_matrix = np.zeros((n, n))
    145                 genos = []  # prepare an array of Geno objects so we don't need to convert raw strings to Geno objects all the time
     145                genos = []  # prepare an array of Geno objects so that we don't need to convert raw strings to Geno objects all the time in loops
    146146                for g in genotype_list:
    147147                        genos.append(frams.Geno.newFromString(g))
     148                frams_evaluateDistance = frams.SimilMeasure.evaluateDistance  # cache function reference for better performance in loops
    148149                for i in range(n):
    149150                        for j in range(n):  # maybe calculate only one triangle if you really need a 2x speedup
    150                                 square_matrix[i][j] = frams.SimilMeasure.evaluateDistance(genos[i], genos[j])._double()
     151                                square_matrix[i][j] = frams_evaluateDistance(genos[i], genos[j])._double()
    151152
    152153                for i in range(n):
Note: See TracChangeset for help on using the changeset viewer.