Exemple #1
0
def test_perf_to_rgb_2d():
    hsl = np.random.rand(19200, 3) * 100
    import nphusl
    nphusl.enable_standard_fns()
    cs = None
    t1 = timeit.timeit("nphusl.to_rgb(hsl, chunksize=cs)", number=1, globals=locals())
    nphusl.enable_numexpr_fns()
    t2 = timeit.timeit("nphusl.to_rgb(hsl, chunksize=cs)", number=1, globals=locals())
    nphusl.enable_cython_fns()
    t3 = timeit.timeit("nphusl.to_rgb(hsl, chunksize=cs)", number=1, globals=locals())
    print("to_rgb()\nCython: {}\nNumExpr: {}\nNumpy: {}".format(
          t3, t2, t1))
    assert t3 < t2 < t1
Exemple #2
0
def test_perf_rgb_to_husl_2d():
    rgb = np.random.rand(19200, 3)
    nphusl.enable_cython_fns()
    go_cy = cy.rgb_to_husl
    t_cy = timeit.timeit("go_cy(rgb)", number=1, globals=locals())
    nphusl.enable_standard_fns()
    nphusl.enable_numexpr_fns()
    go_ex = nphusl.rgb_to_husl
    t_ex = timeit.timeit("go_ex(rgb)", number=1, globals=locals())
    nphusl.enable_standard_fns()
    go_np = nphusl.rgb_to_husl
    t_np = timeit.timeit("go_np(rgb)", number=1, globals=locals())
    print("\n2D RGB->HUSL: "
          "\nCython: {}s\nNumExpr: {}s\nNumpy: {}s".format(
            t_cy, t_ex, t_np))
    assert t_cy < t_ex and t_cy < t_np
Exemple #3
0
def test_perf_cython_husl_to_rgb():
    hsl = np.random.rand(1920, 1080, 3) * 100
    nphusl.enable_cython_fns()
    go_cy = cy.husl_to_rgb
    t_cy = timeit.timeit("go_cy(hsl)", number=1, globals=locals())
    nphusl.enable_standard_fns()
    nphusl.enable_numexpr_fns()
    go_ex = nphusl.husl_to_rgb
    t_ex = timeit.timeit("go_ex(hsl)", number=1, globals=locals())
    nphusl.enable_standard_fns()
    go_np = nphusl.husl_to_rgb
    t_np = timeit.timeit("go_np(hsl)", number=1, globals=locals())
    print("\n1080p image HUSL->RGB: "
          "\nCython: {}s\nNumExpr: {}s\nNumpy: {}s".format(
            t_cy, t_ex, t_np))
    assert t_cy < t_ex < t_np
    assert t_np / t_cy > 2
Exemple #4
0
 def with_cyth(*args, **kwargs):
     assert hasattr(nphusl, "_nphusl_cython")
     nphusl.enable_cython_fns()
     fn(*args, **kwargs)
     nphusl.enable_standard_fns()
Exemple #5
0
 def with_expr(*args, **kwargs):
     assert hasattr(nphusl, "_nphusl_expr")
     nphusl.enable_numexpr_fns()
     fn(*args, **kwargs)
     nphusl.enable_standard_fns()
Exemple #6
0
import argparse
import sys

import imread
import numpy as np

import nphusl
from nphusl.nphusl import _channel
import husl  # the original husl-colors.org library


nphusl.enable_standard_fns()  # test, by default, without optimizations


### Tests for conversion in the RGB -> HUSL direction

def try_all_optimizations(fn):
    def with_expr(*args, **kwargs):
        assert hasattr(nphusl, "_nphusl_expr")
        nphusl.enable_numexpr_fns()
        fn(*args, **kwargs)
        nphusl.enable_standard_fns()

    def with_cyth(*args, **kwargs):
        assert hasattr(nphusl, "_nphusl_cython")
        nphusl.enable_cython_fns()
        fn(*args, **kwargs)
        nphusl.enable_standard_fns()

    globals()[fn.__name__ + "__with_numexp"] = with_expr
    globals()[fn.__name__ + "__with_cython"] = with_cyth