


'''simple docstring'''







import gc
import unittest

from diffusers import FlaxDPMSolverMultistepScheduler, FlaxStableDiffusionPipeline
from diffusers.utils import is_flax_available, slow
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
       import jax
       import jax.numpy as jnp
       from flax.jax_utils import replicate
       from flax.training.common_utils import shard
@slow
@require_flax
class 	UpperCamelCase__					( unittest.TestCase	):



     """simple docstring"""






     def a	( self   ):

            '''simple docstring'''

            super().tearDown()
            gc.collect()







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							List[Any]   			=       FlaxStableDiffusionPipeline.from_pretrained(
                'stabilityai/stable-diffusion-2'      ,	revision='bf16'      ,	dtype=jnp.bfloataa      ,	)

            _lowerCAmelCase    :							List[Any]   			=       'A painting of a squirrel eating a burger'
            _lowerCAmelCase    :							Optional[int]   			=       jax.device_count()
            _lowerCAmelCase    :							Tuple   			=       num_samples * [prompt]
            _lowerCAmelCase    :							Optional[int]   			=       sd_pipe.prepare_inputs(snake_case__   )

            _lowerCAmelCase    :							Tuple   			=       replicate(snake_case__   )
            _lowerCAmelCase    :							str   			=       shard(snake_case__   )

            _lowerCAmelCase    :							Tuple   			=       jax.random.PRNGKey(0   )
            _lowerCAmelCase    :							Any   			=       jax.random.split(snake_case__      ,	jax.device_count()   )

            _lowerCAmelCase    :							Dict   			=       sd_pipe(snake_case__      ,	snake_case__      ,	snake_case__      ,	num_inference_steps=25      ,	jit=snake_case__   )[0]
            assert images.shape == (jax.device_count(), 1, 768, 768, 3)

            _lowerCAmelCase    :							Dict   			=       images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]   )
            _lowerCAmelCase    :							Optional[int]   			=       images[0, 253:256, 253:256, -1]

            _lowerCAmelCase    :							List[str]   			=       jnp.asarray(jax.device_get(image_slice.flatten()   )   )
            _lowerCAmelCase    :							int   			=       jnp.array([0.4238, 0.4414, 0.4395, 0.4453, 0.4629, 0.4590, 0.4531, 0.4_5508, 0.4512]   )
            print(F'output_slice: {output_slice}'   )
            assert jnp.abs(output_slice - expected_slice   ).max() < 1E-2







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							int   			=       'stabilityai/stable-diffusion-2'
            _lowerCAmelCase    :							Optional[Any]   			=       FlaxDPMSolverMultistepScheduler.from_pretrained(snake_case__      ,	subfolder='scheduler'   )
            _lowerCAmelCase    :							Optional[int]   			=       FlaxStableDiffusionPipeline.from_pretrained(
                snake_case__      ,	scheduler=snake_case__      ,	revision='bf16'      ,	dtype=jnp.bfloataa      ,	)
            _lowerCAmelCase    :							Any   			=       scheduler_params

            _lowerCAmelCase    :							Tuple   			=       'A painting of a squirrel eating a burger'
            _lowerCAmelCase    :							Optional[int]   			=       jax.device_count()
            _lowerCAmelCase    :							Any   			=       num_samples * [prompt]
            _lowerCAmelCase    :							Dict   			=       sd_pipe.prepare_inputs(snake_case__   )

            _lowerCAmelCase    :							Tuple   			=       replicate(snake_case__   )
            _lowerCAmelCase    :							Optional[int]   			=       shard(snake_case__   )

            _lowerCAmelCase    :							Optional[int]   			=       jax.random.PRNGKey(0   )
            _lowerCAmelCase    :							Dict   			=       jax.random.split(snake_case__      ,	jax.device_count()   )

            _lowerCAmelCase    :							List[Any]   			=       sd_pipe(snake_case__      ,	snake_case__      ,	snake_case__      ,	num_inference_steps=25      ,	jit=snake_case__   )[0]
            assert images.shape == (jax.device_count(), 1, 768, 768, 3)

            _lowerCAmelCase    :							Dict   			=       images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]   )
            _lowerCAmelCase    :							Optional[int]   			=       images[0, 253:256, 253:256, -1]

            _lowerCAmelCase    :							Dict   			=       jnp.asarray(jax.device_get(image_slice.flatten()   )   )
            _lowerCAmelCase    :							Any   			=       jnp.array([0.4336, 0.4_2969, 0.4453, 0.4199, 0.4297, 0.4531, 0.4434, 0.4434, 0.4297]   )
            print(F'output_slice: {output_slice}'   )
            assert jnp.abs(output_slice - expected_slice   ).max() < 1E-2





'''simple docstring'''







import unittest

from knapsack import greedy_knapsack as kp
class 	UpperCamelCase__					( unittest.TestCase	):



     """simple docstring"""






     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Union[str, Any]   			=       [10, 20, 30, 40, 50, 60]
            _lowerCAmelCase    :							Union[str, Any]   			=       [2, 4, 6, 8, 10, 12]
            _lowerCAmelCase    :							Dict   			=       100
            self.assertEqual(kp.calc_profit(snake_case__      ,	snake_case__      ,	snake_case__   )      ,	210   )







     def a	( self   ):

            '''simple docstring'''

            self.assertRaisesRegex(snake_case__      ,	'max_weight must greater than zero.'   )







     def a	( self   ):

            '''simple docstring'''

            self.assertRaisesRegex(snake_case__      ,	'Weight can not be negative.'   )







     def a	( self   ):

            '''simple docstring'''

            self.assertRaisesRegex(snake_case__      ,	'Profit can not be negative.'   )







     def a	( self   ):

            '''simple docstring'''

            self.assertRaisesRegex(snake_case__      ,	'max_weight must greater than zero.'   )







     def a	( self   ):

            '''simple docstring'''

            self.assertRaisesRegex(
                snake_case__      ,	'The length of profit and weight must be same.'   )


if __name__ == "__main__":
       unittest.main()

