<s> """<STR_LIT>""" <EOL> import numpy <EOL> import math <EOL> import sys <EOL> if sys . version_info [ <NUM_LIT:0> ] > <NUM_LIT:2> : <EOL> import unittest <EOL> from io import StringIO , BytesIO <EOL> bytes = bytes <EOL> basestring = ( str , bytes ) <EOL> xrange = range <EOL> else : <EOL> import unittest <EOL> if not hasattr ( unittest . TestCase , "<STR_LIT>" ) : <EOL> import unittest2 as unittest <EOL> from StringIO import StringIO <EOL> BytesIO = StringIO <EOL> def bytes ( s , encoding = '<STR_LIT:utf-8>' ) : <EOL> return s <EOL> basestring = basestring <EOL> xrange = xrange <EOL> from collada . common import DaeMalformedError , E , tag <EOL> def falmostEqual ( a , b , rtol = <NUM_LIT> , atol = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> return math . fabs ( a - b ) <= ( atol + rtol * math . fabs ( b ) ) <EOL> def toUnitVec ( vec ) : <EOL> """<STR_LIT>""" <EOL> return vec / numpy . sqrt ( numpy . vdot ( vec , vec ) ) <EOL> def checkSource ( source , components , maxindex ) : <EOL> """<STR_LIT>""" <EOL> if len ( source . data ) <= maxindex : <EOL> raise DaeMalformedError ( <EOL> "<STR_LIT>" <EOL> % ( maxindex , source . id , len ( source . data ) ) ) <EOL> if len ( source . components ) == len ( components ) : <EOL> source . components = components <EOL> if source . components != components : <EOL> raise DaeMalformedError ( '<STR_LIT>' % source . id ) <EOL> return source <EOL> def normalize_v3 ( arr ) : <EOL> """<STR_LIT>""" <EOL> lens = numpy . sqrt ( arr [ : , <NUM_LIT:0> ] ** <NUM_LIT:2> + arr [ : , <NUM_LIT:1> ] ** <NUM_LIT:2> + arr [ : , <NUM_LIT:2> ] ** <NUM_LIT:2> ) <EOL> lens [ numpy . equal ( lens , <NUM_LIT:0> ) ] = <NUM_LIT:1> <EOL> arr [ : , <NUM_LIT:0> ] /= lens <EOL> arr [ : , <NUM_LIT:1> ] /= lens <EOL> arr [ : , <NUM_LIT:2> ] /= lens <EOL> return arr <EOL> def dot_v3 ( arr1 , arr2 ) : <EOL> """<STR_LIT>""" <EOL> return arr1 [ : , <NUM_LIT:0> ] * arr2 [ : , <NUM_LIT:0> ] + arr1 [ : , <NUM_LIT:1> ] * arr2 [ : , <NUM_LIT:1> ] + arr2 [ : , <NUM_LIT:2> ] * arr1 [ : , <NUM_LIT:2> ] <EOL> class IndexedList ( list ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , items , attrs ) : <EOL> super ( IndexedList , self ) . __init__ ( items ) <EOL> self . _attrs = tuple ( attrs ) <EOL> self . _index = { } <EOL> _add = self . _addindex <EOL> for obj in self : <EOL> _add ( obj ) <EOL> def _addindex ( self , obj ) : <EOL> _idx = self . _index <EOL> for attr in self . _attrs : <EOL> _idx [ getattr ( obj , attr ) ] = obj <EOL> def _delindex ( self , obj ) : <EOL> _idx = self . _index <EOL> for attr in self . _attrs : <EOL> try : <EOL> del _idx [ getattr ( obj , attr ) ] <EOL> except KeyError : <EOL> pass <EOL> def __delitem__ ( self , ind ) : <EOL> try : <EOL> obj = list . __getitem__ ( self , ind ) <EOL> except ( IndexError , TypeError ) : <EOL> obj = self . _index [ ind ] <EOL> ind = list . index ( self , obj ) <EOL> self . _delindex ( obj ) <EOL> return list . __delitem__ ( self , ind ) <EOL> def __delslice__ ( self , i , j ) : <EOL> return list . __delslice__ ( self , i , j ) <EOL> def __getitem__ ( self , ind ) : <EOL> try : <EOL> return self . _index [ ind ] <EOL> except KeyError : <EOL> if isinstance ( ind , str ) : <EOL> raise <EOL> return list . __getitem__ ( self , ind ) <EOL> def get ( self , key , default = None ) : <EOL> try : <EOL> return self . _index [ key ] <EOL> except KeyError : <EOL> return default <EOL> def __contains__ ( self , item ) : <EOL> if item in self . _index : <EOL> return True <EOL> return list . __contains__ ( self , item ) <EOL> def __getslice__ ( self , i , j ) : <EOL> return IndexedList ( list . __getslice__ ( self , i , j ) , self . _attrs ) <EOL> def __setitem__ ( self , ind , new_obj ) : <EOL> try : <EOL> obj = list . __getitem__ ( self , ind ) <EOL> except ( IndexError , TypeError ) : <EOL> obj = self . _index [ ind ] <EOL> ind = list . index ( self , obj ) <EOL> self . _delindex ( obj ) <EOL> self . _addindex ( new_obj ) <EOL> return list . __setitem__ ( ind , new_obj ) <EOL> def __setslice__ ( self , i , j , newItems ) : <EOL> _get = self . __getitem__ <EOL> _add = self . _addindex <EOL> _del = self . _delindex <EOL> newItems = list ( newItems ) <EOL> for ind in xrange ( i , j ) : <EOL> _del ( _get ( ind ) ) <EOL> if isinstance ( newList , IndexedList ) : <EOL> self . _index . update ( newList . _index ) <EOL> else : <EOL> for obj in newList : <EOL> _add ( obj ) <EOL> return list . __setslice__ ( self , i , j , newList ) <EOL> def append ( self , obj ) : <EOL> self . _addindex ( obj ) <EOL> return list . append ( self , obj ) <EOL> def extend ( self , newList ) : <EOL> newList = list ( newList ) <EOL> if isinstance ( newList , IndexedList ) : <EOL> self . _index . update ( newList . _index ) <EOL> else : <EOL> _add = self . _addindex <EOL> for obj in newList : <EOL> _add ( obj ) <EOL> return list . extend ( self , newList ) <EOL> def insert ( self , ind , new_obj ) : <EOL> try : <EOL> obj = list . __getitem__ ( self , ind ) <EOL> except ( IndexError , TypeError ) : <EOL> obj = self . _index [ ind ] <EOL> ind = list . index ( self , obj ) <EOL> self . _addindex ( new_obj ) <EOL> return list . insert ( self , ind , new_obj ) <EOL> def pop ( self , ind = - <NUM_LIT:1> ) : <EOL> try : <EOL> obj = list . __getitem__ ( self , ind ) <EOL> except ( IndexError , TypeError ) : <EOL> obj = self . _index [ ind ] <EOL> ind = list . index ( self , obj ) <EOL> self . _delindex ( obj ) <EOL> return list . pop ( self , ind ) <EOL> def remove ( self , ind_or_obj ) : <EOL> try : <EOL> obj = self . _index [ ind_or_obj ] <EOL> ind = list . index ( self , obj ) <EOL> except KeyError : <EOL> ind = list . index ( self , ind_or_obj ) <EOL> obj = list . __getitem__ ( self , ind ) <EOL> self . _delindex ( obj ) <EOL> return list . remove ( self , ind ) <EOL> def _correctValInNode ( outernode , tagname , value ) : <EOL> innernode = outernode . find ( tag ( tagname ) ) <EOL> if value is None and innernode is not None : <EOL> outernode . remove ( innernode ) <EOL> elif innernode is not None : <EOL> innernode . text = str ( value ) <EOL> elif value is not None : <EOL> outernode . append ( E ( tagname , str ( value ) ) ) </s>
