<s> import numpy <EOL> import theano <EOL> from fuel . datasets import IterableDataset <EOL> from theano import tensor <EOL> from blocks . algorithms import GradientDescent , Scale <EOL> from blocks . extensions import FinishAfter , ProgressBar , Printing <EOL> from blocks . main_loop import MainLoop <EOL> from blocks . utils import shared_floatx <EOL> def setup_mainloop ( extension ) : <EOL> """<STR_LIT>""" <EOL> features = [ numpy . array ( f , dtype = theano . config . floatX ) <EOL> for f in [ [ <NUM_LIT:1> , <NUM_LIT:2> ] ] * <NUM_LIT> ] <EOL> dataset = IterableDataset ( dict ( features = features ) ) <EOL> W = shared_floatx ( [ <NUM_LIT:0> , <NUM_LIT:0> ] , name = '<STR_LIT>' ) <EOL> x = tensor . vector ( '<STR_LIT>' ) <EOL> cost = tensor . sum ( ( x - W ) ** <NUM_LIT:2> ) <EOL> cost . name = "<STR_LIT>" <EOL> algorithm = GradientDescent ( cost = cost , parameters = [ W ] , <EOL> step_rule = Scale ( <NUM_LIT> ) ) <EOL> main_loop = MainLoop ( <EOL> model = None , data_stream = dataset . get_example_stream ( ) , <EOL> algorithm = algorithm , <EOL> extensions = [ <EOL> FinishAfter ( after_n_epochs = <NUM_LIT:1> ) , <EOL> extension ] ) <EOL> return main_loop <EOL> def test_progressbar ( ) : <EOL> main_loop = setup_mainloop ( ProgressBar ( ) ) <EOL> main_loop . run ( ) <EOL> def test_printing ( ) : <EOL> main_loop = setup_mainloop ( Printing ( ) ) <EOL> main_loop . run ( ) </s>
