Check whether one forward mode input dict has elements of valid shape
        Returns inferred value of T
778042
def _check_forward_mode_input_dict(self, var_tbl: dict) -> int:
        
        T: int = 1
        for var_name in var_tbl:
            # The bound value to this variable name
            val = var_tbl[var_name]
            # case 1: this is a scalar; T=1
            if isinstance(val, scalar_instance_types):
                t = 1
            # case 2: this is an array; calulate T
            elif isinstance(val, np.ndarray):
                t = self._calc_T_var(val)
            #case 3: throw an error
            else:
                raise ValueError(f'val={val} in var_tbl; {type(val)} not a recognized value type.')
            #update T
            if t > 1 and T == 1:
                T = t
            elif t not in (1,T):
                raise ValueError(f'Bound variable {var_name} has inconsistent shape')
        return T
591859
def _infer_shape(self, dimensions):
    
    # Size of input
    n = np.prod(dimensions)
    # Size of output where defined
    m = np.prod(abs(np.array(self._shape)))
    # Replace wildcard
    v = np.array(self._shape)
    v[v == -1] = n // m
    return tuple(v)
754273
def assert_shape_match(shape1, shape2):
  
  shape1 = tf.TensorShape(shape1)
  shape2 = tf.TensorShape(shape2)
  if shape1.ndims is None or shape2.ndims is None:
    raise ValueError('Shapes must have known rank. Got %s and %s.' %
                     (shape1.ndims, shape2.ndims))
  shape1.assert_same_rank(shape2)
  shape1.assert_is_compatible_with(shape2)
214244
static boolean matchForward(char[] chars, char[] pattern, int[] cursor) {
    if (pattern.length > cursor[1] - cursor[0])
      return false;
    int index = 0;
    while (index < pattern.length)
      if (chars[cursor[0]++] != pattern[index++])
        return false;
    return true;
  }
532486
def check_valid(self):
		
		for k,input in self.inputs.items():
			if k in self.valid_opts:
				for param in self.valid_opts[k]:
					if param is None or input is None:
						return True
					elif type(param) is str and '+' in param:
						if re.search(r'^'+param,str(input)):
							return True
					elif type(param) is bool and type(input) is bool:
						return True
					elif type(param) is list and type(input) is list:
						return True
					else:
						if str(input).lower() == str(param):
							return True
				raise ValueError("Invalid input for '%s' parameter. Options are: %s" % (k,' '.join(["'%s'," % str(o) for o in self.valid_opts[k]]) ))
			else:
				raise ValueError("Invalid parameter for '%s'. Params are: %s" % (self.__class__.__name__,', '.join(["'%s'" % p for p in self.valid_opts.keys()]) ))
740458
def _pyfftw_check_args(arr_in, arr_out, axes, halfcomplex, direction):
    """"""
    if len(set(axes)) != len(axes):
        raise ValueError('duplicate axes are not allowed')

    if direction == 'forward':
        out_shape = list(arr_in.shape)
        if halfcomplex:
            try:
                out_shape[axes[-1]] = arr_in.shape[axes[-1]] // 2 + 1
            except IndexError:
                raise IndexError('axis index {} out of range for array '
                                 'with {} axes'
                                 ''.format(axes[-1], arr_in.ndim))

        if arr_out.shape != tuple(out_shape):
            raise ValueError('expected output shape {}, got {}'
                             ''.format(tuple(out_shape), arr_out.shape))

        if is_real_dtype(arr_in.dtype):
            out_dtype = complex_dtype(arr_in.dtype)
        elif halfcomplex:
            raise ValueError('cannot combine halfcomplex forward transform '
                             'with complex input')
        else:
            out_dtype = arr_in.dtype

        if arr_out.dtype != out_dtype:
            raise ValueError('expected output dtype {}, got {}'
                             ''.format(dtype_repr(out_dtype),
                                       dtype_repr(arr_out.dtype)))

    elif direction == 'backward':
        in_shape = list(arr_out.shape)
        if halfcomplex:
            try:
                in_shape[axes[-1]] = arr_out.shape[axes[-1]] // 2 + 1
            except IndexError as err:
                raise IndexError('axis index {} out of range for array '
                                 'with {} axes'
                                 ''.format(axes[-1], arr_out.ndim))

        if arr_in.shape != tuple(in_shape):
            raise ValueError('expected input shape {}, got {}'
                             ''.format(tuple(in_shape), arr_in.shape))

        if is_real_dtype(arr_out.dtype):
            in_dtype = complex_dtype(arr_out.dtype)
        elif halfcomplex:
            raise ValueError('cannot combine halfcomplex backward transform '
                             'with complex output')
        else:
            in_dtype = arr_out.dtype

        if arr_in.dtype != in_dtype:
            raise ValueError('expected input dtype {}, got {}'
                             ''.format(dtype_repr(in_dtype),
                                       dtype_repr(arr_in.dtype)))

    else:  # Shouldn't happen
        raise RuntimeError
1195922
def check_shape(*args)
      _shape = shape
      args.each do |arg|
        _arg_shape = arg.shape
        if _shape.size < _arg_shape.size
          raise "#{arg.inspect} has #{arg.dimension} dimension(s) " +
                "but should not have more than #{dimension}"
        end
        if ( _shape + _arg_shape ).all? { |s| s.is_a? Integer }
          if _shape.last( _arg_shape.size ) != _arg_shape
            raise "#{arg.inspect} has shape #{arg.shape.inspect} " +
                  "(does not match last value(s) of #{shape.inspect})"
          end
        end
      end
    end
