maxframe 0.1.0b5__cp39-cp39-macosx_10_9_universal2.whl → 1.0.0__cp39-cp39-macosx_10_9_universal2.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of maxframe might be problematic. Click here for more details.
- maxframe/_utils.cpython-39-darwin.so +0 -0
- maxframe/codegen.py +10 -4
- maxframe/config/config.py +68 -10
- maxframe/config/validators.py +42 -11
- maxframe/conftest.py +58 -14
- maxframe/core/__init__.py +2 -16
- maxframe/core/entity/__init__.py +1 -12
- maxframe/core/entity/executable.py +1 -1
- maxframe/core/entity/objects.py +46 -45
- maxframe/core/entity/output_types.py +0 -3
- maxframe/core/entity/tests/test_objects.py +43 -0
- maxframe/core/entity/tileables.py +5 -78
- maxframe/core/graph/__init__.py +2 -2
- maxframe/core/graph/builder/__init__.py +0 -1
- maxframe/core/graph/builder/base.py +5 -4
- maxframe/core/graph/builder/tileable.py +4 -4
- maxframe/core/graph/builder/utils.py +4 -8
- maxframe/core/graph/core.cpython-39-darwin.so +0 -0
- maxframe/core/graph/core.pyx +4 -4
- maxframe/core/graph/entity.py +9 -33
- maxframe/core/operator/__init__.py +2 -9
- maxframe/core/operator/base.py +3 -5
- maxframe/core/operator/objects.py +0 -9
- maxframe/core/operator/utils.py +55 -0
- maxframe/dataframe/__init__.py +1 -1
- maxframe/dataframe/arithmetic/around.py +5 -17
- maxframe/dataframe/arithmetic/core.py +15 -7
- maxframe/dataframe/arithmetic/docstring.py +7 -33
- maxframe/dataframe/arithmetic/equal.py +4 -2
- maxframe/dataframe/arithmetic/greater.py +4 -2
- maxframe/dataframe/arithmetic/greater_equal.py +4 -2
- maxframe/dataframe/arithmetic/less.py +2 -2
- maxframe/dataframe/arithmetic/less_equal.py +4 -2
- maxframe/dataframe/arithmetic/not_equal.py +4 -2
- maxframe/dataframe/arithmetic/tests/test_arithmetic.py +39 -16
- maxframe/dataframe/core.py +31 -7
- maxframe/dataframe/datasource/date_range.py +2 -2
- maxframe/dataframe/datasource/read_odps_query.py +117 -23
- maxframe/dataframe/datasource/read_odps_table.py +6 -3
- maxframe/dataframe/datasource/tests/test_datasource.py +103 -8
- maxframe/dataframe/datastore/tests/test_to_odps.py +48 -0
- maxframe/dataframe/datastore/to_odps.py +28 -0
- maxframe/dataframe/extensions/__init__.py +5 -0
- maxframe/dataframe/extensions/flatjson.py +131 -0
- maxframe/dataframe/extensions/flatmap.py +317 -0
- maxframe/dataframe/extensions/reshuffle.py +1 -1
- maxframe/dataframe/extensions/tests/test_extensions.py +108 -3
- maxframe/dataframe/groupby/core.py +1 -1
- maxframe/dataframe/groupby/cum.py +0 -1
- maxframe/dataframe/groupby/fill.py +4 -1
- maxframe/dataframe/groupby/getitem.py +6 -0
- maxframe/dataframe/groupby/tests/test_groupby.py +5 -1
- maxframe/dataframe/groupby/transform.py +5 -1
- maxframe/dataframe/indexing/align.py +1 -1
- maxframe/dataframe/indexing/loc.py +6 -4
- maxframe/dataframe/indexing/rename.py +5 -28
- maxframe/dataframe/indexing/sample.py +0 -1
- maxframe/dataframe/indexing/set_index.py +68 -1
- maxframe/dataframe/initializer.py +11 -1
- maxframe/dataframe/merge/__init__.py +9 -1
- maxframe/dataframe/merge/concat.py +41 -31
- maxframe/dataframe/merge/merge.py +237 -3
- maxframe/dataframe/merge/tests/test_merge.py +126 -1
- maxframe/dataframe/misc/apply.py +5 -10
- maxframe/dataframe/misc/case_when.py +1 -1
- maxframe/dataframe/misc/describe.py +2 -2
- maxframe/dataframe/misc/drop_duplicates.py +8 -8
- maxframe/dataframe/misc/eval.py +4 -0
- maxframe/dataframe/misc/memory_usage.py +2 -2
- maxframe/dataframe/misc/pct_change.py +1 -83
- maxframe/dataframe/misc/tests/test_misc.py +33 -2
- maxframe/dataframe/misc/transform.py +1 -30
- maxframe/dataframe/misc/value_counts.py +4 -17
- maxframe/dataframe/missing/dropna.py +1 -1
- maxframe/dataframe/missing/fillna.py +5 -5
- maxframe/dataframe/operators.py +1 -17
- maxframe/dataframe/reduction/core.py +2 -2
- maxframe/dataframe/reduction/tests/test_reduction.py +2 -4
- maxframe/dataframe/sort/sort_values.py +1 -11
- maxframe/dataframe/statistics/corr.py +3 -3
- maxframe/dataframe/statistics/quantile.py +13 -19
- maxframe/dataframe/statistics/tests/test_statistics.py +4 -4
- maxframe/dataframe/tests/test_initializer.py +33 -2
- maxframe/dataframe/utils.py +26 -11
- maxframe/dataframe/window/expanding.py +5 -3
- maxframe/dataframe/window/tests/test_expanding.py +2 -2
- maxframe/errors.py +13 -0
- maxframe/extension.py +12 -0
- maxframe/io/__init__.py +13 -0
- maxframe/io/objects/__init__.py +24 -0
- maxframe/io/objects/core.py +140 -0
- maxframe/io/objects/tensor.py +76 -0
- maxframe/io/objects/tests/__init__.py +13 -0
- maxframe/io/objects/tests/test_object_io.py +97 -0
- maxframe/{odpsio → io/odpsio}/__init__.py +3 -1
- maxframe/{odpsio → io/odpsio}/arrow.py +42 -10
- maxframe/{odpsio → io/odpsio}/schema.py +38 -16
- maxframe/io/odpsio/tableio.py +719 -0
- maxframe/io/odpsio/tests/__init__.py +13 -0
- maxframe/{odpsio → io/odpsio}/tests/test_schema.py +59 -22
- maxframe/{odpsio → io/odpsio}/tests/test_tableio.py +50 -23
- maxframe/{odpsio → io/odpsio}/tests/test_volumeio.py +4 -6
- maxframe/io/odpsio/volumeio.py +63 -0
- maxframe/learn/contrib/__init__.py +3 -1
- maxframe/learn/contrib/graph/__init__.py +15 -0
- maxframe/learn/contrib/graph/connected_components.py +215 -0
- maxframe/learn/contrib/graph/tests/__init__.py +13 -0
- maxframe/learn/contrib/graph/tests/test_connected_components.py +53 -0
- maxframe/learn/contrib/llm/__init__.py +16 -0
- maxframe/learn/contrib/llm/core.py +54 -0
- maxframe/learn/contrib/llm/models/__init__.py +14 -0
- maxframe/learn/contrib/llm/models/dashscope.py +73 -0
- maxframe/learn/contrib/llm/multi_modal.py +42 -0
- maxframe/learn/contrib/llm/text.py +42 -0
- maxframe/learn/contrib/xgboost/classifier.py +26 -2
- maxframe/learn/contrib/xgboost/core.py +87 -2
- maxframe/learn/contrib/xgboost/dmatrix.py +3 -6
- maxframe/learn/contrib/xgboost/predict.py +29 -46
- maxframe/learn/contrib/xgboost/regressor.py +3 -10
- maxframe/learn/contrib/xgboost/train.py +29 -18
- maxframe/{core/operator/fuse.py → learn/core.py} +7 -10
- maxframe/lib/mmh3.cpython-39-darwin.so +0 -0
- maxframe/lib/mmh3.pyi +43 -0
- maxframe/lib/sparse/tests/test_sparse.py +15 -15
- maxframe/lib/wrapped_pickle.py +2 -1
- maxframe/opcodes.py +8 -0
- maxframe/protocol.py +154 -27
- maxframe/remote/core.py +4 -8
- maxframe/serialization/__init__.py +1 -0
- maxframe/serialization/core.cpython-39-darwin.so +0 -0
- maxframe/serialization/core.pxd +3 -0
- maxframe/serialization/core.pyi +3 -0
- maxframe/serialization/core.pyx +67 -26
- maxframe/serialization/exception.py +1 -1
- maxframe/serialization/pandas.py +52 -17
- maxframe/serialization/serializables/core.py +180 -15
- maxframe/serialization/serializables/field_type.py +4 -1
- maxframe/serialization/serializables/tests/test_serializable.py +54 -5
- maxframe/serialization/tests/test_serial.py +2 -1
- maxframe/session.py +9 -2
- maxframe/tensor/__init__.py +81 -2
- maxframe/tensor/arithmetic/isclose.py +1 -0
- maxframe/tensor/arithmetic/tests/test_arithmetic.py +22 -18
- maxframe/tensor/core.py +5 -136
- maxframe/tensor/datasource/array.py +3 -0
- maxframe/tensor/datasource/full.py +1 -1
- maxframe/tensor/datasource/tests/test_datasource.py +1 -1
- maxframe/tensor/indexing/flatnonzero.py +1 -1
- maxframe/tensor/indexing/getitem.py +2 -0
- maxframe/tensor/merge/__init__.py +2 -0
- maxframe/tensor/merge/concatenate.py +101 -0
- maxframe/tensor/merge/tests/test_merge.py +30 -1
- maxframe/tensor/merge/vstack.py +74 -0
- maxframe/tensor/{base → misc}/__init__.py +2 -0
- maxframe/tensor/{base → misc}/atleast_1d.py +1 -3
- maxframe/tensor/misc/atleast_2d.py +70 -0
- maxframe/tensor/misc/atleast_3d.py +85 -0
- maxframe/tensor/misc/tests/__init__.py +13 -0
- maxframe/tensor/{base → misc}/transpose.py +22 -18
- maxframe/tensor/{base → misc}/unique.py +3 -3
- maxframe/tensor/operators.py +1 -7
- maxframe/tensor/random/core.py +1 -1
- maxframe/tensor/reduction/count_nonzero.py +2 -1
- maxframe/tensor/reduction/mean.py +1 -0
- maxframe/tensor/reduction/nanmean.py +1 -0
- maxframe/tensor/reduction/nanvar.py +2 -0
- maxframe/tensor/reduction/tests/test_reduction.py +12 -1
- maxframe/tensor/reduction/var.py +2 -0
- maxframe/tensor/statistics/quantile.py +2 -2
- maxframe/tensor/utils.py +2 -22
- maxframe/tests/test_protocol.py +34 -0
- maxframe/tests/test_utils.py +0 -12
- maxframe/tests/utils.py +17 -2
- maxframe/typing_.py +4 -1
- maxframe/udf.py +8 -9
- maxframe/utils.py +106 -86
- {maxframe-0.1.0b5.dist-info → maxframe-1.0.0.dist-info}/METADATA +25 -25
- {maxframe-0.1.0b5.dist-info → maxframe-1.0.0.dist-info}/RECORD +197 -173
- {maxframe-0.1.0b5.dist-info → maxframe-1.0.0.dist-info}/WHEEL +1 -1
- maxframe_client/__init__.py +0 -1
- maxframe_client/clients/framedriver.py +4 -1
- maxframe_client/fetcher.py +81 -74
- maxframe_client/session/consts.py +3 -0
- maxframe_client/session/graph.py +8 -2
- maxframe_client/session/odps.py +194 -40
- maxframe_client/session/task.py +94 -39
- maxframe_client/tests/test_fetcher.py +21 -3
- maxframe_client/tests/test_session.py +109 -8
- maxframe/core/entity/chunks.py +0 -68
- maxframe/core/entity/fuse.py +0 -73
- maxframe/core/graph/builder/chunk.py +0 -430
- maxframe/odpsio/tableio.py +0 -322
- maxframe/odpsio/volumeio.py +0 -95
- maxframe_client/clients/spe.py +0 -104
- /maxframe/{odpsio → core/entity}/tests/__init__.py +0 -0
- /maxframe/{tensor/base → dataframe/datastore}/tests/__init__.py +0 -0
- /maxframe/{odpsio → io/odpsio}/tests/test_arrow.py +0 -0
- /maxframe/tensor/{base → misc}/astype.py +0 -0
- /maxframe/tensor/{base → misc}/broadcast_to.py +0 -0
- /maxframe/tensor/{base → misc}/ravel.py +0 -0
- /maxframe/tensor/{base/tests/test_base.py → misc/tests/test_misc.py} +0 -0
- /maxframe/tensor/{base → misc}/where.py +0 -0
- {maxframe-0.1.0b5.dist-info → maxframe-1.0.0.dist-info}/top_level.txt +0 -0
|
@@ -18,7 +18,36 @@ import numpy as np
|
|
|
18
18
|
import pytest
|
|
19
19
|
|
|
20
20
|
from ...datasource import empty, ones
|
|
21
|
-
from .. import stack
|
|
21
|
+
from .. import concatenate, stack
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_concatenate():
|
|
25
|
+
a = ones((10, 20, 30), chunk_size=10)
|
|
26
|
+
b = ones((20, 20, 30), chunk_size=20)
|
|
27
|
+
|
|
28
|
+
c = concatenate([a, b])
|
|
29
|
+
assert c.shape == (30, 20, 30)
|
|
30
|
+
|
|
31
|
+
a = ones((10, 20, 30), chunk_size=10)
|
|
32
|
+
b = ones((10, 20, 40), chunk_size=20)
|
|
33
|
+
|
|
34
|
+
c = concatenate([a, b], axis=-1)
|
|
35
|
+
assert c.shape == (10, 20, 70)
|
|
36
|
+
|
|
37
|
+
with pytest.raises(ValueError):
|
|
38
|
+
a = ones((10, 20, 30), chunk_size=10)
|
|
39
|
+
b = ones((20, 30, 30), chunk_size=20)
|
|
40
|
+
|
|
41
|
+
concatenate([a, b])
|
|
42
|
+
|
|
43
|
+
with pytest.raises(ValueError):
|
|
44
|
+
a = ones((10, 20, 30), chunk_size=10)
|
|
45
|
+
b = ones((20, 20), chunk_size=20)
|
|
46
|
+
|
|
47
|
+
concatenate([a, b])
|
|
48
|
+
|
|
49
|
+
a = ones((10, 20, 30), chunk_size=5)
|
|
50
|
+
b = ones((20, 20, 30), chunk_size=10)
|
|
22
51
|
|
|
23
52
|
|
|
24
53
|
def test_stack():
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Copyright 1999-2024 Alibaba Group Holding Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from ..misc import atleast_2d
|
|
17
|
+
from .concatenate import _concatenate, concatenate
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def vstack(tup):
|
|
21
|
+
"""
|
|
22
|
+
Stack tensors in sequence vertically (row wise).
|
|
23
|
+
|
|
24
|
+
This is equivalent to concatenation along the first axis after 1-D tensors
|
|
25
|
+
of shape `(N,)` have been reshaped to `(1,N)`. Rebuilds tensors divided by
|
|
26
|
+
`vsplit`.
|
|
27
|
+
|
|
28
|
+
This function makes most sense for tensors with up to 3 dimensions. For
|
|
29
|
+
instance, for pixel-data with a height (first axis), width (second axis),
|
|
30
|
+
and r/g/b channels (third axis). The functions `concatenate`, `stack` and
|
|
31
|
+
`block` provide more general stacking and concatenation operations.
|
|
32
|
+
|
|
33
|
+
Parameters
|
|
34
|
+
----------
|
|
35
|
+
tup : sequence of tensors
|
|
36
|
+
The tensors must have the same shape along all but the first axis.
|
|
37
|
+
1-D tensors must have the same length.
|
|
38
|
+
|
|
39
|
+
Returns
|
|
40
|
+
-------
|
|
41
|
+
stacked : Tensor
|
|
42
|
+
The tensor formed by stacking the given tensors, will be at least 2-D.
|
|
43
|
+
|
|
44
|
+
See Also
|
|
45
|
+
--------
|
|
46
|
+
stack : Join a sequence of tensors along a new axis.
|
|
47
|
+
concatenate : Join a sequence of tensors along an existing axis.
|
|
48
|
+
|
|
49
|
+
Examples
|
|
50
|
+
--------
|
|
51
|
+
>>> import mars.tensor as mt
|
|
52
|
+
|
|
53
|
+
>>> a = mt.array([1, 2, 3])
|
|
54
|
+
>>> b = mt.array([2, 3, 4])
|
|
55
|
+
>>> mt.vstack((a,b)).execute()
|
|
56
|
+
array([[1, 2, 3],
|
|
57
|
+
[2, 3, 4]])
|
|
58
|
+
|
|
59
|
+
>>> a = mt.array([[1], [2], [3]])
|
|
60
|
+
>>> b = mt.array([[2], [3], [4]])
|
|
61
|
+
>>> mt.vstack((a,b)).execute()
|
|
62
|
+
array([[1],
|
|
63
|
+
[2],
|
|
64
|
+
[3],
|
|
65
|
+
[2],
|
|
66
|
+
[3],
|
|
67
|
+
[4]])
|
|
68
|
+
|
|
69
|
+
"""
|
|
70
|
+
return concatenate([atleast_2d(t) for t in tup], axis=0)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _vstack(tup):
|
|
74
|
+
return _concatenate([atleast_2d(t) for t in tup], axis=0)
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
from .astype import TensorAstype
|
|
16
16
|
from .atleast_1d import atleast_1d
|
|
17
|
+
from .atleast_2d import atleast_2d
|
|
18
|
+
from .atleast_3d import atleast_3d
|
|
17
19
|
from .broadcast_to import TensorBroadcastTo, broadcast_to
|
|
18
20
|
from .ravel import ravel
|
|
19
21
|
from .transpose import transpose
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# Copyright 1999-2021 Alibaba Group Holding Ltd.
|
|
1
|
+
# Copyright 1999-2024 Alibaba Group Holding Ltd.
|
|
4
2
|
#
|
|
5
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Copyright 1999-2024 Alibaba Group Holding Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import numpy as np
|
|
16
|
+
|
|
17
|
+
from ...core import ExecutableTuple
|
|
18
|
+
from ..datasource import tensor as astensor
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def atleast_2d(*tensors):
|
|
22
|
+
"""
|
|
23
|
+
View inputs as tensors with at least two dimensions.
|
|
24
|
+
|
|
25
|
+
Parameters
|
|
26
|
+
----------
|
|
27
|
+
tensors1, tensors2, ... : array_like
|
|
28
|
+
One or more array-like sequences. Non-tensor inputs are converted
|
|
29
|
+
to tensors. Tensors that already have two or more dimensions are
|
|
30
|
+
preserved.
|
|
31
|
+
|
|
32
|
+
Returns
|
|
33
|
+
-------
|
|
34
|
+
res, res2, ... : Tensor
|
|
35
|
+
A tensor, or list of tensors, each with ``a.ndim >= 2``.
|
|
36
|
+
Copies are avoided where possible, and views with two or more
|
|
37
|
+
dimensions are returned.
|
|
38
|
+
|
|
39
|
+
See Also
|
|
40
|
+
--------
|
|
41
|
+
atleast_1d, atleast_3d
|
|
42
|
+
|
|
43
|
+
Examples
|
|
44
|
+
--------
|
|
45
|
+
>>> import maxframe.tensor as mt
|
|
46
|
+
|
|
47
|
+
>>> mt.atleast_2d(3.0).execute()
|
|
48
|
+
array([[ 3.]])
|
|
49
|
+
|
|
50
|
+
>>> x = mt.arange(3.0)
|
|
51
|
+
>>> mt.atleast_2d(x).execute()
|
|
52
|
+
array([[ 0., 1., 2.]])
|
|
53
|
+
|
|
54
|
+
>>> mt.atleast_2d(1, [1, 2], [[1, 2]]).execute()
|
|
55
|
+
[array([[1]]), array([[1, 2]]), array([[1, 2]])]
|
|
56
|
+
|
|
57
|
+
"""
|
|
58
|
+
new_tensors = []
|
|
59
|
+
for x in tensors:
|
|
60
|
+
x = astensor(x)
|
|
61
|
+
if x.ndim == 0:
|
|
62
|
+
x = x[np.newaxis, np.newaxis]
|
|
63
|
+
elif x.ndim == 1:
|
|
64
|
+
x = x[np.newaxis, :]
|
|
65
|
+
|
|
66
|
+
new_tensors.append(x)
|
|
67
|
+
|
|
68
|
+
if len(new_tensors) == 1:
|
|
69
|
+
return new_tensors[0]
|
|
70
|
+
return ExecutableTuple(new_tensors)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Copyright 1999-2024 Alibaba Group Holding Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
import numpy as np
|
|
17
|
+
|
|
18
|
+
from ...core import ExecutableTuple
|
|
19
|
+
from ..datasource import tensor as astensor
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def atleast_3d(*tensors):
|
|
23
|
+
"""
|
|
24
|
+
View inputs as tensors with at least three dimensions.
|
|
25
|
+
|
|
26
|
+
Parameters
|
|
27
|
+
----------
|
|
28
|
+
tensors1, tensors2, ... : array_like
|
|
29
|
+
One or more tensor-like sequences. Non-tensor inputs are converted to
|
|
30
|
+
tensors. Tensors that already have three or more dimensions are
|
|
31
|
+
preserved.
|
|
32
|
+
|
|
33
|
+
Returns
|
|
34
|
+
-------
|
|
35
|
+
res1, res2, ... : Tensor
|
|
36
|
+
A tensor, or list of tensors, each with ``a.ndim >= 3``. Copies are
|
|
37
|
+
avoided where possible, and views with three or more dimensions are
|
|
38
|
+
returned. For example, a 1-D tensor of shape ``(N,)`` becomes a view
|
|
39
|
+
of shape ``(1, N, 1)``, and a 2-D tensor of shape ``(M, N)`` becomes a
|
|
40
|
+
view of shape ``(M, N, 1)``.
|
|
41
|
+
|
|
42
|
+
See Also
|
|
43
|
+
--------
|
|
44
|
+
atleast_1d, atleast_2d
|
|
45
|
+
|
|
46
|
+
Examples
|
|
47
|
+
--------
|
|
48
|
+
>>> import maxframe.tensor as mt
|
|
49
|
+
|
|
50
|
+
>>> mt.atleast_3d(3.0).execute()
|
|
51
|
+
array([[[ 3.]]])
|
|
52
|
+
|
|
53
|
+
>>> x = mt.arange(3.0)
|
|
54
|
+
>>> mt.atleast_3d(x).shape
|
|
55
|
+
(1, 3, 1)
|
|
56
|
+
|
|
57
|
+
>>> x = mt.arange(12.0).reshape(4,3)
|
|
58
|
+
>>> mt.atleast_3d(x).shape
|
|
59
|
+
(4, 3, 1)
|
|
60
|
+
|
|
61
|
+
>>> for arr in mt.atleast_3d([1, 2], [[1, 2]], [[[1, 2]]]).execute():
|
|
62
|
+
... print(arr, arr.shape)
|
|
63
|
+
...
|
|
64
|
+
[[[1]
|
|
65
|
+
[2]]] (1, 2, 1)
|
|
66
|
+
[[[1]
|
|
67
|
+
[2]]] (1, 2, 1)
|
|
68
|
+
[[[1 2]]] (1, 1, 2)
|
|
69
|
+
|
|
70
|
+
"""
|
|
71
|
+
new_tensors = []
|
|
72
|
+
for x in tensors:
|
|
73
|
+
x = astensor(x)
|
|
74
|
+
if x.ndim == 0:
|
|
75
|
+
x = x[np.newaxis, np.newaxis, np.newaxis]
|
|
76
|
+
elif x.ndim == 1:
|
|
77
|
+
x = x[np.newaxis, :, np.newaxis]
|
|
78
|
+
elif x.ndim == 2:
|
|
79
|
+
x = x[:, :, None]
|
|
80
|
+
|
|
81
|
+
new_tensors.append(x)
|
|
82
|
+
|
|
83
|
+
if len(new_tensors) == 1:
|
|
84
|
+
return new_tensors[0]
|
|
85
|
+
return ExecutableTuple(new_tensors)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright 1999-2024 Alibaba Group Holding Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
1
|
# Copyright 1999-2024 Alibaba Group Holding Ltd.
|
|
4
2
|
#
|
|
5
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -66,33 +64,39 @@ class TensorTranspose(TensorHasInput, TensorOperatorMixin):
|
|
|
66
64
|
|
|
67
65
|
def transpose(a, axes=None):
|
|
68
66
|
"""
|
|
69
|
-
|
|
67
|
+
Returns an array with axes transposed.
|
|
68
|
+
|
|
69
|
+
For a 1-D array, this returns an unchanged view of the original array, as a
|
|
70
|
+
transposed vector is simply the same vector.
|
|
71
|
+
To convert a 1-D array into a 2-D column vector, an additional dimension
|
|
72
|
+
must be added, e.g., ``mt.atleast_2d(a).T`` achieves this, as does
|
|
73
|
+
``a[:, mt.newaxis]``.
|
|
74
|
+
For a 2-D array, this is the standard matrix transpose.
|
|
75
|
+
For an n-D array, if axes are given, their order indicates how the
|
|
76
|
+
axes are permuted (see Examples). If axes are not provided, then
|
|
77
|
+
``transpose(a).shape == a.shape[::-1]``.
|
|
70
78
|
|
|
71
79
|
Parameters
|
|
72
80
|
----------
|
|
73
81
|
a : array_like
|
|
74
|
-
Input
|
|
75
|
-
axes : list of ints, optional
|
|
76
|
-
|
|
77
|
-
|
|
82
|
+
Input array.
|
|
83
|
+
axes : tuple or list of ints, optional
|
|
84
|
+
If specified, it must be a tuple or list which contains a permutation
|
|
85
|
+
of [0,1,...,N-1] where N is the number of axes of `a`. The `i`'th axis
|
|
86
|
+
of the returned array will correspond to the axis numbered ``axes[i]``
|
|
87
|
+
of the input. If not specified, defaults to ``range(a.ndim)[::-1]``,
|
|
88
|
+
which reverses the order of the axes.
|
|
78
89
|
|
|
79
90
|
Returns
|
|
80
91
|
-------
|
|
81
|
-
p :
|
|
82
|
-
`a` with its axes permuted.
|
|
83
|
-
possible.
|
|
84
|
-
|
|
85
|
-
See Also
|
|
86
|
-
--------
|
|
87
|
-
moveaxis
|
|
88
|
-
argsort
|
|
92
|
+
p : ndarray
|
|
93
|
+
`a` with its axes permuted. A view is returned whenever possible.
|
|
89
94
|
|
|
90
95
|
Notes
|
|
91
96
|
-----
|
|
92
|
-
Use
|
|
97
|
+
Use ``transpose(a, argsort(axes))`` to invert the transposition of tensors
|
|
93
98
|
when using the `axes` keyword argument.
|
|
94
99
|
|
|
95
|
-
Transposing a 1-D array returns an unchanged view of the original tensor.
|
|
96
100
|
|
|
97
101
|
Examples
|
|
98
102
|
--------
|
|
@@ -121,5 +125,5 @@ def transpose(a, axes=None):
|
|
|
121
125
|
axes = list(range(a.ndim))[::-1]
|
|
122
126
|
else:
|
|
123
127
|
axes = list(axes)
|
|
124
|
-
op = TensorTranspose(axes, dtype=a.dtype
|
|
128
|
+
op = TensorTranspose(axes, dtype=a.dtype)
|
|
125
129
|
return op(a)
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
import numpy as np
|
|
17
17
|
|
|
18
|
-
from ... import opcodes
|
|
18
|
+
from ... import opcodes
|
|
19
19
|
from ...serialization.serializables import BoolField, Int32Field
|
|
20
20
|
from ..core import TensorOrder
|
|
21
21
|
from ..operators import TensorHasInput, TensorOperatorMixin
|
|
@@ -23,7 +23,7 @@ from ..utils import validate_axis
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
class TensorUnique(TensorHasInput, TensorOperatorMixin):
|
|
26
|
-
_op_type_ =
|
|
26
|
+
_op_type_ = opcodes.UNIQUE
|
|
27
27
|
|
|
28
28
|
return_index = BoolField("return_index", default=False)
|
|
29
29
|
return_inverse = BoolField("return_inverse", default=False)
|
|
@@ -75,7 +75,7 @@ class TensorUnique(TensorHasInput, TensorOperatorMixin):
|
|
|
75
75
|
if self.return_counts:
|
|
76
76
|
kw = {
|
|
77
77
|
"shape": (np.nan,),
|
|
78
|
-
"dtype": np.dtype(
|
|
78
|
+
"dtype": np.dtype(int),
|
|
79
79
|
"gpu": input_obj.op.gpu,
|
|
80
80
|
"type": "counts",
|
|
81
81
|
}
|
maxframe/tensor/operators.py
CHANGED
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
|
|
15
16
|
from ..core import OutputType
|
|
16
17
|
from ..core.operator import (
|
|
17
|
-
Fuse,
|
|
18
18
|
HasInput,
|
|
19
19
|
MapReduceOperator,
|
|
20
20
|
Operator,
|
|
@@ -115,9 +115,3 @@ class TensorMapReduceOperator(MapReduceOperator):
|
|
|
115
115
|
_output_type_ = OutputType.tensor
|
|
116
116
|
|
|
117
117
|
dtype = DataTypeField("dtype", default=None)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
class TensorFuse(Fuse):
|
|
121
|
-
_output_type_ = OutputType.tensor
|
|
122
|
-
|
|
123
|
-
dtype = DataTypeField("dtype", default=None)
|
maxframe/tensor/random/core.py
CHANGED
|
@@ -19,9 +19,9 @@ from contextlib import contextmanager
|
|
|
19
19
|
import numpy as np
|
|
20
20
|
|
|
21
21
|
from ...serialization.serializables import FieldTypes, Int32Field, TupleField
|
|
22
|
-
from ..base import broadcast_to
|
|
23
22
|
from ..core import TENSOR_TYPE
|
|
24
23
|
from ..datasource import tensor as astensor
|
|
24
|
+
from ..misc import broadcast_to
|
|
25
25
|
from ..operators import TensorMapReduceOperator, TensorOperator, TensorOperatorMixin
|
|
26
26
|
from ..utils import broadcast_shape
|
|
27
27
|
|
|
@@ -22,6 +22,7 @@ from .core import TensorReduction, TensorReductionMixin
|
|
|
22
22
|
|
|
23
23
|
class TensorCountNonzero(TensorReduction, TensorReductionMixin):
|
|
24
24
|
_op_type_ = opcodes.COUNT_NONZERO
|
|
25
|
+
_func_name = "count_nonzero"
|
|
25
26
|
|
|
26
27
|
def __init__(self, dtype=None, **kw):
|
|
27
28
|
if dtype is None:
|
|
@@ -77,5 +78,5 @@ def count_nonzero(a, axis=None):
|
|
|
77
78
|
array([2, 3])
|
|
78
79
|
|
|
79
80
|
"""
|
|
80
|
-
op = TensorCountNonzero(axis=axis, dtype=np.dtype(
|
|
81
|
+
op = TensorCountNonzero(axis=axis, dtype=np.dtype(int), keepdims=None)
|
|
81
82
|
return op(a)
|
|
@@ -24,6 +24,7 @@ from .core import TensorReduction, TensorReductionMixin
|
|
|
24
24
|
|
|
25
25
|
class TensorNanMoment(TensorReduction, TensorReductionMixin):
|
|
26
26
|
_op_type_ = opcodes.NANMOMENT
|
|
27
|
+
_func_name = "nanvar"
|
|
27
28
|
|
|
28
29
|
moment = Int32Field("moment", default=2)
|
|
29
30
|
ddof = Int32Field("ddof", default=None)
|
|
@@ -36,6 +37,7 @@ class TensorNanMoment(TensorReduction, TensorReductionMixin):
|
|
|
36
37
|
|
|
37
38
|
class TensorNanVar(TensorReduction, TensorReductionMixin):
|
|
38
39
|
_op_type_ = opcodes.NANVAR
|
|
40
|
+
_func_name = "nanvar"
|
|
39
41
|
|
|
40
42
|
ddof = Int32Field("ddof", default=0)
|
|
41
43
|
|
|
@@ -17,8 +17,11 @@
|
|
|
17
17
|
import numpy as np
|
|
18
18
|
import pytest
|
|
19
19
|
|
|
20
|
+
from maxframe.tensor.reduction.core import TensorReduction
|
|
21
|
+
|
|
22
|
+
from ....utils import collect_leaf_operators
|
|
20
23
|
from ...datasource import ones, tensor
|
|
21
|
-
from .. import
|
|
24
|
+
from .. import * # noqa: F401
|
|
22
25
|
|
|
23
26
|
|
|
24
27
|
def test_base_reduction():
|
|
@@ -179,3 +182,11 @@ def test_var_reduction():
|
|
|
179
182
|
|
|
180
183
|
res1 = var(ones((10, 8, 8), chunk_size=3), axis=1)
|
|
181
184
|
assert res1.shape == (10, 8)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def test_reduction_op_func_name():
|
|
188
|
+
# make sure all the binary op has defined the func name.
|
|
189
|
+
|
|
190
|
+
results = collect_leaf_operators(TensorReduction)
|
|
191
|
+
for op_type in results:
|
|
192
|
+
assert hasattr(op_type, "_func_name")
|
maxframe/tensor/reduction/var.py
CHANGED
|
@@ -42,6 +42,7 @@ def reduce_var_square(var_square, avg_diff, count, op, axis, sum_func):
|
|
|
42
42
|
|
|
43
43
|
class TensorMoment(TensorReduction, TensorReductionMixin):
|
|
44
44
|
_op_type_ = opcodes.MOMENT
|
|
45
|
+
_func_name = "var"
|
|
45
46
|
|
|
46
47
|
moment = Int32Field("moment", default=2)
|
|
47
48
|
ddof = Int32Field("ddof", default=None)
|
|
@@ -54,6 +55,7 @@ class TensorMoment(TensorReduction, TensorReductionMixin):
|
|
|
54
55
|
|
|
55
56
|
class TensorVar(TensorReduction, TensorReductionMixin):
|
|
56
57
|
_op_type_ = opcodes.VAR
|
|
58
|
+
_func_name = "var"
|
|
57
59
|
|
|
58
60
|
ddof = Int32Field("ddof", default=0)
|
|
59
61
|
|
|
@@ -16,7 +16,7 @@ from collections.abc import Iterable
|
|
|
16
16
|
|
|
17
17
|
import numpy as np
|
|
18
18
|
|
|
19
|
-
from ... import opcodes
|
|
19
|
+
from ... import opcodes
|
|
20
20
|
from ...core import ENTITY_TYPE
|
|
21
21
|
from ...serialization.serializables import AnyField, BoolField, KeyField, StringField
|
|
22
22
|
from ..core import TENSOR_TYPE, TensorOrder
|
|
@@ -43,7 +43,7 @@ q_error_msg = "Quantiles must be in the range [0, 1]"
|
|
|
43
43
|
|
|
44
44
|
class TensorQuantile(TensorOperator, TensorOperatorMixin):
|
|
45
45
|
__slots__ = ("q_error_msg",)
|
|
46
|
-
_op_type_ =
|
|
46
|
+
_op_type_ = opcodes.QUANTILE
|
|
47
47
|
|
|
48
48
|
a = KeyField("a")
|
|
49
49
|
q = AnyField("q")
|
maxframe/tensor/utils.py
CHANGED
|
@@ -19,18 +19,13 @@ import itertools
|
|
|
19
19
|
import operator
|
|
20
20
|
from collections import OrderedDict
|
|
21
21
|
from collections.abc import Iterable
|
|
22
|
-
from functools import
|
|
22
|
+
from functools import wraps
|
|
23
23
|
from math import ceil
|
|
24
24
|
from numbers import Integral
|
|
25
25
|
from typing import Dict, List, Union
|
|
26
26
|
|
|
27
27
|
import numpy as np
|
|
28
28
|
|
|
29
|
-
try:
|
|
30
|
-
import tiledb
|
|
31
|
-
except (ImportError, OSError): # pragma: no cover
|
|
32
|
-
tildb = None
|
|
33
|
-
|
|
34
29
|
from ..core import ExecutableTuple
|
|
35
30
|
from ..lib.mmh3 import hash_from_buffer
|
|
36
31
|
from ..utils import lazy_import
|
|
@@ -508,7 +503,7 @@ def decide_unify_split(*splits):
|
|
|
508
503
|
|
|
509
504
|
|
|
510
505
|
def check_out_param(out, t, casting):
|
|
511
|
-
from .
|
|
506
|
+
from .misc import broadcast_to
|
|
512
507
|
|
|
513
508
|
if not hasattr(out, "shape"):
|
|
514
509
|
raise TypeError("return arrays must be a tensor")
|
|
@@ -563,21 +558,6 @@ def filter_inputs(inputs):
|
|
|
563
558
|
return [inp for inp in inputs if isinstance(inp, ENTITY_TYPE)]
|
|
564
559
|
|
|
565
560
|
|
|
566
|
-
# As TileDB Ctx's creation is a bit time-consuming,
|
|
567
|
-
# we just cache the Ctx
|
|
568
|
-
# also remember the arguments should be hashable
|
|
569
|
-
@lru_cache(10)
|
|
570
|
-
def _create_tiledb_ctx(conf_tuple):
|
|
571
|
-
if conf_tuple is not None:
|
|
572
|
-
return tiledb.Ctx(dict(conf_tuple))
|
|
573
|
-
return tiledb.Ctx()
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
def get_tiledb_ctx(conf):
|
|
577
|
-
key = tuple(conf.items()) if conf is not None else None
|
|
578
|
-
return _create_tiledb_ctx(key)
|
|
579
|
-
|
|
580
|
-
|
|
581
561
|
# this function is only used for pandas' compatibility
|
|
582
562
|
def to_numpy(pdf):
|
|
583
563
|
try:
|
maxframe/tests/test_protocol.py
CHANGED
|
@@ -85,6 +85,40 @@ def test_error_info_json_serialize():
|
|
|
85
85
|
deserial_err_info.reraise()
|
|
86
86
|
|
|
87
87
|
|
|
88
|
+
class CannotPickleException(Exception):
|
|
89
|
+
def __reduce__(self):
|
|
90
|
+
raise ValueError
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class CannotUnpickleException(Exception):
|
|
94
|
+
@classmethod
|
|
95
|
+
def load_from_pk(cls, _):
|
|
96
|
+
raise ValueError
|
|
97
|
+
|
|
98
|
+
def __reduce__(self):
|
|
99
|
+
return type(self).load_from_pk, (0,)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def test_error_info_fallback_json_serialize():
|
|
103
|
+
try:
|
|
104
|
+
raise CannotPickleException
|
|
105
|
+
except CannotPickleException as ex:
|
|
106
|
+
err_info1 = ErrorInfo.from_exception(ex)
|
|
107
|
+
|
|
108
|
+
try:
|
|
109
|
+
raise CannotUnpickleException
|
|
110
|
+
except CannotUnpickleException as ex:
|
|
111
|
+
err_info2 = ErrorInfo.from_exception(ex)
|
|
112
|
+
|
|
113
|
+
for err_info in (err_info1, err_info2):
|
|
114
|
+
deserial_err_info = ErrorInfo.from_json(err_info.to_json())
|
|
115
|
+
assert deserial_err_info.raw_error_source is None
|
|
116
|
+
assert deserial_err_info.raw_error_data is None
|
|
117
|
+
|
|
118
|
+
with pytest.raises(RemoteException):
|
|
119
|
+
deserial_err_info.reraise()
|
|
120
|
+
|
|
121
|
+
|
|
88
122
|
def test_dag_info_json_serialize():
|
|
89
123
|
try:
|
|
90
124
|
raise ValueError("ERR_DATA")
|
maxframe/tests/test_utils.py
CHANGED
|
@@ -288,15 +288,6 @@ def test_estimate_pandas_size():
|
|
|
288
288
|
df2 = pd.DataFrame(np.random.rand(1000, 10))
|
|
289
289
|
assert utils.estimate_pandas_size(df2) == sys.getsizeof(df2)
|
|
290
290
|
|
|
291
|
-
df3 = pd.DataFrame(
|
|
292
|
-
{
|
|
293
|
-
"A": np.random.choice(["abcd", "def", "gh"], size=(1000,)),
|
|
294
|
-
"B": np.random.rand(1000),
|
|
295
|
-
"C": np.random.rand(1000),
|
|
296
|
-
}
|
|
297
|
-
)
|
|
298
|
-
assert utils.estimate_pandas_size(df3) != sys.getsizeof(df3)
|
|
299
|
-
|
|
300
291
|
s1 = pd.Series(np.random.rand(1000))
|
|
301
292
|
assert utils.estimate_pandas_size(s1) == sys.getsizeof(s1)
|
|
302
293
|
|
|
@@ -307,7 +298,6 @@ def test_estimate_pandas_size():
|
|
|
307
298
|
assert utils.estimate_pandas_size(s2) == sys.getsizeof(s2)
|
|
308
299
|
|
|
309
300
|
s3 = pd.Series(np.random.choice(["abcd", "def", "gh"], size=(1000,)))
|
|
310
|
-
assert utils.estimate_pandas_size(s3) != sys.getsizeof(s3)
|
|
311
301
|
assert (
|
|
312
302
|
pytest.approx(utils.estimate_pandas_size(s3) / sys.getsizeof(s3), abs=0.5) == 1
|
|
313
303
|
)
|
|
@@ -318,7 +308,6 @@ def test_estimate_pandas_size():
|
|
|
318
308
|
assert utils.estimate_pandas_size(idx1) == sys.getsizeof(idx1)
|
|
319
309
|
|
|
320
310
|
string_idx = pd.Index(np.random.choice(["a", "bb", "cc"], size=(1000,)))
|
|
321
|
-
assert utils.estimate_pandas_size(string_idx) != sys.getsizeof(string_idx)
|
|
322
311
|
assert (
|
|
323
312
|
pytest.approx(
|
|
324
313
|
utils.estimate_pandas_size(string_idx) / sys.getsizeof(string_idx), abs=0.5
|
|
@@ -338,7 +327,6 @@ def test_estimate_pandas_size():
|
|
|
338
327
|
},
|
|
339
328
|
index=idx2,
|
|
340
329
|
)
|
|
341
|
-
assert utils.estimate_pandas_size(df4) != sys.getsizeof(df4)
|
|
342
330
|
assert (
|
|
343
331
|
pytest.approx(utils.estimate_pandas_size(df4) / sys.getsizeof(df4), abs=0.5)
|
|
344
332
|
== 1
|