# -*- coding: utf-8 -*-
# MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
#
# Copyright (c) 2014-2020 Megvii Inc. All rights reserved.
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# pylint: disable=too-many-lines
from typing import Optional, Tuple, Union

import megengine._internal as mgb
from megengine._internal import CompGraph, CompNode

from ..core import Tensor, wrap_io_tensor
from ..core.graph import _use_default_if_none
from ..jit import barrier, mark_impure
from ..random import uniform
from ..utils.types import _pair, _pair_nonzero
from .debug_param import get_conv_execution_strategy
from .tensor import concat
from .utils import _decide_comp_node_and_comp_graph


@wrap_io_tensor
def linear(inp: Tensor, weight: Tensor, bias: Optional[Tensor] = None) -> Tensor:
    """Applies a linear transformation to the input.

    Refer to :class:`~.Linear` for more information.
    """
    orig_shape = inp.shape
    inp = inp.reshape(-1, orig_shape[-1])
    ret = 
mgb.opr.matrix_mul(inp, weight, transposeB=True)