#NEWLINE# def _getAllowedShapes( self , shape ) : #NEWLINE# #INDENT# " Return set of allowed shapes that can be squeezed into given shape.\n\n        Examples\n        --------\n        >>> PB = ParamBag() # fixing K,D doesn't matter\n        >>> PB._getAllowedShapes(())\n        set([()])\n        >>> PB._getAllowedShapes((1))\n        set([(), (1,)])\n        >>> PB._getAllowedShapes((23))\n        set([(23)])\n        >>> PB._getAllowedShapes((3,1))\n        set([(3), (3,1)])\n        >>> PB._getAllowedShapes((1,1))\n        set([(), (1,), (1,1)])\n    " #NEWLINE# allowedShapes = set ( ) #NEWLINE# if ( len ( shape ) == 0 ) : #NEWLINE# #INDENT# allowedShapes . add ( tuple ( ) ) #NEWLINE# return allowedShapes #NEWLINE# #UNINDENT# shapeVec = np . asarray ( shape , dtype = np . int32 ) #NEWLINE# onesMask = ( shapeVec == 1 ) #NEWLINE# keepMask = np . logical_not ( onesMask ) #NEWLINE# nOnes = sum ( onesMask ) #NEWLINE# for b in range ( ( 2 ** nOnes ) ) : #NEWLINE# #INDENT# bStr = np . binary_repr ( b ) #NEWLINE# bStr = ( ( '0' * ( nOnes - len ( bStr ) ) ) + bStr ) #NEWLINE# keepMask [ onesMask ] = np . asarray ( [ ( int ( x ) > 0 ) for x in bStr ] ) #NEWLINE# curShape = shapeVec [ keepMask ] #NEWLINE# allowedShapes . add ( tuple ( curShape ) ) #NEWLINE# #UNINDENT# return allowedShapes