(cls, domain, source, row_indices=...)
Create a new table from selected columns and/or rows of an existing
        one. The columns are chosen using a domain. The domain may also include
        variables that do not appear in the source table; they are computed
        from source variables if possible.

        The resulting data may be a view or a copy of the existing data.

        :param domain: the domain for the new table
        :type domain: Orange.data.Domain
        :param source: the source table
        :type source: Orange.data.Table
        :param row_indices: indices of the rows to include
        :type row_indices: a slice or a sequence
        :return: a new table
        :rtype: Orange.data.Table
Create a new table from selected columns and/or rows of an existing
        one. The columns are chosen using a domain. The domain may also include
        variables that do not appear in the source table; they are computed
        from source variables if possible.
Create a new table from selected columns and / or rows of an existing one . The columns are chosen using a domain . The domain may also include variables that do not appear in the source table ; they are computed from source variables if possible .
def from_table(cls, domain, source, row_indices=...):
        """
        Create a new table from selected columns and/or rows of an existing
        one. The columns are chosen using a domain. The domain may also include
        variables that do not appear in the source table; they are computed
        from source variables if possible.

        The resulting data may be a view or a copy of the existing data.

        :param domain: the domain for the new table
        :type domain: Orange.data.Domain
        :param source: the source table
        :type source: Orange.data.Table
        :param row_indices: indices of the rows to include
        :type row_indices: a slice or a sequence
        :return: a new table
        :rtype: Orange.data.Table
        """

        PART = 5000

        new_cache = _thread_local.conversion_cache is None
        try:
            if new_cache:
                _thread_local.conversion_cache = {}
                _thread_local.domain_cache = {}
            else:
                cached = _idcache_restore(_thread_local.conversion_cache, (domain, source))
                if cached is not None:
                    return cached
            if domain is source.domain:
                table = cls.from_table_rows(source, row_indices)
                # assure resulting domain is the instance passed on input
                table.domain = domain
                # since sparse flags are not considered when checking for
                # domain equality, fix manually.
                with table.unlocked_reference():
                    table = assure_domain_conversion_sparsity(table, source)
                return table

            if row_indices is ...:
                n_rows = len(source)
            elif isinstance(row_indices, slice):
                row_indices_range = range(*row_indices.indices(source.X.shape[0]))
                n_rows = len(row_indices_range)
            else:
                n_rows = len(row_indices)

            self = cls()
            self.domain = domain

            table_conversion = \
                _idcache_restore(_thread_local.domain_cache, (domain, source.domain))
            if table_conversion is None:
                table_conversion = _FromTableConversion(source.domain, domain)
                _idcache_save(_thread_local.domain_cache, (domain, source.domain),
                              table_conversion)

            # if an array can be a subarray of the input table, this needs to be done
            # on the whole table, because this avoids needless copies of contents

            with self.unlocked_reference():
                for array_conv in table_conversion.subarray:
                    out = array_conv.get_subarray(source, row_indices, n_rows)
                    setattr(self, array_conv.target, out)

                parts = {}

                for array_conv in table_conversion.columnwise:
                    if array_conv.is_sparse:
                        parts[array_conv.target] = []
                    else:
                        # F-order enables faster writing to the array while accessing and
                        # matrix operations work with same speed (e.g. dot)
                        parts[array_conv.target] = \
                            np.zeros((n_rows, len(array_conv.src_cols)),
                                     order="F", dtype=array_conv.dtype)

                if n_rows <= PART:
                    for array_conv in table_conversion.columnwise:
                        out = array_conv.get_columns(source, row_indices, n_rows,
                                                     parts[array_conv.target],
                                                     ...)
                        setattr(self, array_conv.target, out)
                else:
                    i_done = 0

                    while i_done < n_rows:
                        target_indices = slice(i_done, min(n_rows, i_done + PART))
                        if row_indices is ...:
                            source_indices = target_indices
                        elif isinstance(row_indices, slice):
                            r = row_indices_range[target_indices]
                            source_indices = slice(r.start, r.stop, r.step)
                        else:
                            source_indices = row_indices[target_indices]
                        part_rows = min(n_rows, i_done+PART) - i_done

                        for array_conv in table_conversion.columnwise:
                            out = array_conv.get_columns(source, source_indices, part_rows,
                                                         parts[array_conv.target],
                                                         target_indices)
                            if array_conv.is_sparse:  # dense arrays are populated in-place
                                parts[array_conv.target].append(out)

                        i_done += PART

                        # clear cache after a part is done
                        if new_cache:
                            _thread_local.conversion_cache = {}

                    for array_conv in table_conversion.columnwise:
                        cparts = parts[array_conv.target]
                        out = cparts if not array_conv.is_sparse else sp.vstack(cparts)
                        setattr(self, array_conv.target, out)

                if source.has_weights():
                    self.W = source.W[row_indices]
                else:
                    self.W = np.empty((n_rows, 0))
                self.name = getattr(source, 'name', '')
                if hasattr(source, 'ids'):
                    self.ids = source.ids[row_indices]
                else:
                    cls._init_ids(self)
                self.attributes = getattr(source, 'attributes', {})
                _idcache_save(_thread_local.conversion_cache, (domain, source), self)
            return self
        finally:
            if new_cache:
                _thread_local.conversion_cache = None
                _thread_local.domain_cache = None
def from_table ( cls , domain , source , row_indices = ... ) : PART = 5000 new_cache = _thread_local . conversion_cache is None try : if new_cache : _thread_local . conversion_cache = { } _thread_local . domain_cache = { } else : cached = _idcache_restore ( _thread_local . conversion_cache , ( domain , source ) ) if cached is not None : return cached if domain is source . domain : table = cls . from_table_rows ( source , row_indices ) # assure resulting domain is the instance passed on input table . domain = domain # since sparse flags are not considered when checking for # domain equality, fix manually. with table . unlocked_reference ( ) : table = assure_domain_conversion_sparsity ( table , source ) return table if row_indices is ... : n_rows = len ( source ) elif isinstance ( row_indices , slice ) : row_indices_range = range ( * row_indices . indices ( source . X . shape [ 0 ] ) ) n_rows = len ( row_indices_range ) else : n_rows = len ( row_indices ) self = cls ( ) self . domain = domain table_conversion = _idcache_restore ( _thread_local . domain_cache , ( domain , source . domain ) ) if table_conversion is None : table_conversion = _FromTableConversion ( source . domain , domain ) _idcache_save ( _thread_local . domain_cache , ( domain , source . domain ) , table_conversion ) # if an array can be a subarray of the input table, this needs to be done # on the whole table, because this avoids needless copies of contents with self . unlocked_reference ( ) : for array_conv in table_conversion . subarray : out = array_conv . get_subarray ( source , row_indices , n_rows ) setattr ( self , array_conv . target , out ) parts = { } for array_conv in table_conversion . columnwise : if array_conv . is_sparse : parts [ array_conv . target ] = [ ] else : # F-order enables faster writing to the array while accessing and # matrix operations work with same speed (e.g. dot) parts [ array_conv . target ] = np . zeros ( ( n_rows , len ( array_conv . src_cols ) ) , order = "F" , dtype = array_conv . dtype ) if n_rows <= PART : for array_conv in table_conversion . columnwise : out = array_conv . get_columns ( source , row_indices , n_rows , parts [ array_conv . target ] , ... ) setattr ( self , array_conv . target , out ) else : i_done = 0 while i_done < n_rows : target_indices = slice ( i_done , min ( n_rows , i_done + PART ) ) if row_indices is ... : source_indices = target_indices elif isinstance ( row_indices , slice ) : r = row_indices_range [ target_indices ] source_indices = slice ( r . start , r . stop , r . step ) else : source_indices = row_indices [ target_indices ] part_rows = min ( n_rows , i_done + PART ) - i_done for array_conv in table_conversion . columnwise : out = array_conv . get_columns ( source , source_indices , part_rows , parts [ array_conv . target ] , target_indices ) if array_conv . is_sparse : # dense arrays are populated in-place parts [ array_conv . target ] . append ( out ) i_done += PART # clear cache after a part is done if new_cache : _thread_local . conversion_cache = { } for array_conv in table_conversion . columnwise : cparts = parts [ array_conv . target ] out = cparts if not array_conv . is_sparse else sp . vstack ( cparts ) setattr ( self , array_conv . target , out ) if source . has_weights ( ) : self . W = source . W [ row_indices ] else : self . W = np . empty ( ( n_rows , 0 ) ) self . name = getattr ( source , 'name' , '' ) if hasattr ( source , 'ids' ) : self . ids = source . ids [ row_indices ] else : cls . _init_ids ( self ) self . attributes = getattr ( source , 'attributes' , { } ) _idcache_save ( _thread_local . conversion_cache , ( domain , source ) , self ) return self finally : if new_cache : _thread_local . conversion_cache = None _thread_local . domain_cache = None