Exemple #1
0
 def test_collapse_None(self, input_data, input_var, input_layer_with_None):
     from lasagne.layers.shape import DimshuffleLayer
     ds_ok = DimshuffleLayer(input_layer_with_None, [0, 1, 3, 4])
     ds_bad = DimshuffleLayer(input_layer_with_None, [0, 1, 2, 4])
     assert ds_ok.get_output_shape() == (2, 3, 5, 7)
     assert ds_ok.get_output_for(input_var).eval(
         {input_var: input_data}).shape == (2, 3, 5, 7)
     with pytest.raises(ValueError):
         ds_bad.get_output_shape()
Exemple #2
0
 def test_invalid_pattern(self, input_data, input_var, input_layer):
     from lasagne.layers.shape import DimshuffleLayer
     with pytest.raises(ValueError):
         DimshuffleLayer(input_layer, ['q'])
     with pytest.raises(ValueError):
         DimshuffleLayer(input_layer, [0, 0, 1, 3, 4])
     # There is no dimension 42
     ds_bad = DimshuffleLayer(input_layer, [0, 1, 2, 4, 42])
     with pytest.raises(ValueError):
         ds_bad.get_output_shape()
Exemple #3
0
 def test_collapse_None(self, input_data, input_var, input_layer_with_None):
     from lasagne.layers.shape import DimshuffleLayer
     ds_ok = DimshuffleLayer(input_layer_with_None, [0, 1, 3, 4])
     ds_bad = DimshuffleLayer(input_layer_with_None, [0, 1, 2, 4])
     assert ds_ok.get_output_shape() == (2, 3, 5, 7)
     assert ds_ok.get_output_for(input_var).eval({
         input_var: input_data
     }).shape == (2, 3, 5, 7)
     with pytest.raises(ValueError):
         ds_bad.get_output_shape()
Exemple #4
0
 def test_invalid_pattern(self, input_data, input_var, input_layer):
     from lasagne.layers.shape import DimshuffleLayer
     with pytest.raises(ValueError):
         DimshuffleLayer(input_layer, ['q'])
     with pytest.raises(ValueError):
         DimshuffleLayer(input_layer, [0, 0, 1, 3, 4])
     # There is no dimension 42
     ds_bad = DimshuffleLayer(input_layer, [0, 1, 2, 4, 42])
     with pytest.raises(ValueError):
         ds_bad.get_output_shape()
Exemple #5
0
 def test_broadcast(self, input_data, input_var, input_layer):
     from lasagne.layers.shape import DimshuffleLayer
     ds = DimshuffleLayer(input_layer, [0, 1, 2, 3, 4, 'x'])
     assert ds.get_output_shape() == (2, 3, 1, 5, 7, 1)
     assert ds.get_output_for(input_var).eval({
         input_var: input_data
     }).shape == (2, 3, 1, 5, 7, 1)
Exemple #6
0
 def test_rearrange(self, input_data, input_var, input_layer):
     from lasagne.layers.shape import DimshuffleLayer
     ds = DimshuffleLayer(input_layer, [4, 3, 2, 1, 0])
     assert ds.get_output_shape() == (7, 5, 1, 3, 2)
     assert ds.get_output_for(input_var).eval({
         input_var: input_data
     }).shape == (7, 5, 1, 3, 2)
Exemple #7
0
 def test_broadcast(self, input_data, input_var, input_layer):
     from lasagne.layers.shape import DimshuffleLayer
     ds = DimshuffleLayer(input_layer, [0, 1, 2, 3, 4, 'x'])
     assert ds.get_output_shape() == (2, 3, 1, 5, 7, 1)
     assert ds.get_output_for(input_var).eval(
         {input_var: input_data}).shape == (2, 3, 1, 5, 7, 1)
Exemple #8
0
 def test_rearrange(self, input_data, input_var, input_layer):
     from lasagne.layers.shape import DimshuffleLayer
     ds = DimshuffleLayer(input_layer, [4, 3, 2, 1, 0])
     assert ds.get_output_shape() == (7, 5, 1, 3, 2)
     assert ds.get_output_for(input_var).eval(
         {input_var: input_data}).shape == (7, 5, 1, 3, 2)