def meshgrid(context, node):
    """
    For N input tensors, a meshgrid is constructed by viewing each tensor as an N-dimension tensor
    with values in the dimension corresponding it its order in the args. (a.)
    Then, it is expanded along dimensions corresponding to the dimensions of each
    1d tensor in the order that they were passed in. (b.)

    Each output tensor is put into a tuple that is returned. These tuples form
    N, N-dimenional grids, where the ith grid is defined as expanding the ith input over
    dimensions defined by the other inputs.
    """

    def _parse_positional_args(context, node) -> Tuple[Var]:
        inputs = _get_inputs(context, node, expected=[1, 2])
        nargs = len(inputs)

        tensor_inputs = inputs[0]
        indexing = inputs[1].val if nargs > 1 else "ij"
        return tensor_inputs, indexing

    def _parse_keyword_args(context, node, indexing) -> Var:
        indexing = _get_kwinputs(context, node, "indexing", default=[indexing])[0]
        return indexing

    def _check_args(tensor_inputs, indexing) -> None:
        assert isinstance(tensor_inputs, (list, tuple))
        if len(tensor_inputs) < 2:
            raise ValueError("Requires >= 2 tensor inputs.")
        if any(tensor_input.rank > 1 for tensor_input in tensor_inputs):
            raise ValueError("meshgrid received non-1d tensor.")

        if indexing not in ("ij", "xy"):
            raise ValueError(f"indexing mode {indexing} not supported")

    tensor_inputs, indexing = _parse_positional_args(context, node)
    indexing = _parse_keyword_args(context, node, indexing)
    _check_args(tensor_inputs, indexing)

    result_symbolic_shape = [tensor_input.shape[0] for tensor_input in tensor_inputs]
    result_shape = _utils.maybe_replace_symbols_with_source_tensor_shape_variables(
        result_symbolic_shape, tensor_inputs
    )

    grids = []
    size = len(tensor_inputs)
    for i in range(size):
        view_shape = [1] * size
        view_shape[i] = -1
        view_shape = tuple(view_shape)
        # (a.) in docstring
        view = mb.reshape(
            x=tensor_inputs[i], shape=view_shape, name=node.name + "_view_" + str(i)
        )

        # (b.) in docstring
        reps = result_shape.copy()
        reps[i] = 1
        if any(isinstance(rep, Var) for rep in reps):
            reps = mb.concat(values=reps, axis=0)
        res = mb.tile(x=view, reps=reps, name=node.name + "_expand_" + str(i))

        # transpose the first two dimensions for "xy" indexing
        if indexing == "xy":
            perm = [1, 0] + list(range(2, size))
            res = mb.transpose(x=res, perm=perm, name=node.name + "_transpose_" + str(i))

        grids.append(res)

    context.add(tuple(grids), node.name)

    For N input tensors, a meshgrid is constructed by viewing each tensor as an N-dimension tensor
    with values in the dimension corresponding it its order in the args. (a.)
    Then, it is expanded along dimensions corresponding to the dimensions of each
    1d tensor in the order that they were passed in. (b.)

    Each output tensor is put into a tuple that is returned. These tuples form
    N, N-dimenional grids, where the ith grid is defined as expanding the ith input over
    dimensions defined by the other inputs.
    
coremltools/converters/mil/frontend/torch/ops.py