<commit_before># -*- coding: utf8 -*-
#
# Module ELEMENT
#
# Part of Nutils: open source numerical utilities for Python. Jointly developed
# by HvZ Computational Engineering, TU/e Multiscale Engineering Fluid Dynamics,
# and others. More info at http://nutils.org <<EMAIL>>. (c) 2014

"""
The transform module.
"""

from __future__ import division
from . import cache, rational, numeric
import numpy


class TransformChain( tuple ):

  __slots__ = ()

  def __getslice__( self, i, j ):
    return TransformChain( tuple.__getslice__( self, i, j ) )

  @property
  def todims( self ):
    return self[0].todims

  @property
  def fromdims( self ):
    return self[-1].fromdims

  @property
  def isflipped( self ):
    return any( trans.isflipped for trans in self )

  def lookup( self, transforms ):
    # to be replaced by bisection soon
    headtrans = self
    while headtrans:
      if headtrans in transforms:
        return headtrans
      headtrans = headtrans[:-1]
    return None

  def slice( self, fromdims=None, todims=None ):
    if fromdims is None:
      fromdims = self.fromdims
    if todims is None:
      todims = self.todims
    if fromdims == self.fromdims and todims == self.todims:
      return self
    transforms = self
    while transforms and transforms[-1].fromdims != fromdims:
      transforms = transforms[:-1]
    while transforms and transforms[0].todims != todims:
      transforms = transforms[1:]
    assert transforms or fromdims == todims, 'invalid slice (%d,%d) of %s' % ( todims, fromdims, self )
    return transforms

  def __lshift__( self, other ):
    # self << other
    assert isinstance( other, TransformChain )
    if not self:
      return other
    if not other:
      return self
    assert self.fromdims == other.todims
    return TransformChain( self + other )

  def __rshift__( self, other ):
    # self >> other
    assert isinstance( other, TransformChain )
    return other << self

  @property
  def flipped( self ):
    return TransformChain( trans.flipped for trans in self )
<commit_msg>fix Transform.slice bug<commit_after># -*- coding: utf8 -*-
#
# Module ELEMENT
#
# Part of Nutils: open source numerical utilities for Python. Jointly developed
# by HvZ Computational Engineering, TU/e Multiscale Engineering Fluid Dynamics,
# and others. More info at http://nutils.org <<EMAIL>>. (c) 2014

"""
The transform module.
"""

from __future__ import division
from . import cache, rational, numeric
import numpy

_noarg = object()


class TransformChain( tuple ):

  __slots__ = ()

  def __getslice__( self, i, j ):
    return TransformChain( tuple.__getslice__( self, i, j ) )

  @property
  def todims( self ):
    return self[0].todims

  @property
  def fromdims( self ):
    return self[-1].fromdims

  @property
  def isflipped( self ):
    return any( trans.isflipped for trans in self )

  def lookup( self, transforms ):
    # to be replaced by bisection soon
    headtrans = self
    while headtrans:
      if headtrans in transforms:
        return headtrans
      headtrans = headtrans[:-1]
    return None

  def slice( self, fromdims=_noarg, todims=_noarg ):
    if fromdims is _noarg:
      fromdims = self.fromdims
    if todims is _noarg:
      todims = self.todims
    if fromdims == self.fromdims and todims == self.todims:
      return self
    transforms = self
    while transforms and transforms[-1].fromdims != fromdims:
      transforms = transforms[:-1]
    while transforms and transforms[0].todims != todims:
      transforms = transforms[1:]
    assert transforms or fromdims == todims, 'invalid slice (%d,%d) of %s' % ( todims, fromdims, self )
    return transforms

  def __lshift__( self, other ):
    # self << other
    assert isinstance( other, TransformChain )
    if not self:
      return other
    if not other:
      return self
    assert self.fromdims == other.todims
    return TransformChain( self + other )

  def __rshift__( self, other ):
    # self >> other
    assert isinstance( other, TransformChain )
    return other << self

  @property
  def flipped( self ):
    return TransformChain( trans.flipped for trans in self )

{'fraction_non_alphanumeric': 0.09475465313028765, 'fraction_numerical': 0.005801305293691081, 'mean_word_length': 3.041015625, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7178378', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1254, 'n_words': 438}