Eager 执行#

备注

自 0.2.0a2 起支持

Mars 支持 Eager 模式以方便开发和调试。

用户可以通过选项启用 Eager 模式,在程序开头或控制台会话中设置选项。

>>> from mars.config import options
>>> options.eager_mode = True

或者使用上下文。

>>> from mars.config import option_context

>>> with option_context() as options:
>>>     options.eager_mode = True
>>>     # the eager mode is on only for the with statement
>>>     ...

如果打开了 Eager 模式,则会在创建默认会话后立即执行 tensor 和 DataFrame 等等。

>>> import mars.tensor as mt
>>> import mars.dataframe as md
>>> from mars.config import options
>>> options.eager_mode = True
>>> t = mt.arange(6).reshape(2, 3)
>>> t
array([[0, 1, 2],
       [3, 4, 5]])
>>> df = md.DataFrame(t)
>>> df.sum()
0    3
1    5
2    7
dtype: int64