コード例 #1
0
ファイル: test_sparse_reader.py プロジェクト: wibrt/orange3
    def test_read_simple(self):
        f = tempfile.NamedTemporaryFile(delete=False)
        f.write(simple_file.encode("ascii"))
        f.close()
        try:
            X, Y, metas, attr_indices, class_indices, meta_indices = \
                _io.sparse_read_float(f.name.encode("ascii"))

            self.assertEqual(
                attr_indices, {
                    b"abc": 0,
                    b"def": 1,
                    b"g": 2,
                    b"h": 3,
                    b"ij k": 4,
                    b"t": 5,
                    b"ij": 6,
                    b"kl": 7,
                    b"m": 8
                })
            np.testing.assert_almost_equal(
                X.data, [1, 1, 1, 1, 5, 1, 1, 1, 1, 1, 4, 1, 1])
            np.testing.assert_equal(X.indices,
                                    [0, 1, 2, 3, 4, 5, 1, 2, 3, 6, 7, 8, 1])
            np.testing.assert_equal(X.indptr, [0, 6, 12, 13])

            self.assertEqual(class_indices, {})
            self.assertIsNone(Y)

            self.assertEqual(meta_indices, {})
            self.assertIsNone(metas)
        finally:
            os.remove(f.name)
コード例 #2
0
ファイル: test_sparse_reader.py プロジェクト: wibrt/orange3
    def test_read_complex(self):
        f = tempfile.NamedTemporaryFile(delete=False)
        f.write(complex_file.encode("ascii"))
        f.close()
        try:
            X, Y, metas, attr_indices, class_indices, meta_indices = \
                _io.sparse_read_float(f.name.encode("ascii"))

            self.assertEqual(attr_indices, {
                b"abc": 0,
                b"g": 1,
                b"h": 2,
                b"ij": 3
            })
            np.testing.assert_equal(X.data, [1, 1, 1, 1, 1, 1, 1])
            np.testing.assert_equal(X.indices, [0, 1, 2, 3, 1, 2, 3])
            np.testing.assert_equal(X.indptr, [0, 4, 7, 7])

            self.assertEqual(class_indices, {b"k": 0, b"t": 1, b"kl": 2})
            np.testing.assert_equal(Y.data, [5, 1, 1, 4])
            np.testing.assert_equal(Y.indices, [0, 1, 0, 2])
            np.testing.assert_equal(Y.indptr, [0, 2, 4, 4])

            self.assertEqual(meta_indices, {b"m": 0, b"def": 1})
            np.testing.assert_equal(metas.data, [1, 1])
            np.testing.assert_equal(metas.indices, [0, 1])
            np.testing.assert_equal(metas.indptr, [0, 0, 1, 2])
        finally:
            os.remove(f.name)
コード例 #3
0
    def test_read_complex(self):
        f = tempfile.NamedTemporaryFile(delete=False)
        f.write(complex_file.encode("ascii"))
        f.close()
        try:
            X, Y, metas, attr_indices, class_indices, meta_indices = \
                _io.sparse_read_float(f.name.encode("ascii"))

            self.assertEqual(attr_indices,
                {b"abc": 0, b"g": 1, b"h": 2, b"ij": 3})
            np.testing.assert_equal(X.data,    [1, 1, 1, 1, 1, 1, 1])
            np.testing.assert_equal(X.indices, [0, 1, 2, 3, 1, 2, 3])
            np.testing.assert_equal(X.indptr,  [0,          4,       7, 7])


            self.assertEqual(class_indices, {b"k": 0, b"t": 1, b"kl": 2})
            np.testing.assert_equal(Y.data,    [5, 1, 1, 4])
            np.testing.assert_equal(Y.indices, [0, 1, 0, 2])
            np.testing.assert_equal(Y.indptr,  [0,    2,   4, 4])

            self.assertEqual(meta_indices, {b"m": 0, b"def": 1})
            np.testing.assert_equal(metas.data,    [   1, 1])
            np.testing.assert_equal(metas.indices, [   0, 1])
            np.testing.assert_equal(metas.indptr,  [0, 0, 1, 2])
        finally:
            os.remove(f.name)
コード例 #4
0
    def test_read_simple(self):
        f = tempfile.NamedTemporaryFile(delete=False)
        f.write(simple_file.encode("ascii"))
        f.close()
        try:
            X, Y, metas, attr_indices, class_indices, meta_indices = \
                _io.sparse_read_float(f.name.encode("ascii"))

            self.assertEqual(attr_indices,
                {b"abc": 0, b"def": 1, b"g": 2, b"h": 3, b"ij k": 4, b"t": 5,
                 b"ij": 6, b"kl": 7, b"m": 8})
            np.testing.assert_almost_equal(X.data, [1, 1, 1, 1, 5, 1,
                                                  1, 1, 1, 1, 4, 1,
                                                  1])
            np.testing.assert_equal(X.indices, [0, 1, 2, 3, 4, 5,
                                           1, 2, 3, 6, 7, 8,
                                           1])
            np.testing.assert_equal(X.indptr, [0, 6, 12, 13])

            self.assertEqual(class_indices, {})
            self.assertIsNone(Y)

            self.assertEqual(meta_indices, {})
            self.assertIsNone(metas)
        finally:
            os.remove(f.name)
コード例 #5
0
    def read(self):
        def constr_vars(inds):
            if inds:
                return [ContinuousVariable(x.decode("utf-8")) for _, x in
                        sorted((ind, name) for name, ind in inds.items())]

        X, Y, metas, attr_indices, class_indices, meta_indices = \
            _io.sparse_read_float(self.filename.encode(sys.getdefaultencoding()))

        attrs = constr_vars(attr_indices)
        classes = constr_vars(class_indices)
        meta_attrs = constr_vars(meta_indices)
        domain = Domain(attrs, classes, meta_attrs)
        return Table.from_numpy(
            domain, attrs and X, classes and Y, metas and meta_attrs)
コード例 #6
0
ファイル: io.py プロジェクト: Micseb/orange3
    def read_file(cls, filename, storage_class=None):
        if storage_class is None:
            from ..data import Table as storage_class
        def constr_vars(inds):
            if inds:
                return [ContinuousVariable(x.decode("utf-8")) for _, x in
                        sorted((ind, name) for name, ind in inds.items())]

        X, Y, metas, attr_indices, class_indices, meta_indices = \
            _io.sparse_read_float(filename.encode(sys.getdefaultencoding()))

        attrs = constr_vars(attr_indices)
        classes = constr_vars(class_indices)
        meta_attrs = constr_vars(meta_indices)
        domain = Domain(attrs, classes, meta_attrs)
        return storage_class.from_numpy(
            domain, attrs and X, classes and Y, metas and meta_attrs)
コード例 #7
0
    def read_file(cls, filename, storage_class=None):
        if storage_class is None:
            from ..data import Table as storage_class

        def constr_vars(inds):
            if inds:
                return [
                    ContinuousVariable(x.decode("utf-8")) for _, x in sorted(
                        (ind, name) for name, ind in inds.items())
                ]

        X, Y, metas, attr_indices, class_indices, meta_indices = \
            _io.sparse_read_float(filename.encode(sys.getdefaultencoding()))

        attrs = constr_vars(attr_indices)
        classes = constr_vars(class_indices)
        meta_attrs = constr_vars(meta_indices)
        domain = Domain(attrs, classes, meta_attrs)
        return storage_class.from_numpy(domain, attrs and X, classes and Y,
                                        metas and meta_attrs)