protoMaybeShape :: Lens' TensorShapeProto (Maybe Shape)
protoMaybeShape = under (adapter protoToShape shapeToProto)
  where
    protoToShape :: TensorShapeProto -> Maybe Shape
    protoToShape p =
        if view unknownRank p
            then Nothing
            else Just (Shape (p ^.. dim . traverse . size))
    shapeToProto :: Maybe Shape -> TensorShapeProto
    shapeToProto Nothing =
        defMessage & unknownRank .~ True
    shapeToProto (Just (Shape ds)) =
        defMessage & dim .~ fmap (\d -> defMessage & size .~ d) ds
protoMaybeShape :: Lens' TensorShapeProto (Maybe Shape)
protoMaybeShape = under (adapter protoToShape shapeToProto)
  where
    protoToShape :: TensorShapeProto -> Maybe Shape
    protoToShape p =
        if view unknownRank p
            then Nothing
            else Just (Shape (p ^.. dim . traverse . size))
    shapeToProto :: Maybe Shape -> TensorShapeProto
    shapeToProto Nothing =
        defMessage & unknownRank .~ True
    shapeToProto (Just (Shape ds)) =
        defMessage & dim .~ fmap (\d -> defMessage & size .~ d) ds
protoMaybeShape = under (adapter protoToShape shapeToProto)
  where
    protoToShape :: TensorShapeProto -> Maybe Shape
    protoToShape p =
        if view unknownRank p
            then Nothing
            else Just (Shape (p ^.. dim . traverse . size))
    shapeToProto :: Maybe Shape -> TensorShapeProto
    shapeToProto Nothing =
        defMessage & unknownRank .~ True
    shapeToProto (Just (Shape ds)) =
        defMessage & dim .~ fmap (\d -> defMessage & size .~ d) ds