Write test for from_dataset

Now we have a test code for from_dataset function. It tests if the function can return a DenseDesignMatrix in proper shape while the passed parameter has/has not a y vector of integers. For the current version of from_dataset(), there is no problem dealing with integer "y"s.

However, I find another bug of this function: If the passed DenseDesignMatrix does not define a topological view, it will fail. I don't deem it to be proper because dataset without a topo_view could still return its slice while asked for a slice of it: 


>>> dataset = DenseDesignMatrix(X=X, y=y)       # X is a 2-d ndarray and y is 1-d vector of labels.
>>> from_dataset(dataset, 5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "dense_design_matrix.py", line 1492, in from_dataset
    V, y = dataset.get_batch_topo(num_examples, True)
  File "dense_design_matrix.py", line 911, in get_batch_topo
    rval = self.view_converter.design_mat_to_topo_view(batch_design)
AttributeError: 'NoneType' object has no attribute 'design_mat_to_topo_view'


The culprit is that in the method get_batch_topo(), it is always calling the view_converter, which does not exist while we pass a DenseDesignMatrix with no topo view. Should I fix it?
OK. I have changed it now.

On Monday, November 17, 2014, Bart van Merriënboer <notifications@github.com>
wrote:

> In pylearn2/datasets/tests/test_dense_design_matrix.py:
>
> > @@ -75,3 +76,33 @@ def test_pytables():
> >
> >      it = ds.iterator(mode='sequential', batch_size=1)
> >      it.next()
> > +
> > +
> > +def test_from_dataset():
> > +    """
> > +    Tests whether it supports integer labels.
> > +    """
> > +    rng = np.random.RandomState([1, 2, 3])
> > +    topo_view = rng.randn(12, 2, 3, 3)
> > +    y = rng.randint(0, 5, 12)
>
> I think this should be y = rng.randint(0, 5, (12, 1)). Passing y has a 1D
> array used to be supported, but isn't anymore, so although it works here,
> it might break in the future.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/lisa-lab/pylearn2/pull/1247/files#r20484641>.
>


-- 
LIN, Zhouhan
Department of Computer Science and Operational Research
University of Montreal

Phone: +01-514-553-6037
Email: lin.zhouhan@gmail.com
Homepage:http://zhouhanlin.webs.com/