mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-14 19:43:41 +02: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
|
from autograd import jacobian
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numdifftools as nd
|
import numdifftools as nd
|
||||||
|
from itertools import groupby
|
||||||
|
|
||||||
|
|
||||||
class Obs:
|
class Obs:
|
||||||
|
@ -819,6 +820,12 @@ def merge_idx(idl):
|
||||||
----------
|
----------
|
||||||
idl -- List of lists or ranges.
|
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 np.all([type(idx) is range for idx in idl]):
|
||||||
if len(set([idx[0] for idx in idl])) == 1:
|
if len(set([idx[0] for idx in idl])) == 1:
|
||||||
idstart = min([idx.start for idx in idl])
|
idstart = min([idx.start for idx in idl])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue