Return the length of the trace.

        :Parameters:
        chain : int or None
          The chain index. If None, returns the combined length of all chains.
487149
def length(self, chain=-1):
        
        if chain is not None:
            if chain < 0:
                chain = range(self.db.chains)[chain]
            return self._trace[chain].shape[0]
        else:
            return sum([t.shape[0] for t in self._trace.values()])
88160
def _maxlength(X):
    
    return np.fromiter((map(lambda x: len(x), X)), dtype=int).max()
1229674
def truncate(self, index, chain):
        
        self._trace[chain] = self._trace[chain][:index]
1257307
def match_length(self):
        
        length = 0
        for match in self.get_matching_blocks():
            a, b, size = match
            length += self._text_length(self.a[a:a+size])
        return length
1318184
def truncate(self, index, chain=-1):
        """"""
        chain = range(self.chains)[chain]
        for name in self.trace_names[chain]:
            self._traces[name].truncate(index, chain)
641196
def size(self):
        

        if self.id.endswith("/"):
            subqueues = self.get_known_subqueues()
            if len(subqueues) == 0:
                return 0
            else:
                with context.connections.redis.pipeline(transaction=False) as pipe:
                    for subqueue in subqueues:
                        pipe.get("queuesize:%s" % subqueue)
                    return [int(size or 0) for size in pipe.execute()]
        else:
            return int(context.connections.redis.get("queuesize:%s" % self.id) or 0)
546421
def _initialize(self, chain, length):
        

        if self._getfunc is None:
            self._getfunc = self.db.model._funs_to_tally[self.name]

        # Determine size
        try:
            self._shape = np.shape(self._getfunc())
        except TypeError:
            self._shape = None

        self._vstr = ', '.join(var_str(self._shape))

        # If the table already exists, exit now.
        if chain != 0:
            return

        # Create the variable name strings.
        vstr = ', '.join(v + ' FLOAT' for v in var_str(self._shape))
        query = """CREATE TABLE IF NOT EXISTS [%s]
                     (recid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
                      trace  int(5), %s)""" % (self.name, vstr)
        self.db.cur.execute(query)
819060
def get_chain_sequence_string(self, chain_id, use_seqres_sequences_if_possible, raise_Exception_if_not_found = True):
        ''''''
        chain_pair = self.get_annotated_chain_sequence_string(chain_id, use_seqres_sequences_if_possible, raise_Exception_if_not_found = raise_Exception_if_not_found)
        if chain_pair:
            return chain_pair[1]
        return None
647087
def get_encoded_seq_len(self, seq_len: int) -> int:
        
        return int(ceil(seq_len / self.pool_stride))
181030
def length(self, error=ERROR, min_depth=MIN_DEPTH):
        """"""
        start_point = self.point(0)
        end_point = self.point(1)
        return segment_length(self, 0, 1, start_point, end_point, error, min_depth, 0)
280378
def has_length(self, length=None, min=None, max=None):
        
        unittest_case.assertFalse(length is None and min is None and max is None)
        my_length = len(self._subject)
        if length is not None:
            try:
                unittest_case.assertTrue(my_length == length)
            except self._catch as err:
                raise self._error_factory(_format("Expected {} to have length {}", self._subject, length))
        if min is not None:
            try:
                unittest_case.assertTrue(my_length >= min)
            except self._catch as err:
                raise self._error_factory(_format("Expected {} to have length at least {}", self._subject, min))
        if max is not None:
            try:
                unittest_case.assertTrue(my_length <= max)
            except self._catch as err:
                raise self._error_factory(_format("Expected {} to have length at most {}", self._subject, max))
        return ChainInspector(self._subject)
953446
def chain_id(chain_id: int, chain_class: Type[BaseChain]) -> Type[BaseChain]:
    
    return chain_class.configure(chain_id=chain_id)
73197
def total_size(obj, verbose=False):
    
    seen = set()

    def sizeof(o):
        if id(o) in seen:
            return 0
        seen.add(id(o))
        s = sys.getsizeof(o, default=0)
        if verbose:
            print(s, type(o), repr(o))
        if isinstance(o, (tuple, list, set, frozenset, deque)):
            s += sum(map(sizeof, iter(o)))
        elif isinstance(o, dict):
            s += sum(map(sizeof, chain.from_iterable(o.items())))
        elif "__dict__" in dir(o):
            s += sum(map(sizeof, chain.from_iterable(o.__dict__.items())))
        return s

    return sizeof(obj)
14118
def length(self, t0=0, t1=1, error=LENGTH_ERROR, min_depth=LENGTH_MIN_DEPTH):
        """"""
        if t0 == 0 and t1 == 1:
            if self._length_info['bpoints'] == self.bpoints() \
                    and self._length_info['error'] >= error \
                    and self._length_info['min_depth'] >= min_depth:
                return self._length_info['length']

        # using scipy.integrate.quad is quick
        if _quad_available:
            s = quad(lambda tau: abs(self.derivative(tau)), t0, t1,
                            epsabs=error, limit=1000)[0]
        else:
            s = segment_length(self, t0, t1, self.point(t0), self.point(t1),
                               error, min_depth, 0)

        if t0 == 0 and t1 == 1:
            self._length_info['length'] = s
            self._length_info['bpoints'] = self.bpoints()
            self._length_info['error'] = error
            self._length_info['min_depth'] = min_depth
            return self._length_info['length']
        else:
            return s
1061493
def max_value_length(cls):
        
        if not hasattr(cls, '__max_value_length_'):
            cls.__max_value_length_ = max([len(c.value) for c in list(cls)])
        return cls.__max_value_length_
340839
def size(self):
        

        if self.id.endswith("/"):
            return sum(Queue(q).size() for q in self.get_known_subqueues())

        # ZSET
        if self.is_sorted:
            return context.connections.redis.zcard(self.redis_key)
        # SET
        elif self.is_set:
            return context.connections.redis.scard(self.redis_key)
        # LIST
        else:
            return context.connections.redis.llen(self.redis_key)
837846
def calculate_size(timeout, durability, transaction_type, thread_id):
    
    data_size = 0
    data_size += LONG_SIZE_IN_BYTES
    data_size += INT_SIZE_IN_BYTES
    data_size += INT_SIZE_IN_BYTES
    data_size += LONG_SIZE_IN_BYTES
    return data_size