當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python cuml.common.memory_utils.using_output_type用法及代碼示例

用法:

cuml.common.memory_utils.using_output_type(output_type)

with 語句中設置 cuML 的全局輸出類型的上下文管理器方法。一旦with 代碼塊被執行,它就會重置為之前的值。

參數

output_type{‘input’, ‘cudf’, ‘cupy’, ‘numpy’}(默認 = ‘input’)

期望的結果輸出類型和估計器的屬性。

  • 'input' 意味著參數和方法將盡可能地鏡像發送到估計器/方法的數據格式。具體來說:

    輸入類型

    輸出類型

    cuDF DataFrame 或係列

    cuDF DataFrame 或係列

    NumPy 數組

    NumPy 數組

    Pandas DataFrame 或係列

    NumPy 數組

    Numba 設備陣列

    Numba 設備陣列

    CuPy 數組

    CuPy 數組

    其他 __cuda_array_interface__ 對象

    CuPy 數組

  • 'cudf' 將為單維結果返回 cuDF 係列,為其餘結果返回 DataFrames。

  • 'cupy' 將返回 CuPy 數組。

  • 'numpy' 將返回 NumPy 數組。

例子

import cuml
import cupy as cp

ary = [[1.0, 4.0, 4.0], [2.0, 2.0, 2.0], [5.0, 1.0, 1.0]]
ary = cp.asarray(ary)

with cuml.using_output_type('cudf'):
    dbscan_float = cuml.DBSCAN(eps=1.0, min_samples=1)
    dbscan_float.fit(ary)

    print("cuML output inside 'with' context")
    print(dbscan_float.labels_)
    print(type(dbscan_float.labels_))

# use cuml again outside the context manager
dbscan_float2 = cuml.DBSCAN(eps=1.0, min_samples=1)
dbscan_float2.fit(ary)

print("cuML default output")
print(dbscan_float2.labels_)
print(type(dbscan_float2.labels_))

輸出:

cuML output inside 'with' context
0    0
1    1
2    2
dtype: int32
<class 'cudf.core.series.Series'>

cuML default output
[0 1 2]
<class 'cupy.ndarray'>

相關用法


注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cuml.common.memory_utils.using_output_type。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。