# Compressed tensor types.

load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")

package(
    default_applicable_licenses = [
        "//:license",  # Placeholder comment, do not modify
    ],
    # Placeholder for internal compatible_with
    default_visibility = [
        # Placeholder for internal visibility,
        # Users require gcpp::Path etc., which are defined in this package.
        "//visibility:public",
    ],
)

config_setting(
    name = "android",
    constraint_values = [
        "@platforms//os:android",
    ],
    visibility = ["//visibility:private"],
)

cc_library(
    name = "distortion",
    hdrs = [
        "distortion.h",
        "types.h",
    ],
    deps = [
        "//:basics",
        "@highway//:hwy",
        "@highway//:stats",
        "@highway//hwy/contrib/sort:vqsort",
    ],
)

cc_test(
    name = "distortion_test",
    size = "small",
    srcs = ["distortion_test.cc"],
    deps = [
        ":distortion",
        "@googletest//:gtest_main",  # buildcleaner: keep
        "//:test_util",
        "@highway//:hwy_test_util",
        "@highway//:nanobenchmark",  # Unpredictable1
    ],
)

cc_library(
    name = "types",
    hdrs = ["types.h"],
    deps = [
        "//:basics",
        "@highway//:hwy",
    ],
)

cc_library(
    name = "sfp",
    textual_hdrs = ["sfp-inl.h"],
    deps = [
        ":types",
        "@highway//:hwy",
    ],
)

cc_library(
    name = "nuq",
    textual_hdrs = ["nuq-inl.h"],
    deps = [
        ":sfp",
        ":types",
        "//:basics",
        "@highway//:hwy",
        "@highway//hwy/contrib/sort:vqsort",
    ],
)

cc_library(
    name = "int",
    textual_hdrs = ["int-inl.h"],
    deps = [
        ":types",
        "//:basics",
        "@highway//:hwy",
    ],
)

cc_test(
    name = "int_test",
    size = "small",
    timeout = "long",
    srcs = ["int_test.cc"],
    features = ["fully_static_link"],
    linkstatic = True,
    local_defines = ["HWY_IS_TEST"],
    # for test_suite.
    tags = ["hwy_ops_test"],
    deps = [
        ":int",
        "@googletest//:gtest_main",  # buildcleaner: keep
        "//:test_util",
        "@highway//:hwy",
        "@highway//:hwy_test_util",
    ],
)

cc_library(
    name = "test_util",
    textual_hdrs = [
        "test_util-inl.h",
    ],
    deps = [
        ":compress",
        ":distortion",
        "//:mat",
        "//:threading_context",
        "@highway//:hwy",
        "@highway//:hwy_test_util",
    ],
)

cc_test(
    name = "sfp_test",
    size = "small",
    srcs = ["sfp_test.cc"],
    linkstatic = True,
    local_defines = ["HWY_IS_TEST"],
    # for test_suite.
    tags = ["hwy_ops_test"],
    deps = [
        ":compress",
        ":distortion",
        "@googletest//:gtest_main",  # buildcleaner: keep
        "//:test_util",
        "@highway//:hwy",
        "@highway//:hwy_test_util",
        "@highway//:nanobenchmark",
    ],
)

cc_test(
    name = "nuq_test",
    size = "small",
    timeout = "long",
    srcs = ["nuq_test.cc"],
    linkstatic = True,
    local_defines = ["HWY_IS_TEST"],
    # for test_suite.
    tags = ["hwy_ops_test"],
    deps = [
        ":distortion",
        ":nuq",
        "@googletest//:gtest_main",  # buildcleaner: keep
        "//:test_util",
        "@highway//:hwy",
        "@highway//:hwy_test_util",
        "@highway//:nanobenchmark",
    ],
)

cc_library(
    name = "compress",
    srcs = ["compress.cc"],
    hdrs = [
        "compress.h",
        "types.h",
    ],
    textual_hdrs = ["compress-inl.h"],
    deps = [
        ":distortion",
        ":int",
        ":nuq",
        ":sfp",
        "//:basics",
        "//:mat",
        "//:threading_context",
        "@highway//:hwy",
        "@highway//:profiler",
        "@highway//:stats",
        "@highway//:thread_pool",
    ],
)

cc_test(
    name = "compress_test",
    size = "small",
    timeout = "long",
    srcs = ["compress_test.cc"],
    linkstatic = True,
    local_defines = ["HWY_IS_TEST"],
    # for test_suite.
    tags = ["hwy_ops_test"],
    deps = [
        ":compress",
        ":distortion",
        ":test_util",
        "@googletest//:gtest_main",  # buildcleaner: keep
        "//:test_util",
        "//:threading_context",
        "@highway//:hwy",
        "@highway//:hwy_test_util",
    ],
)
