parameters: (context, builder, ty, val)
return_statement: return shapes
docstring: Parse the shape argument to an array constructor.
docstring_summary: Parse the shape argument to an array constructor.
docstring_tokens: Parse the shape argument to an array constructor .
function: def _parse_shape(context, builder, ty, val):
      """
      Parse the shape argument to an array constructor.
      """
      def safecast_intp(context, builder, src_t, src):
          """Cast src to intp only if value can be maintained"""
          intp_t = context.get_value_type(types.intp)
          intp_width = intp_t.width
          intp_ir = ir.IntType(intp_width)
          maxval = ir.Constant(intp_ir, ((1 << intp_width - 1) - 1))
          if src_t.width < intp_width:
              res = builder.sext(src, intp_ir)
          elif src_t.width >= intp_width:
              is_larger = builder.icmp_signed(">", src, maxval)
              with builder.if_then(is_larger, likely=False):
                  context.call_conv.return_user_exc(
                      builder, ValueError,
                      ("Cannot safely convert value to intp",)
                  )
              if src_t.width > intp_width:
                  res = builder.trunc(src, intp_ir)
              else:
                  res = src
          return res
  
      if isinstance(ty, types.Integer):
          ndim = 1
          passed_shapes = [context.cast(builder, val, ty, types.intp)]
      else:
          assert isinstance(ty, types.BaseTuple)
          ndim = ty.count
          passed_shapes = cgutils.unpack_tuple(builder, val, count=ndim)
  
      shapes = []
      for s in passed_shapes:
          shapes.append(safecast_intp(context, builder, s.type, s))
  
      zero = context.get_constant_generic(builder, types.intp, 0)
      for dim in range(ndim):
          is_neg = builder.icmp_signed('<', shapes[dim], zero)
          with cgutils.if_unlikely(builder, is_neg):
              context.call_conv.return_user_exc(
                  builder, ValueError, ("negative dimensions not allowed",)
              )
  
      return shapes
function_tokens: def _parse_shape ( context , builder , ty , val ) : def safecast_intp ( context , builder , src_t , src ) : """Cast src to intp only if value can be maintained""" intp_t = context . get_value_type ( types . intp ) intp_width = intp_t . width intp_ir = ir . IntType ( intp_width ) maxval = ir . Constant ( intp_ir , ( ( 1 << intp_width - 1 ) - 1 ) ) if src_t . width < intp_width : res = builder . sext ( src , intp_ir ) elif src_t . width >= intp_width : is_larger = builder . icmp_signed ( ">" , src , maxval ) with builder . if_then ( is_larger , likely = False ) : context . call_conv . return_user_exc ( builder , ValueError , ( "Cannot safely convert value to intp" , ) ) if src_t . width > intp_width : res = builder . trunc ( src , intp_ir ) else : res = src return res if isinstance ( ty , types . Integer ) : ndim = 1 passed_shapes = [ context . cast ( builder , val , ty , types . intp ) ] else : assert isinstance ( ty , types . BaseTuple ) ndim = ty . count passed_shapes = cgutils . unpack_tuple ( builder , val , count = ndim ) shapes = [ ] for s in passed_shapes : shapes . append ( safecast_intp ( context , builder , s . type , s ) ) zero = context . get_constant_generic ( builder , types . intp , 0 ) for dim in range ( ndim ) : is_neg = builder . icmp_signed ( '<' , shapes [ dim ] , zero ) with cgutils . if_unlikely ( builder , is_neg ) : context . call_conv . return_user_exc ( builder , ValueError , ( "negative dimensions not allowed" , ) ) return shapes