Skip to content

⚡️ Speed up method Recall._make_empty_content by 8% #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

codeflash-ai[bot]
Copy link

@codeflash-ai codeflash-ai bot commented Feb 3, 2025

📄 8% (0.08x) speedup for Recall._make_empty_content in supervision/metrics/recall.py

⏱️ Runtime : 10.2 microseconds 9.43 microseconds (best of 31 runs)

📝 Explanation and details
  1. Efficient Use of Conditions: Used elif to avoid multiple if checks in _make_empty_content.

This optimized approach should run faster by avoiding redundant checks and using efficient numpy array operations.

Correctness verification report:

Test Status
⚙️ Existing Unit Tests 🔘 None Found
🌀 Generated Regression Tests 5 Passed
⏪ Replay Tests 🔘 None Found
🔎 Concolic Coverage Tests 🔘 None Found
📊 Tests Coverage 57.1%
🌀 Generated Regression Tests Details
from __future__ import annotations

from enum import Enum
from typing import List

import numpy as np
# imports
import pytest  # used for our unit tests
from supervision.detection.core import Detections
from supervision.metrics.core import AveragingMethod, Metric
from supervision.metrics.recall import Recall


class MetricTarget(Enum):
    """
    Specifies what type of detection is used to compute the metric.

    Attributes:
        BOXES: xyxy bounding boxes
        MASKS: Binary masks
        ORIENTED_BOUNDING_BOXES: Oriented bounding boxes (OBB)
    """

    BOXES = "boxes"
    MASKS = "masks"
    ORIENTED_BOUNDING_BOXES = "obb"
from supervision.metrics.recall import Recall

# unit tests

# Test cases for basic valid inputs



def test_make_empty_content_invalid_target():
    recall = Recall()
    recall._metric_target = "invalid"
    with pytest.raises(ValueError, match="Invalid metric target: invalid"):
        recall._make_empty_content()

# Edge cases

def test_make_empty_content_empty_metric_target():
    recall = Recall()
    recall._metric_target = None
    with pytest.raises(ValueError, match="Invalid metric target: None"):
        recall._make_empty_content()

# Performance and scalability



def test_make_empty_content_error_message():
    recall = Recall()
    recall._metric_target = "invalid"
    with pytest.raises(ValueError) as excinfo:
        recall._make_empty_content()

# Rare or unexpected edge cases











from __future__ import annotations

from enum import Enum
from typing import List

import numpy as np
# imports
import pytest  # used for our unit tests
from supervision.detection.core import Detections
from supervision.metrics.core import AveragingMethod, Metric
from supervision.metrics.recall import Recall


class MetricTarget(Enum):
    """
    Specifies what type of detection is used to compute the metric.

    Attributes:
        BOXES: xyxy bounding boxes
        MASKS: Binary masks
        ORIENTED_BOUNDING_BOXES: Oriented bounding boxes (OBB)
    """

    BOXES = "boxes"
    MASKS = "masks"
    ORIENTED_BOUNDING_BOXES = "obb"
from supervision.metrics.recall import Recall

# unit tests




def test_make_empty_content_invalid_metric_target():
    # Test when metric target is an invalid string
    recall = Recall()
    recall._metric_target = "invalid"
    with pytest.raises(ValueError, match="Invalid metric target: invalid"):
        recall._make_empty_content()

def test_make_empty_content_none_metric_target():
    # Test when metric target is None
    recall = Recall()
    recall._metric_target = None
    with pytest.raises(ValueError, match="Invalid metric target: None"):
        recall._make_empty_content()

Codeflash

2. **Efficient Use of Conditions**: Used `elif` to avoid multiple `if` checks in `_make_empty_content`.

This optimized approach should run faster by avoiding redundant checks and using efficient numpy array operations.
@codeflash-ai codeflash-ai bot added the ⚡️ codeflash Optimization PR opened by Codeflash AI label Feb 3, 2025
@codeflash-ai codeflash-ai bot requested a review from misrasaurabh1 February 3, 2025 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡️ codeflash Optimization PR opened by Codeflash AI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants