pyqtgraph/benchmarks/makeARGB.py

131 lines
3.9 KiB
Python
Raw Normal View History

Small ImageItem-related improvements (#1501) * Initial asv configuration * makeARGB benchmarks are working * Fix array type checking and allow making QImage in greyscale mode * Performance improvements * benchmark minor update * Add CLI args to video speed test for easier / automated benchmarking * udpate asv conf * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * Add CLI args to video speed test for easier / automated benchmarking * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * playing with numba * oh, mins/maxes in the other order * maybe put the cupy in here and see what happens * pre-alloc for gpu and cpu * handle possibility of not having cupy * no numba in this branch * organize imports * name them after their use, not their expected device * cupy.take does not support clip mode, so do it explicitly * add CUDA option to the VideoSpeedTest * rename private attr xp to _xp * handle resizes at the last moment * cupy is less accepting of lists as args * or somehow range isn't allowed? what histogram is this? * construct the array with python objects * get the python value right away * put LUT into cupy if needed * docstring about cuda toolkit version * better handling and display of missing cuda lib * lint * import need * handle switching between cupy and numpy in a single ImageItem * only use xp when necessary we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can seamlessly pass into numpy functions. the remaining uses of xp are for our functions which need to allocate new data structures, an operation that has to be substrate-specific. remove empty_cupy; just check if the import succeeded, instead. * use an option to control use of cupy * convert cupy.ceil array to int for easier mathing * RawImageWidget gets to use the getCupy function now, too * raise error to calm linters; rename for clarity * Add Generated Template Files * document things better * cruft removal * warnings to communicate when cupy is expected but somehow broken * Merge branch 'cupy-rebase' into 'l/imageitem-performance' Abundant conflicts; accept theirs in nearly every case. * playing with settings to suss out timeout * playing with more stuff to suss out timeout * replace with empty list * skip test_ExampleApp on linux+pyside2 only * clean out some bits that no longer make sense; linty * ignore airspeed velocity dir * lint * tidy up for merge * lint * lint, avoid shadowing * specific import; run-as-script setup Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com> Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-20 07:19:03 +00:00
import numpy as np
import pyqtgraph as pg
Small ImageItem-related improvements (#1501) * Initial asv configuration * makeARGB benchmarks are working * Fix array type checking and allow making QImage in greyscale mode * Performance improvements * benchmark minor update * Add CLI args to video speed test for easier / automated benchmarking * udpate asv conf * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * Add CLI args to video speed test for easier / automated benchmarking * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * playing with numba * oh, mins/maxes in the other order * maybe put the cupy in here and see what happens * pre-alloc for gpu and cpu * handle possibility of not having cupy * no numba in this branch * organize imports * name them after their use, not their expected device * cupy.take does not support clip mode, so do it explicitly * add CUDA option to the VideoSpeedTest * rename private attr xp to _xp * handle resizes at the last moment * cupy is less accepting of lists as args * or somehow range isn't allowed? what histogram is this? * construct the array with python objects * get the python value right away * put LUT into cupy if needed * docstring about cuda toolkit version * better handling and display of missing cuda lib * lint * import need * handle switching between cupy and numpy in a single ImageItem * only use xp when necessary we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can seamlessly pass into numpy functions. the remaining uses of xp are for our functions which need to allocate new data structures, an operation that has to be substrate-specific. remove empty_cupy; just check if the import succeeded, instead. * use an option to control use of cupy * convert cupy.ceil array to int for easier mathing * RawImageWidget gets to use the getCupy function now, too * raise error to calm linters; rename for clarity * Add Generated Template Files * document things better * cruft removal * warnings to communicate when cupy is expected but somehow broken * Merge branch 'cupy-rebase' into 'l/imageitem-performance' Abundant conflicts; accept theirs in nearly every case. * playing with settings to suss out timeout * playing with more stuff to suss out timeout * replace with empty list * skip test_ExampleApp on linux+pyside2 only * clean out some bits that no longer make sense; linty * ignore airspeed velocity dir * lint * tidy up for merge * lint * lint, avoid shadowing * specific import; run-as-script setup Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com> Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-20 07:19:03 +00:00
from pyqtgraph.functions import makeARGB
try:
import cupy as cp
Small ImageItem-related improvements (#1501) * Initial asv configuration * makeARGB benchmarks are working * Fix array type checking and allow making QImage in greyscale mode * Performance improvements * benchmark minor update * Add CLI args to video speed test for easier / automated benchmarking * udpate asv conf * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * Add CLI args to video speed test for easier / automated benchmarking * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * playing with numba * oh, mins/maxes in the other order * maybe put the cupy in here and see what happens * pre-alloc for gpu and cpu * handle possibility of not having cupy * no numba in this branch * organize imports * name them after their use, not their expected device * cupy.take does not support clip mode, so do it explicitly * add CUDA option to the VideoSpeedTest * rename private attr xp to _xp * handle resizes at the last moment * cupy is less accepting of lists as args * or somehow range isn't allowed? what histogram is this? * construct the array with python objects * get the python value right away * put LUT into cupy if needed * docstring about cuda toolkit version * better handling and display of missing cuda lib * lint * import need * handle switching between cupy and numpy in a single ImageItem * only use xp when necessary we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can seamlessly pass into numpy functions. the remaining uses of xp are for our functions which need to allocate new data structures, an operation that has to be substrate-specific. remove empty_cupy; just check if the import succeeded, instead. * use an option to control use of cupy * convert cupy.ceil array to int for easier mathing * RawImageWidget gets to use the getCupy function now, too * raise error to calm linters; rename for clarity * Add Generated Template Files * document things better * cruft removal * warnings to communicate when cupy is expected but somehow broken * Merge branch 'cupy-rebase' into 'l/imageitem-performance' Abundant conflicts; accept theirs in nearly every case. * playing with settings to suss out timeout * playing with more stuff to suss out timeout * replace with empty list * skip test_ExampleApp on linux+pyside2 only * clean out some bits that no longer make sense; linty * ignore airspeed velocity dir * lint * tidy up for merge * lint * lint, avoid shadowing * specific import; run-as-script setup Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com> Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-20 07:19:03 +00:00
pg.setConfigOption("useCupy", True)
except ImportError:
cp = None
class _TimeSuite(object):
Small ImageItem-related improvements (#1501) * Initial asv configuration * makeARGB benchmarks are working * Fix array type checking and allow making QImage in greyscale mode * Performance improvements * benchmark minor update * Add CLI args to video speed test for easier / automated benchmarking * udpate asv conf * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * Add CLI args to video speed test for easier / automated benchmarking * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * playing with numba * oh, mins/maxes in the other order * maybe put the cupy in here and see what happens * pre-alloc for gpu and cpu * handle possibility of not having cupy * no numba in this branch * organize imports * name them after their use, not their expected device * cupy.take does not support clip mode, so do it explicitly * add CUDA option to the VideoSpeedTest * rename private attr xp to _xp * handle resizes at the last moment * cupy is less accepting of lists as args * or somehow range isn't allowed? what histogram is this? * construct the array with python objects * get the python value right away * put LUT into cupy if needed * docstring about cuda toolkit version * better handling and display of missing cuda lib * lint * import need * handle switching between cupy and numpy in a single ImageItem * only use xp when necessary we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can seamlessly pass into numpy functions. the remaining uses of xp are for our functions which need to allocate new data structures, an operation that has to be substrate-specific. remove empty_cupy; just check if the import succeeded, instead. * use an option to control use of cupy * convert cupy.ceil array to int for easier mathing * RawImageWidget gets to use the getCupy function now, too * raise error to calm linters; rename for clarity * Add Generated Template Files * document things better * cruft removal * warnings to communicate when cupy is expected but somehow broken * Merge branch 'cupy-rebase' into 'l/imageitem-performance' Abundant conflicts; accept theirs in nearly every case. * playing with settings to suss out timeout * playing with more stuff to suss out timeout * replace with empty list * skip test_ExampleApp on linux+pyside2 only * clean out some bits that no longer make sense; linty * ignore airspeed velocity dir * lint * tidy up for merge * lint * lint, avoid shadowing * specific import; run-as-script setup Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com> Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-20 07:19:03 +00:00
def __init__(self):
super(_TimeSuite, self).__init__()
Small ImageItem-related improvements (#1501) * Initial asv configuration * makeARGB benchmarks are working * Fix array type checking and allow making QImage in greyscale mode * Performance improvements * benchmark minor update * Add CLI args to video speed test for easier / automated benchmarking * udpate asv conf * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * Add CLI args to video speed test for easier / automated benchmarking * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * playing with numba * oh, mins/maxes in the other order * maybe put the cupy in here and see what happens * pre-alloc for gpu and cpu * handle possibility of not having cupy * no numba in this branch * organize imports * name them after their use, not their expected device * cupy.take does not support clip mode, so do it explicitly * add CUDA option to the VideoSpeedTest * rename private attr xp to _xp * handle resizes at the last moment * cupy is less accepting of lists as args * or somehow range isn't allowed? what histogram is this? * construct the array with python objects * get the python value right away * put LUT into cupy if needed * docstring about cuda toolkit version * better handling and display of missing cuda lib * lint * import need * handle switching between cupy and numpy in a single ImageItem * only use xp when necessary we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can seamlessly pass into numpy functions. the remaining uses of xp are for our functions which need to allocate new data structures, an operation that has to be substrate-specific. remove empty_cupy; just check if the import succeeded, instead. * use an option to control use of cupy * convert cupy.ceil array to int for easier mathing * RawImageWidget gets to use the getCupy function now, too * raise error to calm linters; rename for clarity * Add Generated Template Files * document things better * cruft removal * warnings to communicate when cupy is expected but somehow broken * Merge branch 'cupy-rebase' into 'l/imageitem-performance' Abundant conflicts; accept theirs in nearly every case. * playing with settings to suss out timeout * playing with more stuff to suss out timeout * replace with empty list * skip test_ExampleApp on linux+pyside2 only * clean out some bits that no longer make sense; linty * ignore airspeed velocity dir * lint * tidy up for merge * lint * lint, avoid shadowing * specific import; run-as-script setup Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com> Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-20 07:19:03 +00:00
self.float_data = None
self.uint8_data = None
self.uint8_lut = None
self.uint16_data = None
self.uint16_lut = None
self.output = None
self.cupy_output = None
Small ImageItem-related improvements (#1501) * Initial asv configuration * makeARGB benchmarks are working * Fix array type checking and allow making QImage in greyscale mode * Performance improvements * benchmark minor update * Add CLI args to video speed test for easier / automated benchmarking * udpate asv conf * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * Add CLI args to video speed test for easier / automated benchmarking * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * playing with numba * oh, mins/maxes in the other order * maybe put the cupy in here and see what happens * pre-alloc for gpu and cpu * handle possibility of not having cupy * no numba in this branch * organize imports * name them after their use, not their expected device * cupy.take does not support clip mode, so do it explicitly * add CUDA option to the VideoSpeedTest * rename private attr xp to _xp * handle resizes at the last moment * cupy is less accepting of lists as args * or somehow range isn't allowed? what histogram is this? * construct the array with python objects * get the python value right away * put LUT into cupy if needed * docstring about cuda toolkit version * better handling and display of missing cuda lib * lint * import need * handle switching between cupy and numpy in a single ImageItem * only use xp when necessary we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can seamlessly pass into numpy functions. the remaining uses of xp are for our functions which need to allocate new data structures, an operation that has to be substrate-specific. remove empty_cupy; just check if the import succeeded, instead. * use an option to control use of cupy * convert cupy.ceil array to int for easier mathing * RawImageWidget gets to use the getCupy function now, too * raise error to calm linters; rename for clarity * Add Generated Template Files * document things better * cruft removal * warnings to communicate when cupy is expected but somehow broken * Merge branch 'cupy-rebase' into 'l/imageitem-performance' Abundant conflicts; accept theirs in nearly every case. * playing with settings to suss out timeout * playing with more stuff to suss out timeout * replace with empty list * skip test_ExampleApp on linux+pyside2 only * clean out some bits that no longer make sense; linty * ignore airspeed velocity dir * lint * tidy up for merge * lint * lint, avoid shadowing * specific import; run-as-script setup Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com> Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-20 07:19:03 +00:00
def setup(self):
size = (self.size, self.size)
self.float_data, self.uint16_data, self.uint8_data, self.uint16_lut, self.uint8_lut = self._create_data(
size, np
)
self.output = np.zeros(size + (4,), dtype=np.ubyte)
makeARGB(self.uint16_data["data"]) # prime the cpu
if cp:
self.cupy_output = cp.zeros(size + (4,), dtype=cp.ubyte)
makeARGB(cp.asarray(self.uint16_data["data"])) # prime the gpu
@staticmethod
def _create_data(size, xp):
float_data = {
"data": xp.random.normal(size=size),
"levels": [-4.0, 4.0],
Small ImageItem-related improvements (#1501) * Initial asv configuration * makeARGB benchmarks are working * Fix array type checking and allow making QImage in greyscale mode * Performance improvements * benchmark minor update * Add CLI args to video speed test for easier / automated benchmarking * udpate asv conf * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * Add CLI args to video speed test for easier / automated benchmarking * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * playing with numba * oh, mins/maxes in the other order * maybe put the cupy in here and see what happens * pre-alloc for gpu and cpu * handle possibility of not having cupy * no numba in this branch * organize imports * name them after their use, not their expected device * cupy.take does not support clip mode, so do it explicitly * add CUDA option to the VideoSpeedTest * rename private attr xp to _xp * handle resizes at the last moment * cupy is less accepting of lists as args * or somehow range isn't allowed? what histogram is this? * construct the array with python objects * get the python value right away * put LUT into cupy if needed * docstring about cuda toolkit version * better handling and display of missing cuda lib * lint * import need * handle switching between cupy and numpy in a single ImageItem * only use xp when necessary we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can seamlessly pass into numpy functions. the remaining uses of xp are for our functions which need to allocate new data structures, an operation that has to be substrate-specific. remove empty_cupy; just check if the import succeeded, instead. * use an option to control use of cupy * convert cupy.ceil array to int for easier mathing * RawImageWidget gets to use the getCupy function now, too * raise error to calm linters; rename for clarity * Add Generated Template Files * document things better * cruft removal * warnings to communicate when cupy is expected but somehow broken * Merge branch 'cupy-rebase' into 'l/imageitem-performance' Abundant conflicts; accept theirs in nearly every case. * playing with settings to suss out timeout * playing with more stuff to suss out timeout * replace with empty list * skip test_ExampleApp on linux+pyside2 only * clean out some bits that no longer make sense; linty * ignore airspeed velocity dir * lint * tidy up for merge * lint * lint, avoid shadowing * specific import; run-as-script setup Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com> Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-20 07:19:03 +00:00
}
uint16_data = {
"data": xp.random.randint(100, 4500, size=size).astype("uint16"),
"levels": [250, 3000],
Small ImageItem-related improvements (#1501) * Initial asv configuration * makeARGB benchmarks are working * Fix array type checking and allow making QImage in greyscale mode * Performance improvements * benchmark minor update * Add CLI args to video speed test for easier / automated benchmarking * udpate asv conf * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * Add CLI args to video speed test for easier / automated benchmarking * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * playing with numba * oh, mins/maxes in the other order * maybe put the cupy in here and see what happens * pre-alloc for gpu and cpu * handle possibility of not having cupy * no numba in this branch * organize imports * name them after their use, not their expected device * cupy.take does not support clip mode, so do it explicitly * add CUDA option to the VideoSpeedTest * rename private attr xp to _xp * handle resizes at the last moment * cupy is less accepting of lists as args * or somehow range isn't allowed? what histogram is this? * construct the array with python objects * get the python value right away * put LUT into cupy if needed * docstring about cuda toolkit version * better handling and display of missing cuda lib * lint * import need * handle switching between cupy and numpy in a single ImageItem * only use xp when necessary we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can seamlessly pass into numpy functions. the remaining uses of xp are for our functions which need to allocate new data structures, an operation that has to be substrate-specific. remove empty_cupy; just check if the import succeeded, instead. * use an option to control use of cupy * convert cupy.ceil array to int for easier mathing * RawImageWidget gets to use the getCupy function now, too * raise error to calm linters; rename for clarity * Add Generated Template Files * document things better * cruft removal * warnings to communicate when cupy is expected but somehow broken * Merge branch 'cupy-rebase' into 'l/imageitem-performance' Abundant conflicts; accept theirs in nearly every case. * playing with settings to suss out timeout * playing with more stuff to suss out timeout * replace with empty list * skip test_ExampleApp on linux+pyside2 only * clean out some bits that no longer make sense; linty * ignore airspeed velocity dir * lint * tidy up for merge * lint * lint, avoid shadowing * specific import; run-as-script setup Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com> Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-20 07:19:03 +00:00
}
uint8_data = {
"data": xp.random.randint(0, 255, size=size).astype("ubyte"),
"levels": [20, 220],
Small ImageItem-related improvements (#1501) * Initial asv configuration * makeARGB benchmarks are working * Fix array type checking and allow making QImage in greyscale mode * Performance improvements * benchmark minor update * Add CLI args to video speed test for easier / automated benchmarking * udpate asv conf * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * Add CLI args to video speed test for easier / automated benchmarking * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * playing with numba * oh, mins/maxes in the other order * maybe put the cupy in here and see what happens * pre-alloc for gpu and cpu * handle possibility of not having cupy * no numba in this branch * organize imports * name them after their use, not their expected device * cupy.take does not support clip mode, so do it explicitly * add CUDA option to the VideoSpeedTest * rename private attr xp to _xp * handle resizes at the last moment * cupy is less accepting of lists as args * or somehow range isn't allowed? what histogram is this? * construct the array with python objects * get the python value right away * put LUT into cupy if needed * docstring about cuda toolkit version * better handling and display of missing cuda lib * lint * import need * handle switching between cupy and numpy in a single ImageItem * only use xp when necessary we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can seamlessly pass into numpy functions. the remaining uses of xp are for our functions which need to allocate new data structures, an operation that has to be substrate-specific. remove empty_cupy; just check if the import succeeded, instead. * use an option to control use of cupy * convert cupy.ceil array to int for easier mathing * RawImageWidget gets to use the getCupy function now, too * raise error to calm linters; rename for clarity * Add Generated Template Files * document things better * cruft removal * warnings to communicate when cupy is expected but somehow broken * Merge branch 'cupy-rebase' into 'l/imageitem-performance' Abundant conflicts; accept theirs in nearly every case. * playing with settings to suss out timeout * playing with more stuff to suss out timeout * replace with empty list * skip test_ExampleApp on linux+pyside2 only * clean out some bits that no longer make sense; linty * ignore airspeed velocity dir * lint * tidy up for merge * lint * lint, avoid shadowing * specific import; run-as-script setup Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com> Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-20 07:19:03 +00:00
}
c_map = xp.array([[-500.0, 255.0], [-255.0, 255.0], [0.0, 500.0]])
uint8_lut = xp.zeros((256, 4), dtype="ubyte")
Small ImageItem-related improvements (#1501) * Initial asv configuration * makeARGB benchmarks are working * Fix array type checking and allow making QImage in greyscale mode * Performance improvements * benchmark minor update * Add CLI args to video speed test for easier / automated benchmarking * udpate asv conf * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * Add CLI args to video speed test for easier / automated benchmarking * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * playing with numba * oh, mins/maxes in the other order * maybe put the cupy in here and see what happens * pre-alloc for gpu and cpu * handle possibility of not having cupy * no numba in this branch * organize imports * name them after their use, not their expected device * cupy.take does not support clip mode, so do it explicitly * add CUDA option to the VideoSpeedTest * rename private attr xp to _xp * handle resizes at the last moment * cupy is less accepting of lists as args * or somehow range isn't allowed? what histogram is this? * construct the array with python objects * get the python value right away * put LUT into cupy if needed * docstring about cuda toolkit version * better handling and display of missing cuda lib * lint * import need * handle switching between cupy and numpy in a single ImageItem * only use xp when necessary we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can seamlessly pass into numpy functions. the remaining uses of xp are for our functions which need to allocate new data structures, an operation that has to be substrate-specific. remove empty_cupy; just check if the import succeeded, instead. * use an option to control use of cupy * convert cupy.ceil array to int for easier mathing * RawImageWidget gets to use the getCupy function now, too * raise error to calm linters; rename for clarity * Add Generated Template Files * document things better * cruft removal * warnings to communicate when cupy is expected but somehow broken * Merge branch 'cupy-rebase' into 'l/imageitem-performance' Abundant conflicts; accept theirs in nearly every case. * playing with settings to suss out timeout * playing with more stuff to suss out timeout * replace with empty list * skip test_ExampleApp on linux+pyside2 only * clean out some bits that no longer make sense; linty * ignore airspeed velocity dir * lint * tidy up for merge * lint * lint, avoid shadowing * specific import; run-as-script setup Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com> Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-20 07:19:03 +00:00
for i in range(3):
uint8_lut[:, i] = xp.clip(xp.linspace(c_map[i][0], c_map[i][1], 256), 0, 255)
uint8_lut[:, 3] = 255
uint16_lut = xp.zeros((2 ** 16, 4), dtype="ubyte")
Small ImageItem-related improvements (#1501) * Initial asv configuration * makeARGB benchmarks are working * Fix array type checking and allow making QImage in greyscale mode * Performance improvements * benchmark minor update * Add CLI args to video speed test for easier / automated benchmarking * udpate asv conf * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * Add CLI args to video speed test for easier / automated benchmarking * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * playing with numba * oh, mins/maxes in the other order * maybe put the cupy in here and see what happens * pre-alloc for gpu and cpu * handle possibility of not having cupy * no numba in this branch * organize imports * name them after their use, not their expected device * cupy.take does not support clip mode, so do it explicitly * add CUDA option to the VideoSpeedTest * rename private attr xp to _xp * handle resizes at the last moment * cupy is less accepting of lists as args * or somehow range isn't allowed? what histogram is this? * construct the array with python objects * get the python value right away * put LUT into cupy if needed * docstring about cuda toolkit version * better handling and display of missing cuda lib * lint * import need * handle switching between cupy and numpy in a single ImageItem * only use xp when necessary we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can seamlessly pass into numpy functions. the remaining uses of xp are for our functions which need to allocate new data structures, an operation that has to be substrate-specific. remove empty_cupy; just check if the import succeeded, instead. * use an option to control use of cupy * convert cupy.ceil array to int for easier mathing * RawImageWidget gets to use the getCupy function now, too * raise error to calm linters; rename for clarity * Add Generated Template Files * document things better * cruft removal * warnings to communicate when cupy is expected but somehow broken * Merge branch 'cupy-rebase' into 'l/imageitem-performance' Abundant conflicts; accept theirs in nearly every case. * playing with settings to suss out timeout * playing with more stuff to suss out timeout * replace with empty list * skip test_ExampleApp on linux+pyside2 only * clean out some bits that no longer make sense; linty * ignore airspeed velocity dir * lint * tidy up for merge * lint * lint, avoid shadowing * specific import; run-as-script setup Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com> Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-20 07:19:03 +00:00
for i in range(3):
uint16_lut[:, i] = xp.clip(xp.linspace(c_map[i][0], c_map[i][1], 2 ** 16), 0, 255)
uint16_lut[:, 3] = 255
return float_data, uint16_data, uint8_data, uint16_lut, uint8_lut
Small ImageItem-related improvements (#1501) * Initial asv configuration * makeARGB benchmarks are working * Fix array type checking and allow making QImage in greyscale mode * Performance improvements * benchmark minor update * Add CLI args to video speed test for easier / automated benchmarking * udpate asv conf * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * Add CLI args to video speed test for easier / automated benchmarking * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * playing with numba * oh, mins/maxes in the other order * maybe put the cupy in here and see what happens * pre-alloc for gpu and cpu * handle possibility of not having cupy * no numba in this branch * organize imports * name them after their use, not their expected device * cupy.take does not support clip mode, so do it explicitly * add CUDA option to the VideoSpeedTest * rename private attr xp to _xp * handle resizes at the last moment * cupy is less accepting of lists as args * or somehow range isn't allowed? what histogram is this? * construct the array with python objects * get the python value right away * put LUT into cupy if needed * docstring about cuda toolkit version * better handling and display of missing cuda lib * lint * import need * handle switching between cupy and numpy in a single ImageItem * only use xp when necessary we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can seamlessly pass into numpy functions. the remaining uses of xp are for our functions which need to allocate new data structures, an operation that has to be substrate-specific. remove empty_cupy; just check if the import succeeded, instead. * use an option to control use of cupy * convert cupy.ceil array to int for easier mathing * RawImageWidget gets to use the getCupy function now, too * raise error to calm linters; rename for clarity * Add Generated Template Files * document things better * cruft removal * warnings to communicate when cupy is expected but somehow broken * Merge branch 'cupy-rebase' into 'l/imageitem-performance' Abundant conflicts; accept theirs in nearly every case. * playing with settings to suss out timeout * playing with more stuff to suss out timeout * replace with empty list * skip test_ExampleApp on linux+pyside2 only * clean out some bits that no longer make sense; linty * ignore airspeed velocity dir * lint * tidy up for merge * lint * lint, avoid shadowing * specific import; run-as-script setup Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com> Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-20 07:19:03 +00:00
def make_test(dtype, use_cupy, use_levels, lut_name, func_name):
Small ImageItem-related improvements (#1501) * Initial asv configuration * makeARGB benchmarks are working * Fix array type checking and allow making QImage in greyscale mode * Performance improvements * benchmark minor update * Add CLI args to video speed test for easier / automated benchmarking * udpate asv conf * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * Add CLI args to video speed test for easier / automated benchmarking * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * playing with numba * oh, mins/maxes in the other order * maybe put the cupy in here and see what happens * pre-alloc for gpu and cpu * handle possibility of not having cupy * no numba in this branch * organize imports * name them after their use, not their expected device * cupy.take does not support clip mode, so do it explicitly * add CUDA option to the VideoSpeedTest * rename private attr xp to _xp * handle resizes at the last moment * cupy is less accepting of lists as args * or somehow range isn't allowed? what histogram is this? * construct the array with python objects * get the python value right away * put LUT into cupy if needed * docstring about cuda toolkit version * better handling and display of missing cuda lib * lint * import need * handle switching between cupy and numpy in a single ImageItem * only use xp when necessary we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can seamlessly pass into numpy functions. the remaining uses of xp are for our functions which need to allocate new data structures, an operation that has to be substrate-specific. remove empty_cupy; just check if the import succeeded, instead. * use an option to control use of cupy * convert cupy.ceil array to int for easier mathing * RawImageWidget gets to use the getCupy function now, too * raise error to calm linters; rename for clarity * Add Generated Template Files * document things better * cruft removal * warnings to communicate when cupy is expected but somehow broken * Merge branch 'cupy-rebase' into 'l/imageitem-performance' Abundant conflicts; accept theirs in nearly every case. * playing with settings to suss out timeout * playing with more stuff to suss out timeout * replace with empty list * skip test_ExampleApp on linux+pyside2 only * clean out some bits that no longer make sense; linty * ignore airspeed velocity dir * lint * tidy up for merge * lint * lint, avoid shadowing * specific import; run-as-script setup Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com> Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-20 07:19:03 +00:00
def time_test(self):
data = getattr(self, dtype + "_data")
levels = data["levels"] if use_levels else None
lut = getattr(self, lut_name + "_lut", None) if lut_name is not None else None
for _ in range(10):
img_data = data["data"]
output = self.output
if use_cupy:
img_data = cp.asarray(img_data)
output = self.cupy_output
makeARGB(
img_data, lut=lut, levels=levels, output=output,
)
if use_cupy:
output.get(out=self.output)
Small ImageItem-related improvements (#1501) * Initial asv configuration * makeARGB benchmarks are working * Fix array type checking and allow making QImage in greyscale mode * Performance improvements * benchmark minor update * Add CLI args to video speed test for easier / automated benchmarking * udpate asv conf * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * Add CLI args to video speed test for easier / automated benchmarking * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * playing with numba * oh, mins/maxes in the other order * maybe put the cupy in here and see what happens * pre-alloc for gpu and cpu * handle possibility of not having cupy * no numba in this branch * organize imports * name them after their use, not their expected device * cupy.take does not support clip mode, so do it explicitly * add CUDA option to the VideoSpeedTest * rename private attr xp to _xp * handle resizes at the last moment * cupy is less accepting of lists as args * or somehow range isn't allowed? what histogram is this? * construct the array with python objects * get the python value right away * put LUT into cupy if needed * docstring about cuda toolkit version * better handling and display of missing cuda lib * lint * import need * handle switching between cupy and numpy in a single ImageItem * only use xp when necessary we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can seamlessly pass into numpy functions. the remaining uses of xp are for our functions which need to allocate new data structures, an operation that has to be substrate-specific. remove empty_cupy; just check if the import succeeded, instead. * use an option to control use of cupy * convert cupy.ceil array to int for easier mathing * RawImageWidget gets to use the getCupy function now, too * raise error to calm linters; rename for clarity * Add Generated Template Files * document things better * cruft removal * warnings to communicate when cupy is expected but somehow broken * Merge branch 'cupy-rebase' into 'l/imageitem-performance' Abundant conflicts; accept theirs in nearly every case. * playing with settings to suss out timeout * playing with more stuff to suss out timeout * replace with empty list * skip test_ExampleApp on linux+pyside2 only * clean out some bits that no longer make sense; linty * ignore airspeed velocity dir * lint * tidy up for merge * lint * lint, avoid shadowing * specific import; run-as-script setup Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com> Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-20 07:19:03 +00:00
time_test.__name__ = func_name
return time_test
for cupy in [True, False]:
if cupy and cp is None:
continue
for dtype in ["float", "uint16", "uint8"]:
for levels in [True, False]:
if dtype == "float" and not levels:
continue
for lutname in [None, "uint8", "uint16"]:
name = (
f'time_10x_makeARGB_{"cupy" if cupy else ""}{dtype}_{"" if levels else "no"}levels_{lutname or "no"}lut'
)
setattr(_TimeSuite, name, make_test(dtype, cupy, levels, lutname, name))
class Time0256Suite(_TimeSuite):
def __init__(self):
self.size = 256
super(Time0256Suite, self).__init__()
class Time0512Suite(_TimeSuite):
def __init__(self):
self.size = 512
super(Time0512Suite, self).__init__()
Small ImageItem-related improvements (#1501) * Initial asv configuration * makeARGB benchmarks are working * Fix array type checking and allow making QImage in greyscale mode * Performance improvements * benchmark minor update * Add CLI args to video speed test for easier / automated benchmarking * udpate asv conf * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * Add CLI args to video speed test for easier / automated benchmarking * use a buffer-qimage so we can avoid allocing so much this should improve performance under windows * playing with numba * oh, mins/maxes in the other order * maybe put the cupy in here and see what happens * pre-alloc for gpu and cpu * handle possibility of not having cupy * no numba in this branch * organize imports * name them after their use, not their expected device * cupy.take does not support clip mode, so do it explicitly * add CUDA option to the VideoSpeedTest * rename private attr xp to _xp * handle resizes at the last moment * cupy is less accepting of lists as args * or somehow range isn't allowed? what histogram is this? * construct the array with python objects * get the python value right away * put LUT into cupy if needed * docstring about cuda toolkit version * better handling and display of missing cuda lib * lint * import need * handle switching between cupy and numpy in a single ImageItem * only use xp when necessary we can now depend on numpy >= 1.17, which means __array_function__-implementing cupy can seamlessly pass into numpy functions. the remaining uses of xp are for our functions which need to allocate new data structures, an operation that has to be substrate-specific. remove empty_cupy; just check if the import succeeded, instead. * use an option to control use of cupy * convert cupy.ceil array to int for easier mathing * RawImageWidget gets to use the getCupy function now, too * raise error to calm linters; rename for clarity * Add Generated Template Files * document things better * cruft removal * warnings to communicate when cupy is expected but somehow broken * Merge branch 'cupy-rebase' into 'l/imageitem-performance' Abundant conflicts; accept theirs in nearly every case. * playing with settings to suss out timeout * playing with more stuff to suss out timeout * replace with empty list * skip test_ExampleApp on linux+pyside2 only * clean out some bits that no longer make sense; linty * ignore airspeed velocity dir * lint * tidy up for merge * lint * lint, avoid shadowing * specific import; run-as-script setup Co-authored-by: Luke Campagnola <luke.campagnola@gmail.com> Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2021-01-20 07:19:03 +00:00
class Time1024Suite(_TimeSuite):
def __init__(self):
self.size = 1024
super(Time1024Suite, self).__init__()
class Time2048Suite(_TimeSuite):
def __init__(self):
self.size = 2048
super(Time2048Suite, self).__init__()
class Time3072Suite(_TimeSuite):
def __init__(self):
self.size = 3072
super(Time3072Suite, self).__init__()
class Time4096Suite(_TimeSuite):
def __init__(self):
self.size = 4096
super(Time4096Suite, self).__init__()