mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-03-15 14:50:25 +01:00
speed up of merge_idx
This commit is contained in:
parent
100228d373
commit
96721431c3
1 changed files with 7 additions and 0 deletions
|
@ -8,6 +8,7 @@ import autograd.numpy as anp # Thinly-wrapped numpy
|
|||
from autograd import jacobian
|
||||
import matplotlib.pyplot as plt
|
||||
import numdifftools as nd
|
||||
from itertools import groupby
|
||||
|
||||
|
||||
class Obs:
|
||||
|
@ -819,6 +820,12 @@ def merge_idx(idl):
|
|||
----------
|
||||
idl -- List of lists or ranges.
|
||||
"""
|
||||
|
||||
# Use groupby to efficiently check whether all elements of idl are identical
|
||||
g = groupby(idl)
|
||||
if next(g, True) and not next(g, False):
|
||||
return idl[0]
|
||||
|
||||
if np.all([type(idx) is range for idx in idl]):
|
||||
if len(set([idx[0] for idx in idl])) == 1:
|
||||
idstart = min([idx.start for idx in idl])
|
||||
|
|
Loading…
Add table
Reference in a new issue