def add_logical(self, name, input_names, output_name, mode):
        """
        Add a logical layer to the model that performs element-wise logical
        and/or/xor/not operation. Broadcasting is supported.
        Refer to the ``LogicalOrLayerParams``, ``LogicalNotLayerParams``,
        ``LogicalNotLayerParams``, and ``LogicalAndLayerParam`` messages in the specification
        (NeuralNetwork.proto) for more details.

        Parameters
        ----------
        name: str
            The name of this layer.
        input_names: list of str
            The input blob names of this layer.
        output_name: str
            The output blob name of this layer.
        mode: str
            Logical operation mode in [AND | OR | XOR | NOT].
        """

        if isinstance(input_names, str):
            input_names = [input_names]

        spec_layer = self._add_generic_layer(name, input_names, [output_name])

        if mode in ["AND", "OR", "XOR"] and len(input_names) != 2:
            raise ValueError('Logical operation "%s" requires 2 inputs' % name)
        if mode in ["NOT"] and len(input_names) != 1:
            raise ValueError('Logical operation "%s" requires 1 input' % name)

        if mode == "AND":
            spec_layer.logicalAnd.MergeFromString(b"")
        elif mode == "OR":
            spec_layer.logicalOr.MergeFromString(b"")
        elif mode == "XOR":
            spec_layer.logicalXor.MergeFromString(b"")
        elif mode == "NOT":
            spec_layer.logicalNot.MergeFromString(b"")
        else:
            raise ValueError('Logical operation "%s" is not supported' % mode)

        return spec_layer

        Add a logical layer to the model that performs element-wise logical
        and/or/xor/not operation. Broadcasting is supported.
        Refer to the ``LogicalOrLayerParams``, ``LogicalNotLayerParams``,
        ``LogicalNotLayerParams``, and ``LogicalAndLayerParam`` messages in the specification
        (NeuralNetwork.proto) for more details.

        Parameters
        ----------
        name: str
            The name of this layer.
        input_names: list of str
            The input blob names of this layer.
        output_name: str
            The output blob name of this layer.
        mode: str
            Logical operation mode in [AND | OR | XOR | NOT].
        
coremltools/models/neural_network/builder.py