839986
def _assert_is_dictlike(maybe_dictlike, valid_keys):
  """"""
  # This covers a common mistake when people use incorrect dictionary nesting
  # for initializers / partitioners etc. The previous error message was quite
  # opaque, this should be much clearer.
  if not hasattr(maybe_dictlike, "__getitem__"):
    raise TypeError(
        "Expected a dict-like object with possible keys %s, received %s" %
        (str(valid_keys), str(maybe_dictlike)))
668974
def _check_signal(self, s):
        """
        s = np.asanyarray(s)
        if s.shape[0] != self.n_vertices:
            raise ValueError('First dimension must be the number of vertices '
                             'G.N = {}, got {}.'.format(self.N, s.shape))
        return s
1315194
boolean lookForwardLineFeedAndEof() {
		int forwardBak = forward;
		int forwardRowBak = forwardRow;
		for (char c=peek(); true; c=next()) {
			if (CharTable.isBlank(c)) {
				continue ;
			}
			if (c == '\n' || c == EOF) {
				return true;
			}
			forward = forwardBak;
			forwardRow = forwardRowBak;
			return false;
		}
	}
1261231
def _is_inline_definition(arg):
    '''
    
    '''
    return isinstance(arg, dict) and len(arg) == 1 and isinstance(next(six.itervalues(arg)), list)
1374907
def calculate_bidirectional_lstm_output_shapes(operator):
    '''
    
    '''
    check_input_and_output_numbers(operator, input_count_range=[1, 5], output_count_range=[1, 5])
    check_input_and_output_types(operator, good_input_types=[FloatTensorType])

    input_shape = operator.inputs[0].type.shape

    # LSTM accepts [N, C] and [N, C, 1, 1] inputs
    if len(input_shape) not in [2, 4]:
        raise RuntimeError('Input must be a 2-D or 4-D tensor')

    params = operator.raw_operator.biDirectionalLSTM
    # The following line is more accurate but it may break some tests
    # output_shape = ['None', params.outputVectorSize] if params.params.sequenceOutput else [1, 2 *params.outputVectorSize]
    output_shape = ['None', 2 * params.outputVectorSize]
    state_shape = [1, params.outputVectorSize]

    # TODO: Changing input shapes of an operator is dangerous, this should be move to Topology's _fix_shapes function
    if len(operator.inputs) > 1:
        Y_h_in = operator.inputs[1]  # The forward initial hidden state of a single sequence
        Y_h_in.type.shape = state_shape
        Y_h_rev_in = operator.inputs[3]  # The backward initial hidden state of a single sequence
        Y_h_rev_in.type.shape = state_shape
    if len(operator.inputs) > 2:
        Y_c_in = operator.inputs[2]  # The forward initial cell state of a single sequence
        Y_c_in.type.shape = state_shape
        Y_c_rev_in = operator.inputs[4]  # The backward initial cell state of a single sequence
        Y_c_rev_in.type.shape = state_shape

    operator.outputs[0].type.shape = output_shape
    if len(operator.outputs) > 1:
        operator.outputs[1].type.shape = state_shape
        operator.outputs[3].type.shape = state_shape
    if len(operator.outputs) > 2:
        operator.outputs[2].type.shape = state_shape
        operator.outputs[4].type.shape = state_shape
174030
def is1d(a:Collection)->bool:
    ""
    return len(a.shape) == 1 if hasattr(a, 'shape') else True
493415
def has_return_exprs(self, node):
        
        results = {}
        if self.return_expr.match(node, results):
            return True
        for child in node.children:
            if child.type not in (syms.funcdef, syms.classdef):
                if self.has_return_exprs(child):
                    return True
        return False
313449
def _check_var(var, dtype, ndmin, name, shape=None, shape2=None):
    """
    if var is None:
        raise ValueError
    var = np.array(var, dtype=dtype, copy=True, ndmin=ndmin)
    if shape:
        _check_shape(var, name, shape, shape2)
    return var
20328
def _check_not_tuple_of_2_elements(obj, obj_name='obj'):
    """"""
    if not isinstance(obj, tuple) or len(obj) != 2:
        raise TypeError('%s must be a tuple of 2 elements.' % obj_name)
711609
private void checkForOfTypes(NodeTraversal t, Node forOf) {
    Node lhs = forOf.getFirstChild();
    Node iterable = forOf.getSecondChild();
    JSType iterableType = getJSType(iterable);
    JSType actualType;

    if (forOf.isForAwaitOf()) {
      Optional<JSType> maybeType =
          validator.expectAutoboxesToIterableOrAsyncIterable(
              iterable,
              iterableType,
              "Can only async iterate over a (non-null) Iterable or AsyncIterable type");

      if (!maybeType.isPresent()) {
        // Not iterable or async iterable, error reported by
        // expectAutoboxesToIterableOrAsyncIterable.
        return;
      }

      actualType = maybeType.get();
    } else {
      validator.expectAutoboxesToIterable(
          iterable, iterableType, "Can only iterate over a (non-null) Iterable type");

      actualType =
          // Convert primitives to their wrapper type and remove null/undefined
          // If iterable is a union type, autoboxes each member of the union.
          iterableType
              .autobox()
              .getTemplateTypeMap()
              .getResolvedTemplateType(typeRegistry.getIterableTemplate());
    }

    if (NodeUtil.isNameDeclaration(lhs)) {
      // e.g. get "x" given the VAR in "for (var x of arr) {"
      lhs = lhs.getFirstChild();
    }
    if (lhs.isDestructuringLhs()) {
      // e.g. get `[x, y]` given the VAR in `for (var [x, y] of arr) {`
      lhs = lhs.getFirstChild();
    }

    checkCanAssignToWithScope(
        t,
        forOf,
        lhs,
        actualType,
        lhs.getJSDocInfo(),
        "declared type of for-of loop variable does not match inferred type");
  }