How to use _check_supported method in lisa

Best Python code snippet using lisa_python

utilities.py

Source:utilities.py Github

copy

Full Screen

...3from copy import deepcopy4import numpy as np5from pypianoroll.track import Track6from pypianoroll.multitrack import Multitrack7def _check_supported(obj):8 """9 Raise TypeError if the object is not a :class:`pypianoroll.Multitrack`10 or :class:`pypianoroll.Track` object. Otherwise, pass.11 """12 if not (isinstance(obj, Multitrack) or isinstance(obj, Track)):13 raise TypeError("Support only `pypianoroll.Multitrack` and "14 "`pypianoroll.Track` class objects")15def is_pianoroll(arr):16 """17 Return True if the array is a standard piano-roll matrix. Otherwise,18 return False. Raise TypeError if the input object is not a numpy array.19 """20 if not isinstance(arr, np.ndarray):21 raise TypeError("`arr` must be of np.ndarray type")22 if not (np.issubdtype(arr.dtype, np.bool_)23 or np.issubdtype(arr.dtype, np.number)):24 return False25 if arr.ndim != 2:26 return False27 if arr.shape[1] != 128:28 return False29 return True30def assign_constant(obj, value):31 """32 Assign a constant value to the nonzeros in the piano-roll(s). If a33 piano-roll is not binarized, its data type will be preserved. If a34 piano-roll is binarized, it will be casted to the type of `value`.35 Arguments36 ---------37 value : int or float38 The constant value to be assigned to the nonzeros of the39 piano-roll(s).40 """41 _check_supported(obj)42 obj.assign_constant(value)43def binarize(obj, threshold=0):44 """45 Return a copy of the object with binarized piano-roll(s).46 Parameters47 ----------48 threshold : int or float49 Threshold to binarize the piano-roll(s). Default to zero.50 """51 _check_supported(obj)52 copied = deepcopy(obj)53 copied.binarize(threshold)54 return copied55def clip(obj, lower=0, upper=127):56 """57 Return a copy of the object with piano-roll(s) clipped by a lower bound58 and an upper bound specified by `lower` and `upper`, respectively.59 Parameters60 ----------61 lower : int or float62 The lower bound to clip the piano-roll. Default to 0.63 upper : int or float64 The upper bound to clip the piano-roll. Default to 127.65 """66 _check_supported(obj)67 copied = deepcopy(obj)68 copied.clip(lower, upper)69 return copied70def copy(obj):71 """Return a copy of the object."""72 _check_supported(obj)73 copied = deepcopy(obj)74 return copied75def load(filepath):76 """77 Return a :class:`pypianoroll.Multitrack` object loaded from a .npz file.78 Parameters79 ----------80 filepath : str81 The file path to the .npz file.82 """83 if not filepath.endswith('.npz'):84 raise ValueError("Only .npz files are supported")85 multitrack = Multitrack(filepath)86 return multitrack87def pad(obj, pad_length):88 """89 Return a copy of the object with piano-roll padded with zeros at the end90 along the time axis.91 Parameters92 ----------93 pad_length : int94 The length to pad along the time axis with zeros.95 """96 if not isinstance(obj, Track):97 raise TypeError("Support only `pypianoroll.Track` class objects")98 copied = deepcopy(obj)99 copied.pad(pad_length)100 return copied101def pad_to_same(obj):102 """103 Return a copy of the object with shorter piano-rolls padded with zeros104 at the end along the time axis to the length of the piano-roll with the105 maximal length.106 """107 if not isinstance(obj, Multitrack):108 raise TypeError("Support only `pypianoroll.Multitrack` class objects")109 copied = deepcopy(obj)110 copied.pad_to_same()111 return copied112def pad_to_multiple(obj, factor):113 """114 Return a copy of the object with its piano-roll padded with zeros at the115 end along the time axis with the minimal length that make the length of116 the resulting piano-roll a multiple of `factor`.117 Parameters118 ----------119 factor : int120 The value which the length of the resulting piano-roll will be121 a multiple of.122 """123 if not isinstance(obj, Track):124 raise TypeError("Support only `pypianoroll.Track` class objects")125 copied = deepcopy(obj)126 copied.pad_to_multiple(factor)127 return copied128def parse(filepath):129 """130 Return a :class:`pypianoroll.Multitrack` object loaded from a MIDI131 (.mid, .midi, .MID, .MIDI) file.132 Parameters133 ----------134 filepath : str135 The file path to the MIDI file.136 """137 if not filepath.endswith(('.mid', '.midi', '.MID', '.MIDI')):138 raise ValueError("Only MIDI files are supported")139 multitrack = Multitrack(filepath)140 return multitrack141def plot(obj, **kwargs):142 """143 Plot the object. See :func:`pypianoroll.Multitrack.plot` and144 :func:`pypianoroll.Track.plot` for full documentation.145 """146 _check_supported(obj)147 return obj.plot(**kwargs)148def save(filepath, obj, compressed=True):149 """150 Save the object to a .npz file.151 Parameters152 ----------153 filepath : str154 The path to save the file.155 obj: `pypianoroll.Multitrack` objects156 The objecte to be saved.157 """158 if not isinstance(obj, Multitrack):159 raise TypeError("Support only `pypianoroll.Multitrack` class objects")160 obj.save(filepath, compressed)161def transpose(obj, semitone):162 """163 Return a copy of the object with piano-roll(s) transposed by `semitones`164 semitones.165 Parameters166 ----------167 semitone : int168 Number of semitones to transpose the piano-roll(s).169 """170 _check_supported(obj)171 copied = deepcopy(obj)172 copied.transpose(semitone)173 return copied174def trim_trailing_silence(obj):175 """176 Return a copy of the object with trimmed trailing silence of the177 piano-roll(s).178 """179 _check_supported(obj)180 copied = deepcopy(obj)181 length = copied.get_active_length()182 copied.pianoroll = copied.pianoroll[:length]183 return copied184def write(obj, filepath):185 """186 Write the object to a MIDI file.187 Parameters188 ----------189 filepath : str190 The path to write the MIDI file.191 """192 if not isinstance(obj, Multitrack):193 raise TypeError("Support only `pypianoroll.Multitrack` class objects")...

Full Screen

Full Screen

base_continuous_distribution.py

Source:base_continuous_distribution.py Github

copy

Full Screen

...9 return 010 def _is_supported(self, x: float) -> bool:11 return True12 def less_than(self, x: float) -> float:13 self._check_supported(x)14 return self.cdf(x)15 def less_than_equals(self, x: float) -> float:16 self._check_supported(x)17 return self.cdf(x)18 def greater_than(self, x: float) -> float:19 self._check_supported(x)20 return 1 - self.cdf(x)21 def greater_than_equals(self, x: float) -> float:22 self._check_supported(x)23 return 1 - self.cdf(x)24 def between(self, upper: float, lower: float):25 return self.less_than_equals(upper) - self.less_than_equals(lower)26 def pdf_range(self, x: typing.Iterable):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful