def _check_input_fit(self, X, is_categories=False): """Helper function to check input of fit within the multi-gpu model""" if isinstance(X, (dask.array.core.Array, cp.ndarray)): self._set_input_type('array') if is_categories: X = X.transpose() if isinstance(X, cp.ndarray): return DataFrame.from_gpu_matrix(X) else: return to_dask_cudf(X, client=self.client) else: self._set_input_type('df') return X
def to_output(self, output_type='cupy'): """ Convert array to output format Parameters ---------- output_type : string Format to convert the array to. Acceptable formats are: 'cupy' - to cupy array 'numpy' - to numpy (host) array 'numba' - to numba device array 'dataframe' - to cuDF DataFrame 'series' - to cuDF Series 'cudf' - to cuDF Series if array is single dimensional, to DataFrame otherwise """ # check to translate cudf to actual type converted if output_type == 'cudf': if len(self.shape) == 1: output_type = 'series' elif self.shape[1] == 1: output_type = 'series' else: output_type = 'dataframe' if output_type == 'cupy': return cp.asarray(self) elif output_type == 'numba': return cuda.as_cuda_array(self) elif output_type == 'numpy': return cp.asnumpy(cp.asarray(self), order=self.order) elif output_type == 'dataframe': if self.dtype not in [np.uint8, np.uint16, np.uint32, np.uint64, np.float16]: mat = cuda.as_cuda_array(self) if len(mat.shape) == 1: mat = mat.reshape(mat.shape[0], 1) return DataFrame.from_gpu_matrix(mat) else: raise ValueError('cuDF unsupported Array dtype') elif output_type == 'series': # check needed in case output_type was passed as 'series' # directly instead of as 'cudf' if len(self.shape) == 1: if self.dtype not in [np.uint8, np.uint16, np.uint32, np.uint64, np.float16]: return Series(self, dtype=self.dtype) else: raise ValueError('cuDF unsupported Array dtype') elif self.shape[1] > 1: raise ValueError('Only single dimensional arrays can be \ transformed to cuDF Series. ') else: if self.dtype not in [np.uint8, np.uint16, np.uint32, np.uint64, np.float16]: return Series(self, dtype=self.dtype) else: raise ValueError('cuDF unsupported Array dtype')