<s> """<STR_LIT>""" <EOL> from array import array <EOL> import reprlib <EOL> import math <EOL> import numbers <EOL> import functools <EOL> import operator <EOL> class Vector : <EOL> typecode = '<STR_LIT:d>' <EOL> def __init__ ( self , components ) : <EOL> self . _components = array ( self . typecode , components ) <EOL> def __iter__ ( self ) : <EOL> return iter ( self . _components ) <EOL> def __repr__ ( self ) : <EOL> components = reprlib . repr ( self . _components ) <EOL> components = components [ components . find ( '<STR_LIT:[>' ) : - <NUM_LIT:1> ] <EOL> return '<STR_LIT>' . format ( components ) <EOL> def __str__ ( self ) : <EOL> return str ( tuple ( self ) ) <EOL> def __bytes__ ( self ) : <EOL> return ( bytes ( [ ord ( self . typecode ) ] ) + <EOL> bytes ( self . _components ) ) <EOL> def __eq__ ( self , other ) : <EOL> return ( len ( self ) == len ( other ) and <EOL> all ( a == b for a , b in zip ( self , other ) ) ) <EOL> def __hash__ ( self ) : <EOL> hashes = ( hash ( x ) for x in self ) <EOL> return functools . reduce ( operator . xor , hashes , <NUM_LIT:0> ) <EOL> def __abs__ ( self ) : <EOL> return math . sqrt ( sum ( x * x for x in self ) ) <EOL> def __bool__ ( self ) : <EOL> return bool ( abs ( self ) ) <EOL> def __len__ ( self ) : <EOL> return len ( self . _components ) <EOL> def __getitem__ ( self , index ) : <EOL> cls = type ( self ) <EOL> if isinstance ( index , slice ) : <EOL> return cls ( self . _components [ index ] ) <EOL> elif isinstance ( index , numbers . Integral ) : <EOL> return self . _components [ index ] <EOL> else : <EOL> msg = '<STR_LIT>' <EOL> raise TypeError ( msg . format ( cls = cls ) ) <EOL> shortcut_names = '<STR_LIT>' <EOL> def __getattr__ ( self , name ) : <EOL> cls = type ( self ) <EOL> if len ( name ) == <NUM_LIT:1> : <EOL> pos = cls . shortcut_names . find ( name ) <EOL> if <NUM_LIT:0> <= pos < len ( self . _components ) : <EOL> return self . _components [ pos ] <EOL> msg = '<STR_LIT>' <EOL> raise AttributeError ( msg . format ( cls , name ) ) <EOL> @ classmethod <EOL> def frombytes ( cls , octets ) : <EOL> typecode = chr ( octets [ <NUM_LIT:0> ] ) <EOL> memv = memoryview ( octets [ <NUM_LIT:1> : ] ) . cast ( typecode ) <EOL> return cls ( memv ) </s>
