maxframe 2.0.0b2__cp37-cp37m-win32.whl → 2.3.0rc1__cp37-cp37m-win32.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/__init__.py +1 -0
- maxframe/_utils.cp37-win32.pyd +0 -0
- maxframe/_utils.pyx +14 -1
- maxframe/codegen/core.py +9 -8
- maxframe/codegen/spe/core.py +1 -1
- maxframe/codegen/spe/dataframe/__init__.py +1 -0
- maxframe/codegen/spe/dataframe/accessors/base.py +18 -0
- maxframe/codegen/spe/dataframe/accessors/dict_.py +25 -130
- maxframe/codegen/spe/dataframe/accessors/list_.py +12 -48
- maxframe/codegen/spe/dataframe/accessors/struct_.py +28 -0
- maxframe/codegen/spe/dataframe/arithmetic.py +7 -2
- maxframe/codegen/spe/dataframe/groupby.py +88 -0
- maxframe/codegen/spe/dataframe/indexing.py +99 -4
- maxframe/codegen/spe/dataframe/merge.py +38 -1
- maxframe/codegen/spe/dataframe/misc.py +11 -33
- maxframe/codegen/spe/dataframe/reduction.py +32 -9
- maxframe/codegen/spe/dataframe/reshape.py +46 -0
- maxframe/codegen/spe/dataframe/sort.py +39 -18
- maxframe/codegen/spe/dataframe/tests/accessors/test_dict.py +9 -15
- maxframe/codegen/spe/dataframe/tests/accessors/test_list.py +4 -7
- maxframe/codegen/spe/dataframe/tests/accessors/test_struct.py +75 -0
- maxframe/codegen/spe/dataframe/tests/indexing/test_iloc.py +20 -1
- maxframe/codegen/spe/dataframe/tests/indexing/test_loc.py +35 -0
- maxframe/codegen/spe/dataframe/tests/misc/test_misc.py +0 -32
- maxframe/codegen/spe/dataframe/tests/test_groupby.py +81 -18
- maxframe/codegen/spe/dataframe/tests/test_merge.py +27 -1
- maxframe/codegen/spe/dataframe/tests/test_reduction.py +13 -0
- maxframe/codegen/spe/dataframe/tests/test_reshape.py +79 -0
- maxframe/codegen/spe/dataframe/tests/test_sort.py +20 -0
- maxframe/codegen/spe/dataframe/tseries.py +9 -0
- maxframe/codegen/spe/learn/contrib/lightgbm.py +4 -3
- maxframe/codegen/spe/learn/contrib/tests/test_xgboost.py +2 -1
- maxframe/codegen/spe/learn/metrics/__init__.py +1 -1
- maxframe/codegen/spe/learn/metrics/_ranking.py +76 -0
- maxframe/codegen/spe/learn/metrics/pairwise.py +51 -0
- maxframe/codegen/spe/learn/metrics/tests/test_pairwise.py +36 -0
- maxframe/codegen/spe/learn/metrics/tests/test_ranking.py +59 -0
- maxframe/codegen/spe/tensor/__init__.py +3 -0
- maxframe/codegen/spe/tensor/datasource.py +1 -0
- maxframe/codegen/spe/tensor/fft.py +74 -0
- maxframe/codegen/spe/tensor/linalg.py +29 -2
- maxframe/codegen/spe/tensor/misc.py +79 -25
- maxframe/codegen/spe/tensor/spatial.py +45 -0
- maxframe/codegen/spe/tensor/statistics.py +44 -0
- maxframe/codegen/spe/tensor/tests/test_fft.py +64 -0
- maxframe/codegen/spe/tensor/tests/test_linalg.py +15 -1
- maxframe/codegen/spe/tensor/tests/test_misc.py +52 -2
- maxframe/codegen/spe/tensor/tests/test_spatial.py +33 -0
- maxframe/codegen/spe/tensor/tests/test_statistics.py +15 -1
- maxframe/codegen/spe/tests/test_spe_codegen.py +6 -12
- maxframe/codegen/spe/utils.py +2 -0
- maxframe/config/config.py +73 -9
- maxframe/config/tests/test_validators.py +13 -1
- maxframe/config/validators.py +49 -0
- maxframe/conftest.py +54 -17
- maxframe/core/accessor.py +2 -2
- maxframe/core/base.py +2 -1
- maxframe/core/entity/core.py +5 -0
- maxframe/core/entity/tileables.py +3 -1
- maxframe/core/graph/core.cp37-win32.pyd +0 -0
- maxframe/core/graph/entity.py +8 -3
- maxframe/core/mode.py +6 -1
- maxframe/core/operator/base.py +9 -2
- maxframe/core/operator/core.py +10 -2
- maxframe/core/operator/utils.py +13 -0
- maxframe/dataframe/__init__.py +12 -5
- maxframe/dataframe/accessors/__init__.py +1 -1
- maxframe/dataframe/accessors/compat.py +45 -0
- maxframe/dataframe/accessors/datetime_/__init__.py +4 -1
- maxframe/dataframe/accessors/dict_/contains.py +7 -16
- maxframe/dataframe/accessors/dict_/core.py +48 -0
- maxframe/dataframe/accessors/dict_/getitem.py +17 -21
- maxframe/dataframe/accessors/dict_/length.py +7 -16
- maxframe/dataframe/accessors/dict_/remove.py +6 -18
- maxframe/dataframe/accessors/dict_/setitem.py +8 -18
- maxframe/dataframe/accessors/dict_/tests/test_dict_accessor.py +62 -22
- maxframe/dataframe/accessors/list_/__init__.py +2 -2
- maxframe/dataframe/accessors/list_/core.py +48 -0
- maxframe/dataframe/accessors/list_/getitem.py +12 -19
- maxframe/dataframe/accessors/list_/length.py +7 -16
- maxframe/dataframe/accessors/list_/tests/test_list_accessor.py +11 -9
- maxframe/dataframe/accessors/string_/__init__.py +4 -1
- maxframe/dataframe/accessors/struct_/__init__.py +37 -0
- maxframe/dataframe/accessors/struct_/accessor.py +39 -0
- maxframe/dataframe/accessors/struct_/core.py +43 -0
- maxframe/dataframe/accessors/struct_/dtypes.py +53 -0
- maxframe/dataframe/accessors/struct_/field.py +123 -0
- maxframe/dataframe/accessors/struct_/tests/__init__.py +13 -0
- maxframe/dataframe/accessors/struct_/tests/test_struct_accessor.py +91 -0
- maxframe/dataframe/arithmetic/__init__.py +18 -4
- maxframe/dataframe/arithmetic/between.py +106 -0
- maxframe/dataframe/arithmetic/dot.py +237 -0
- maxframe/dataframe/arithmetic/maximum.py +33 -0
- maxframe/dataframe/arithmetic/minimum.py +33 -0
- maxframe/dataframe/arithmetic/{around.py → round.py} +11 -7
- maxframe/dataframe/core.py +161 -224
- maxframe/dataframe/datasource/__init__.py +18 -0
- maxframe/dataframe/datasource/core.py +6 -0
- maxframe/dataframe/datasource/direct.py +57 -0
- maxframe/dataframe/datasource/from_dict.py +124 -0
- maxframe/dataframe/datasource/from_index.py +1 -1
- maxframe/dataframe/datasource/from_records.py +77 -0
- maxframe/dataframe/datasource/from_tensor.py +109 -41
- maxframe/dataframe/datasource/read_csv.py +21 -14
- maxframe/dataframe/datasource/read_odps_query.py +29 -6
- maxframe/dataframe/datasource/read_odps_table.py +32 -10
- maxframe/dataframe/datasource/read_parquet.py +38 -39
- maxframe/dataframe/datasource/tests/test_datasource.py +37 -0
- maxframe/dataframe/datastore/__init__.py +11 -1
- maxframe/dataframe/datastore/direct.py +268 -0
- maxframe/dataframe/datastore/to_csv.py +29 -41
- maxframe/dataframe/datastore/to_odps.py +36 -4
- maxframe/dataframe/extensions/__init__.py +20 -4
- maxframe/dataframe/extensions/apply_chunk.py +32 -6
- maxframe/dataframe/extensions/cartesian_chunk.py +153 -0
- maxframe/dataframe/extensions/collect_kv.py +126 -0
- maxframe/dataframe/extensions/extract_kv.py +177 -0
- maxframe/dataframe/extensions/flatjson.py +2 -1
- maxframe/dataframe/extensions/map_reduce.py +263 -0
- maxframe/dataframe/extensions/rebalance.py +62 -0
- maxframe/dataframe/extensions/tests/test_apply_chunk.py +9 -2
- maxframe/dataframe/extensions/tests/test_extensions.py +54 -0
- maxframe/dataframe/extensions/tests/test_map_reduce.py +135 -0
- maxframe/dataframe/groupby/__init__.py +17 -2
- maxframe/dataframe/groupby/aggregation.py +86 -49
- maxframe/dataframe/groupby/apply.py +1 -1
- maxframe/dataframe/groupby/apply_chunk.py +19 -5
- maxframe/dataframe/groupby/core.py +116 -16
- maxframe/dataframe/groupby/cum.py +4 -25
- maxframe/dataframe/groupby/expanding.py +264 -0
- maxframe/dataframe/groupby/fill.py +1 -1
- maxframe/dataframe/groupby/getitem.py +12 -5
- maxframe/dataframe/groupby/head.py +11 -1
- maxframe/dataframe/groupby/rank.py +136 -0
- maxframe/dataframe/groupby/rolling.py +206 -0
- maxframe/dataframe/groupby/shift.py +114 -0
- maxframe/dataframe/groupby/tests/test_groupby.py +0 -5
- maxframe/dataframe/indexing/__init__.py +22 -2
- maxframe/dataframe/indexing/droplevel.py +195 -0
- maxframe/dataframe/indexing/filter.py +169 -0
- maxframe/dataframe/indexing/get_level_values.py +76 -0
- maxframe/dataframe/indexing/iat.py +45 -0
- maxframe/dataframe/indexing/iloc.py +152 -12
- maxframe/dataframe/indexing/insert.py +46 -18
- maxframe/dataframe/indexing/loc.py +287 -7
- maxframe/dataframe/indexing/reindex.py +14 -5
- maxframe/dataframe/indexing/rename.py +6 -0
- maxframe/dataframe/indexing/rename_axis.py +2 -2
- maxframe/dataframe/indexing/reorder_levels.py +143 -0
- maxframe/dataframe/indexing/reset_index.py +33 -6
- maxframe/dataframe/indexing/sample.py +8 -0
- maxframe/dataframe/indexing/setitem.py +3 -3
- maxframe/dataframe/indexing/swaplevel.py +185 -0
- maxframe/dataframe/indexing/take.py +99 -0
- maxframe/dataframe/indexing/truncate.py +140 -0
- maxframe/dataframe/indexing/where.py +0 -11
- maxframe/dataframe/indexing/xs.py +148 -0
- maxframe/dataframe/merge/__init__.py +15 -1
- maxframe/dataframe/merge/append.py +97 -98
- maxframe/dataframe/merge/combine.py +244 -0
- maxframe/dataframe/merge/combine_first.py +120 -0
- maxframe/dataframe/merge/compare.py +387 -0
- maxframe/dataframe/merge/concat.py +183 -0
- maxframe/dataframe/merge/update.py +271 -0
- maxframe/dataframe/misc/__init__.py +28 -11
- maxframe/dataframe/misc/_duplicate.py +10 -4
- maxframe/dataframe/misc/apply.py +1 -1
- maxframe/dataframe/misc/check_unique.py +82 -0
- maxframe/dataframe/misc/clip.py +145 -0
- maxframe/dataframe/misc/describe.py +175 -9
- maxframe/dataframe/misc/drop.py +31 -0
- maxframe/dataframe/misc/drop_duplicates.py +2 -2
- maxframe/dataframe/misc/duplicated.py +2 -2
- maxframe/dataframe/misc/get_dummies.py +5 -1
- maxframe/dataframe/misc/infer_dtypes.py +251 -0
- maxframe/dataframe/misc/isin.py +2 -2
- maxframe/dataframe/misc/map.py +125 -18
- maxframe/dataframe/misc/repeat.py +159 -0
- maxframe/dataframe/misc/tests/test_misc.py +48 -3
- maxframe/dataframe/misc/to_numeric.py +3 -0
- maxframe/dataframe/misc/transform.py +12 -5
- maxframe/dataframe/misc/transpose.py +13 -1
- maxframe/dataframe/misc/valid_index.py +115 -0
- maxframe/dataframe/misc/value_counts.py +38 -4
- maxframe/dataframe/missing/checkna.py +14 -6
- maxframe/dataframe/missing/dropna.py +5 -0
- maxframe/dataframe/missing/fillna.py +1 -1
- maxframe/dataframe/missing/replace.py +7 -4
- maxframe/dataframe/reduction/__init__.py +35 -16
- maxframe/dataframe/reduction/aggregation.py +43 -14
- maxframe/dataframe/reduction/all.py +2 -2
- maxframe/dataframe/reduction/any.py +2 -2
- maxframe/dataframe/reduction/argmax.py +103 -0
- maxframe/dataframe/reduction/argmin.py +103 -0
- maxframe/dataframe/reduction/core.py +80 -24
- maxframe/dataframe/reduction/count.py +13 -9
- maxframe/dataframe/reduction/cov.py +166 -0
- maxframe/dataframe/reduction/cummax.py +2 -2
- maxframe/dataframe/reduction/cummin.py +2 -2
- maxframe/dataframe/reduction/cumprod.py +2 -2
- maxframe/dataframe/reduction/cumsum.py +2 -2
- maxframe/dataframe/reduction/custom_reduction.py +2 -2
- maxframe/dataframe/reduction/idxmax.py +185 -0
- maxframe/dataframe/reduction/idxmin.py +185 -0
- maxframe/dataframe/reduction/kurtosis.py +37 -30
- maxframe/dataframe/reduction/max.py +2 -2
- maxframe/dataframe/reduction/mean.py +9 -7
- maxframe/dataframe/reduction/median.py +2 -2
- maxframe/dataframe/reduction/min.py +2 -2
- maxframe/dataframe/reduction/mode.py +144 -0
- maxframe/dataframe/reduction/nunique.py +19 -11
- maxframe/dataframe/reduction/prod.py +18 -13
- maxframe/dataframe/reduction/reduction_size.py +2 -2
- maxframe/dataframe/reduction/sem.py +13 -9
- maxframe/dataframe/reduction/skew.py +31 -27
- maxframe/dataframe/reduction/str_concat.py +10 -7
- maxframe/dataframe/reduction/sum.py +18 -14
- maxframe/dataframe/reduction/tests/test_reduction.py +12 -0
- maxframe/dataframe/reduction/unique.py +20 -3
- maxframe/dataframe/reduction/var.py +16 -12
- maxframe/dataframe/reshape/__init__.py +38 -0
- maxframe/dataframe/{misc → reshape}/pivot.py +1 -0
- maxframe/dataframe/{misc → reshape}/pivot_table.py +1 -0
- maxframe/dataframe/reshape/unstack.py +114 -0
- maxframe/dataframe/sort/__init__.py +16 -1
- maxframe/dataframe/sort/argsort.py +68 -0
- maxframe/dataframe/sort/core.py +2 -1
- maxframe/dataframe/sort/nlargest.py +238 -0
- maxframe/dataframe/sort/nsmallest.py +228 -0
- maxframe/dataframe/sort/rank.py +147 -0
- maxframe/dataframe/statistics/__init__.py +3 -3
- maxframe/dataframe/statistics/corr.py +1 -0
- maxframe/dataframe/statistics/quantile.py +2 -2
- maxframe/dataframe/tests/test_typing.py +104 -0
- maxframe/dataframe/tests/test_utils.py +66 -2
- maxframe/dataframe/tseries/__init__.py +19 -0
- maxframe/dataframe/tseries/at_time.py +61 -0
- maxframe/dataframe/tseries/between_time.py +122 -0
- maxframe/dataframe/typing_.py +185 -0
- maxframe/dataframe/utils.py +125 -52
- maxframe/dataframe/window/aggregation.py +8 -4
- maxframe/dataframe/window/core.py +14 -1
- maxframe/dataframe/window/ewm.py +1 -3
- maxframe/dataframe/window/expanding.py +37 -35
- maxframe/dataframe/window/rolling.py +49 -39
- maxframe/dataframe/window/tests/test_expanding.py +1 -7
- maxframe/dataframe/window/tests/test_rolling.py +1 -1
- maxframe/env.py +7 -4
- maxframe/errors.py +2 -2
- maxframe/io/odpsio/schema.py +9 -3
- maxframe/io/odpsio/tableio.py +7 -2
- maxframe/io/odpsio/tests/test_schema.py +198 -83
- maxframe/learn/__init__.py +10 -2
- maxframe/learn/cluster/__init__.py +15 -0
- maxframe/learn/cluster/_kmeans.py +782 -0
- maxframe/learn/contrib/llm/core.py +18 -7
- maxframe/learn/contrib/llm/deploy/__init__.py +13 -0
- maxframe/learn/contrib/llm/deploy/config.py +221 -0
- maxframe/learn/contrib/llm/deploy/core.py +247 -0
- maxframe/learn/contrib/llm/deploy/framework.py +35 -0
- maxframe/learn/contrib/llm/deploy/loader.py +360 -0
- maxframe/learn/contrib/llm/deploy/tests/__init__.py +13 -0
- maxframe/learn/contrib/llm/deploy/tests/test_register_models.py +359 -0
- maxframe/learn/contrib/llm/models/__init__.py +1 -0
- maxframe/learn/contrib/llm/models/dashscope.py +12 -6
- maxframe/learn/contrib/llm/models/managed.py +76 -11
- maxframe/learn/contrib/llm/models/openai.py +72 -0
- maxframe/learn/contrib/llm/tests/__init__.py +13 -0
- maxframe/learn/contrib/llm/tests/test_core.py +34 -0
- maxframe/learn/contrib/llm/tests/test_openai.py +187 -0
- maxframe/learn/contrib/llm/tests/test_text_gen.py +155 -0
- maxframe/learn/contrib/llm/text.py +348 -42
- maxframe/learn/contrib/models.py +4 -1
- maxframe/learn/contrib/xgboost/classifier.py +2 -0
- maxframe/learn/contrib/xgboost/core.py +113 -4
- maxframe/learn/contrib/xgboost/predict.py +4 -2
- maxframe/learn/contrib/xgboost/regressor.py +5 -0
- maxframe/learn/contrib/xgboost/train.py +7 -2
- maxframe/learn/core.py +66 -0
- maxframe/learn/linear_model/_base.py +58 -1
- maxframe/learn/linear_model/_lin_reg.py +1 -1
- maxframe/learn/metrics/__init__.py +6 -0
- maxframe/learn/metrics/_classification.py +145 -0
- maxframe/learn/metrics/_ranking.py +477 -0
- maxframe/learn/metrics/_scorer.py +60 -0
- maxframe/learn/metrics/pairwise/__init__.py +21 -0
- maxframe/learn/metrics/pairwise/core.py +77 -0
- maxframe/learn/metrics/pairwise/cosine.py +115 -0
- maxframe/learn/metrics/pairwise/euclidean.py +176 -0
- maxframe/learn/metrics/pairwise/haversine.py +96 -0
- maxframe/learn/metrics/pairwise/manhattan.py +80 -0
- maxframe/learn/metrics/pairwise/pairwise.py +127 -0
- maxframe/learn/metrics/pairwise/pairwise_distances_topk.py +121 -0
- maxframe/learn/metrics/pairwise/rbf_kernel.py +51 -0
- maxframe/learn/metrics/tests/__init__.py +13 -0
- maxframe/learn/metrics/tests/test_scorer.py +26 -0
- maxframe/learn/preprocessing/_data/min_max_scaler.py +34 -23
- maxframe/learn/preprocessing/_data/standard_scaler.py +34 -25
- maxframe/learn/utils/__init__.py +2 -1
- maxframe/learn/utils/checks.py +1 -2
- maxframe/learn/utils/core.py +59 -0
- maxframe/learn/utils/extmath.py +79 -9
- maxframe/learn/utils/odpsio.py +262 -0
- maxframe/learn/utils/validation.py +2 -2
- maxframe/lib/compat.py +40 -0
- maxframe/lib/dtypes_extension/__init__.py +16 -1
- maxframe/lib/dtypes_extension/_fake_arrow_dtype.py +604 -0
- maxframe/lib/dtypes_extension/blob.py +304 -0
- maxframe/lib/dtypes_extension/dtypes.py +40 -0
- maxframe/lib/dtypes_extension/tests/test_blob.py +88 -0
- maxframe/lib/dtypes_extension/tests/test_dtypes.py +16 -1
- maxframe/lib/dtypes_extension/tests/test_fake_arrow_dtype.py +75 -0
- maxframe/lib/filesystem/_oss_lib/common.py +124 -50
- maxframe/lib/filesystem/_oss_lib/glob.py +1 -1
- maxframe/lib/filesystem/_oss_lib/handle.py +21 -25
- maxframe/lib/filesystem/base.py +1 -1
- maxframe/lib/filesystem/core.py +1 -1
- maxframe/lib/filesystem/oss.py +115 -46
- maxframe/lib/filesystem/tests/test_oss.py +74 -36
- maxframe/lib/mmh3.cp37-win32.pyd +0 -0
- maxframe/lib/wrapped_pickle.py +10 -0
- maxframe/opcodes.py +41 -15
- maxframe/protocol.py +12 -0
- maxframe/remote/core.py +4 -0
- maxframe/serialization/__init__.py +11 -2
- maxframe/serialization/arrow.py +38 -13
- maxframe/serialization/blob.py +32 -0
- maxframe/serialization/core.cp37-win32.pyd +0 -0
- maxframe/serialization/core.pyx +39 -1
- maxframe/serialization/exception.py +2 -4
- maxframe/serialization/numpy.py +11 -0
- maxframe/serialization/pandas.py +46 -9
- maxframe/serialization/serializables/core.py +2 -2
- maxframe/serialization/tests/test_serial.py +31 -4
- maxframe/tensor/__init__.py +38 -8
- maxframe/tensor/arithmetic/__init__.py +19 -10
- maxframe/tensor/arithmetic/core.py +2 -2
- maxframe/tensor/arithmetic/iscomplexobj.py +53 -0
- maxframe/tensor/arithmetic/tests/test_arithmetic.py +6 -9
- maxframe/tensor/core.py +6 -2
- maxframe/tensor/datasource/tests/test_datasource.py +2 -1
- maxframe/tensor/extensions/__init__.py +2 -0
- maxframe/tensor/extensions/apply_chunk.py +3 -3
- maxframe/tensor/extensions/rebalance.py +65 -0
- maxframe/tensor/fft/__init__.py +32 -0
- maxframe/tensor/fft/core.py +168 -0
- maxframe/tensor/fft/fft.py +112 -0
- maxframe/tensor/fft/fft2.py +118 -0
- maxframe/tensor/fft/fftfreq.py +80 -0
- maxframe/tensor/fft/fftn.py +123 -0
- maxframe/tensor/fft/fftshift.py +79 -0
- maxframe/tensor/fft/hfft.py +112 -0
- maxframe/tensor/fft/ifft.py +114 -0
- maxframe/tensor/fft/ifft2.py +115 -0
- maxframe/tensor/fft/ifftn.py +123 -0
- maxframe/tensor/fft/ifftshift.py +73 -0
- maxframe/tensor/fft/ihfft.py +93 -0
- maxframe/tensor/fft/irfft.py +118 -0
- maxframe/tensor/fft/irfft2.py +62 -0
- maxframe/tensor/fft/irfftn.py +114 -0
- maxframe/tensor/fft/rfft.py +116 -0
- maxframe/tensor/fft/rfft2.py +63 -0
- maxframe/tensor/fft/rfftfreq.py +87 -0
- maxframe/tensor/fft/rfftn.py +113 -0
- maxframe/tensor/indexing/fill_diagonal.py +1 -7
- maxframe/tensor/linalg/__init__.py +7 -0
- maxframe/tensor/linalg/_einsumfunc.py +1025 -0
- maxframe/tensor/linalg/cholesky.py +117 -0
- maxframe/tensor/linalg/einsum.py +339 -0
- maxframe/tensor/linalg/lstsq.py +100 -0
- maxframe/tensor/linalg/matrix_norm.py +75 -0
- maxframe/tensor/linalg/norm.py +249 -0
- maxframe/tensor/linalg/solve.py +72 -0
- maxframe/tensor/linalg/solve_triangular.py +2 -2
- maxframe/tensor/linalg/vector_norm.py +113 -0
- maxframe/tensor/misc/__init__.py +24 -1
- maxframe/tensor/misc/argwhere.py +72 -0
- maxframe/tensor/misc/array_split.py +46 -0
- maxframe/tensor/misc/broadcast_arrays.py +57 -0
- maxframe/tensor/misc/copyto.py +130 -0
- maxframe/tensor/misc/delete.py +104 -0
- maxframe/tensor/misc/dsplit.py +68 -0
- maxframe/tensor/misc/ediff1d.py +74 -0
- maxframe/tensor/misc/expand_dims.py +85 -0
- maxframe/tensor/misc/flip.py +90 -0
- maxframe/tensor/misc/fliplr.py +64 -0
- maxframe/tensor/misc/flipud.py +68 -0
- maxframe/tensor/misc/hsplit.py +85 -0
- maxframe/tensor/misc/insert.py +139 -0
- maxframe/tensor/misc/moveaxis.py +83 -0
- maxframe/tensor/misc/result_type.py +88 -0
- maxframe/tensor/misc/roll.py +124 -0
- maxframe/tensor/misc/rollaxis.py +77 -0
- maxframe/tensor/misc/shape.py +89 -0
- maxframe/tensor/misc/split.py +190 -0
- maxframe/tensor/misc/tile.py +109 -0
- maxframe/tensor/misc/vsplit.py +74 -0
- maxframe/tensor/reduction/array_equal.py +2 -1
- maxframe/tensor/sort/__init__.py +2 -0
- maxframe/tensor/sort/argpartition.py +98 -0
- maxframe/tensor/sort/partition.py +228 -0
- maxframe/tensor/spatial/__init__.py +15 -0
- maxframe/tensor/spatial/distance/__init__.py +17 -0
- maxframe/tensor/spatial/distance/cdist.py +421 -0
- maxframe/tensor/spatial/distance/pdist.py +398 -0
- maxframe/tensor/spatial/distance/squareform.py +153 -0
- maxframe/tensor/special/__init__.py +159 -21
- maxframe/tensor/special/airy.py +55 -0
- maxframe/tensor/special/bessel.py +199 -0
- maxframe/tensor/special/core.py +65 -4
- maxframe/tensor/special/ellip_func_integrals.py +155 -0
- maxframe/tensor/special/ellip_harm.py +55 -0
- maxframe/tensor/special/err_fresnel.py +223 -0
- maxframe/tensor/special/gamma_funcs.py +303 -0
- maxframe/tensor/special/hypergeometric_funcs.py +69 -0
- maxframe/tensor/special/info_theory.py +189 -0
- maxframe/tensor/special/misc.py +21 -0
- maxframe/tensor/statistics/__init__.py +6 -0
- maxframe/tensor/statistics/corrcoef.py +77 -0
- maxframe/tensor/statistics/cov.py +222 -0
- maxframe/tensor/statistics/digitize.py +126 -0
- maxframe/tensor/statistics/histogram.py +520 -0
- maxframe/tensor/statistics/median.py +85 -0
- maxframe/tensor/statistics/ptp.py +89 -0
- maxframe/tensor/utils.py +3 -3
- maxframe/tests/test_udf.py +61 -0
- maxframe/tests/test_utils.py +51 -6
- maxframe/tests/utils.py +0 -2
- maxframe/typing_.py +2 -0
- maxframe/udf.py +130 -9
- maxframe/utils.py +254 -27
- {maxframe-2.0.0b2.dist-info → maxframe-2.3.0rc1.dist-info}/METADATA +3 -3
- {maxframe-2.0.0b2.dist-info → maxframe-2.3.0rc1.dist-info}/RECORD +442 -264
- maxframe_client/fetcher.py +35 -4
- maxframe_client/session/odps.py +7 -2
- maxframe_client/session/task.py +8 -1
- maxframe_client/tests/test_fetcher.py +76 -3
- maxframe_client/tests/test_session.py +28 -1
- maxframe/dataframe/arrays.py +0 -864
- /maxframe/dataframe/{misc → reshape}/melt.py +0 -0
- /maxframe/dataframe/{misc → reshape}/stack.py +0 -0
- {maxframe-2.0.0b2.dist-info → maxframe-2.3.0rc1.dist-info}/WHEEL +0 -0
- {maxframe-2.0.0b2.dist-info → maxframe-2.3.0rc1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
# Copyright 1999-2025 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 operator
|
|
16
|
+
import warnings
|
|
17
|
+
from typing import List
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
|
|
21
|
+
from ... import opcodes
|
|
22
|
+
from ...core import ENTITY_TYPE, ExecutableTuple
|
|
23
|
+
from ...serialization.serializables import AnyField, BoolField, KeyField, TupleField
|
|
24
|
+
from ...typing_ import EntityType
|
|
25
|
+
from ..core import TENSOR_TYPE, TensorOrder
|
|
26
|
+
from ..datasource import tensor as astensor
|
|
27
|
+
from ..operators import TensorOperator, TensorOperatorMixin
|
|
28
|
+
from ..utils import is_asc_sorted
|
|
29
|
+
|
|
30
|
+
_hist_bin_selector_names = {
|
|
31
|
+
"stone",
|
|
32
|
+
"auto",
|
|
33
|
+
"doane",
|
|
34
|
+
"fd",
|
|
35
|
+
"rice",
|
|
36
|
+
"scott",
|
|
37
|
+
"sqrt",
|
|
38
|
+
"sturges",
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _ravel_and_check_weights(a, weights):
|
|
43
|
+
"""Check a and weights have matching shapes, and ravel both"""
|
|
44
|
+
a = astensor(a)
|
|
45
|
+
|
|
46
|
+
# Ensure that the array is a "subtractable" dtype
|
|
47
|
+
if a.dtype == np.bool_:
|
|
48
|
+
warnings.warn(
|
|
49
|
+
f"Converting input from {a.dtype} to {np.uint8} for compatibility.",
|
|
50
|
+
RuntimeWarning,
|
|
51
|
+
stacklevel=3,
|
|
52
|
+
)
|
|
53
|
+
a = a.astype(np.uint8)
|
|
54
|
+
|
|
55
|
+
if weights is not None:
|
|
56
|
+
weights = astensor(weights)
|
|
57
|
+
if weights.shape != a.shape:
|
|
58
|
+
raise ValueError("weights should have the same shape as a.")
|
|
59
|
+
weights = weights.ravel()
|
|
60
|
+
a = a.ravel()
|
|
61
|
+
return a, weights
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _check_range(range):
|
|
65
|
+
first_edge, last_edge = range
|
|
66
|
+
if first_edge > last_edge:
|
|
67
|
+
raise ValueError("max must be larger than min in range parameter.")
|
|
68
|
+
if not (np.isfinite(first_edge) and np.isfinite(last_edge)):
|
|
69
|
+
raise ValueError(f"supplied range of [{first_edge}, {last_edge}] is not finite")
|
|
70
|
+
return first_edge, last_edge
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _get_outer_edges(a, range):
|
|
74
|
+
"""
|
|
75
|
+
Determine the outer bin edges to use, from either the data or the range
|
|
76
|
+
argument
|
|
77
|
+
"""
|
|
78
|
+
if range is not None:
|
|
79
|
+
first_edge, last_edge = _check_range(range)
|
|
80
|
+
else:
|
|
81
|
+
assert a.size == 0
|
|
82
|
+
# handle empty arrays. Can't determine range, so use 0-1.
|
|
83
|
+
first_edge, last_edge = 0, 1
|
|
84
|
+
|
|
85
|
+
# expand empty range to avoid divide by zero
|
|
86
|
+
if first_edge == last_edge:
|
|
87
|
+
first_edge = first_edge - 0.5
|
|
88
|
+
last_edge = last_edge + 0.5
|
|
89
|
+
|
|
90
|
+
return first_edge, last_edge
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class TensorHistogramBinEdges(TensorOperator, TensorOperatorMixin):
|
|
94
|
+
_op_type_ = opcodes.HISTOGRAM_BIN_EDGES
|
|
95
|
+
|
|
96
|
+
bins = AnyField("bins", default=None)
|
|
97
|
+
range = TupleField("range", default=None)
|
|
98
|
+
weights = KeyField("weights", default=None)
|
|
99
|
+
uniform_bins = TupleField("uniform_bins", default=None)
|
|
100
|
+
|
|
101
|
+
@classmethod
|
|
102
|
+
def _set_inputs(cls, op: "TensorHistogramBinEdges", inputs: List[EntityType]):
|
|
103
|
+
super()._set_inputs(op, inputs)
|
|
104
|
+
inputs_iter = iter(inputs)
|
|
105
|
+
next(inputs_iter)
|
|
106
|
+
if isinstance(op.bins, ENTITY_TYPE):
|
|
107
|
+
op.bins = next(inputs_iter)
|
|
108
|
+
if op.weights is not None:
|
|
109
|
+
op.weights = next(inputs_iter)
|
|
110
|
+
|
|
111
|
+
def __call__(self, a, bins, range, weights):
|
|
112
|
+
from ... import tensor as mt
|
|
113
|
+
|
|
114
|
+
if range is not None:
|
|
115
|
+
_check_range(range)
|
|
116
|
+
if isinstance(bins, str):
|
|
117
|
+
# string, 'auto', 'stone', ...
|
|
118
|
+
# shape is unknown
|
|
119
|
+
bin_name = bins
|
|
120
|
+
# if `bins` is a string for an automatic method,
|
|
121
|
+
# this will replace it with the number of bins calculated
|
|
122
|
+
if bin_name not in _hist_bin_selector_names:
|
|
123
|
+
raise ValueError(f"{bin_name!r} is not a valid estimator for `bins`")
|
|
124
|
+
if weights is not None:
|
|
125
|
+
raise TypeError(
|
|
126
|
+
"Automated estimation of the number of "
|
|
127
|
+
"bins is not supported for weighted data"
|
|
128
|
+
)
|
|
129
|
+
if isinstance(range, tuple) and len(range) == 2:
|
|
130
|
+
# if `bins` is a string, e.g. 'auto', 'stone'...,
|
|
131
|
+
# and `range` provided as well,
|
|
132
|
+
# `a` should be trimmed first
|
|
133
|
+
first_edge, last_edge = _get_outer_edges(a, range)
|
|
134
|
+
a = a[(a >= first_edge) & (a <= last_edge)]
|
|
135
|
+
shape = (np.nan,)
|
|
136
|
+
elif mt.ndim(bins) == 0:
|
|
137
|
+
try:
|
|
138
|
+
n_equal_bins = operator.index(bins)
|
|
139
|
+
except TypeError: # pragma: no cover
|
|
140
|
+
raise TypeError("`bins` must be an integer, a string, or an array")
|
|
141
|
+
if n_equal_bins < 1:
|
|
142
|
+
raise ValueError("`bins` must be positive, when an integer")
|
|
143
|
+
shape = (bins + 1,)
|
|
144
|
+
elif mt.ndim(bins) == 1:
|
|
145
|
+
if not isinstance(bins, TENSOR_TYPE):
|
|
146
|
+
bins = np.asarray(bins)
|
|
147
|
+
if not is_asc_sorted(bins):
|
|
148
|
+
raise ValueError(
|
|
149
|
+
"`bins` must increase monotonically, when an array"
|
|
150
|
+
)
|
|
151
|
+
shape = astensor(bins).shape
|
|
152
|
+
else:
|
|
153
|
+
raise ValueError("`bins` must be 1d, when an array")
|
|
154
|
+
|
|
155
|
+
inputs = [a]
|
|
156
|
+
if isinstance(bins, TENSOR_TYPE):
|
|
157
|
+
inputs.append(bins)
|
|
158
|
+
if weights is not None:
|
|
159
|
+
inputs.append(weights)
|
|
160
|
+
|
|
161
|
+
return self.new_tensor(inputs, shape=shape, order=TensorOrder.C_ORDER)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def histogram_bin_edges(a, bins=10, range=None, weights=None):
|
|
165
|
+
r"""
|
|
166
|
+
Function to calculate only the edges of the bins used by the `histogram`
|
|
167
|
+
function.
|
|
168
|
+
|
|
169
|
+
Parameters
|
|
170
|
+
----------
|
|
171
|
+
a : array_like
|
|
172
|
+
Input data. The histogram is computed over the flattened tensor.
|
|
173
|
+
bins : int or sequence of scalars or str, optional
|
|
174
|
+
If `bins` is an int, it defines the number of equal-width
|
|
175
|
+
bins in the given range (10, by default). If `bins` is a
|
|
176
|
+
sequence, it defines the bin edges, including the rightmost
|
|
177
|
+
edge, allowing for non-uniform bin widths.
|
|
178
|
+
|
|
179
|
+
If `bins` is a string from the list below, `histogram_bin_edges` will use
|
|
180
|
+
the method chosen to calculate the optimal bin width and
|
|
181
|
+
consequently the number of bins (see `Notes` for more detail on
|
|
182
|
+
the estimators) from the data that falls within the requested
|
|
183
|
+
range. While the bin width will be optimal for the actual data
|
|
184
|
+
in the range, the number of bins will be computed to fill the
|
|
185
|
+
entire range, including the empty portions. For visualisation,
|
|
186
|
+
using the 'auto' option is suggested. Weighted data is not
|
|
187
|
+
supported for automated bin size selection.
|
|
188
|
+
|
|
189
|
+
'auto'
|
|
190
|
+
Maximum of the 'sturges' and 'fd' estimators. Provides good
|
|
191
|
+
all around performance.
|
|
192
|
+
|
|
193
|
+
'fd' (Freedman Diaconis Estimator)
|
|
194
|
+
Robust (resilient to outliers) estimator that takes into
|
|
195
|
+
account data variability and data size.
|
|
196
|
+
|
|
197
|
+
'doane'
|
|
198
|
+
An improved version of Sturges' estimator that works better
|
|
199
|
+
with non-normal datasets.
|
|
200
|
+
|
|
201
|
+
'scott'
|
|
202
|
+
Less robust estimator that that takes into account data
|
|
203
|
+
variability and data size.
|
|
204
|
+
|
|
205
|
+
'stone'
|
|
206
|
+
Estimator based on leave-one-out cross-validation estimate of
|
|
207
|
+
the integrated squared error. Can be regarded as a generalization
|
|
208
|
+
of Scott's rule.
|
|
209
|
+
|
|
210
|
+
'rice'
|
|
211
|
+
Estimator does not take variability into account, only data
|
|
212
|
+
size. Commonly overestimates number of bins required.
|
|
213
|
+
|
|
214
|
+
'sturges'
|
|
215
|
+
R's default method, only accounts for data size. Only
|
|
216
|
+
optimal for gaussian data and underestimates number of bins
|
|
217
|
+
for large non-gaussian datasets.
|
|
218
|
+
|
|
219
|
+
'sqrt'
|
|
220
|
+
Square root (of data size) estimator, used by Excel and
|
|
221
|
+
other programs for its speed and simplicity.
|
|
222
|
+
|
|
223
|
+
range : (float, float), optional
|
|
224
|
+
The lower and upper range of the bins. If not provided, range
|
|
225
|
+
is simply ``(a.min(), a.max())``. Values outside the range are
|
|
226
|
+
ignored. The first element of the range must be less than or
|
|
227
|
+
equal to the second. `range` affects the automatic bin
|
|
228
|
+
computation as well. While bin width is computed to be optimal
|
|
229
|
+
based on the actual data within `range`, the bin count will fill
|
|
230
|
+
the entire range including portions containing no data.
|
|
231
|
+
|
|
232
|
+
weights : array_like, optional
|
|
233
|
+
A tensor of weights, of the same shape as `a`. Each value in
|
|
234
|
+
`a` only contributes its associated weight towards the bin count
|
|
235
|
+
(instead of 1). This is currently not used by any of the bin estimators,
|
|
236
|
+
but may be in the future.
|
|
237
|
+
|
|
238
|
+
Returns
|
|
239
|
+
-------
|
|
240
|
+
bin_edges : tensor of dtype float
|
|
241
|
+
The edges to pass into `histogram`
|
|
242
|
+
|
|
243
|
+
See Also
|
|
244
|
+
--------
|
|
245
|
+
histogram
|
|
246
|
+
|
|
247
|
+
Notes
|
|
248
|
+
-----
|
|
249
|
+
The methods to estimate the optimal number of bins are well founded
|
|
250
|
+
in literature, and are inspired by the choices R provides for
|
|
251
|
+
histogram visualisation. Note that having the number of bins
|
|
252
|
+
proportional to :math:`n^{1/3}` is asymptotically optimal, which is
|
|
253
|
+
why it appears in most estimators. These are simply plug-in methods
|
|
254
|
+
that give good starting points for number of bins. In the equations
|
|
255
|
+
below, :math:`h` is the binwidth and :math:`n_h` is the number of
|
|
256
|
+
bins. All estimators that compute bin counts are recast to bin width
|
|
257
|
+
using the `ptp` of the data. The final bin count is obtained from
|
|
258
|
+
``np.round(np.ceil(range / h))``.
|
|
259
|
+
|
|
260
|
+
'auto' (maximum of the 'sturges' and 'fd' estimators)
|
|
261
|
+
A compromise to get a good value. For small datasets the Sturges
|
|
262
|
+
value will usually be chosen, while larger datasets will usually
|
|
263
|
+
default to FD. Avoids the overly conservative behaviour of FD
|
|
264
|
+
and Sturges for small and large datasets respectively.
|
|
265
|
+
Switchover point is usually :math:`a.size \approx 1000`.
|
|
266
|
+
|
|
267
|
+
'fd' (Freedman Diaconis Estimator)
|
|
268
|
+
.. math:: h = 2 \frac{IQR}{n^{1/3}}
|
|
269
|
+
|
|
270
|
+
The binwidth is proportional to the interquartile range (IQR)
|
|
271
|
+
and inversely proportional to cube root of a.size. Can be too
|
|
272
|
+
conservative for small datasets, but is quite good for large
|
|
273
|
+
datasets. The IQR is very robust to outliers.
|
|
274
|
+
|
|
275
|
+
'scott'
|
|
276
|
+
.. math:: h = \sigma \sqrt[3]{\frac{24 * \sqrt{\pi}}{n}}
|
|
277
|
+
|
|
278
|
+
The binwidth is proportional to the standard deviation of the
|
|
279
|
+
data and inversely proportional to cube root of ``x.size``. Can
|
|
280
|
+
be too conservative for small datasets, but is quite good for
|
|
281
|
+
large datasets. The standard deviation is not very robust to
|
|
282
|
+
outliers. Values are very similar to the Freedman-Diaconis
|
|
283
|
+
estimator in the absence of outliers.
|
|
284
|
+
|
|
285
|
+
'rice'
|
|
286
|
+
.. math:: n_h = 2n^{1/3}
|
|
287
|
+
|
|
288
|
+
The number of bins is only proportional to cube root of
|
|
289
|
+
``a.size``. It tends to overestimate the number of bins and it
|
|
290
|
+
does not take into account data variability.
|
|
291
|
+
|
|
292
|
+
'sturges'
|
|
293
|
+
.. math:: n_h = \log _{2}n+1
|
|
294
|
+
|
|
295
|
+
The number of bins is the base 2 log of ``a.size``. This
|
|
296
|
+
estimator assumes normality of data and is too conservative for
|
|
297
|
+
larger, non-normal datasets. This is the default method in R's
|
|
298
|
+
``hist`` method.
|
|
299
|
+
|
|
300
|
+
'doane'
|
|
301
|
+
.. math:: n_h = 1 + \log_{2}(n) +
|
|
302
|
+
\log_{2}(1 + \frac{|g_1|}{\sigma_{g_1}})
|
|
303
|
+
|
|
304
|
+
g_1 = mean[(\frac{x - \mu}{\sigma})^3]
|
|
305
|
+
|
|
306
|
+
\sigma_{g_1} = \sqrt{\frac{6(n - 2)}{(n + 1)(n + 3)}}
|
|
307
|
+
|
|
308
|
+
An improved version of Sturges' formula that produces better
|
|
309
|
+
estimates for non-normal datasets. This estimator attempts to
|
|
310
|
+
account for the skew of the data.
|
|
311
|
+
|
|
312
|
+
'sqrt'
|
|
313
|
+
.. math:: n_h = \sqrt n
|
|
314
|
+
|
|
315
|
+
The simplest and fastest estimator. Only takes into account the
|
|
316
|
+
data size.
|
|
317
|
+
|
|
318
|
+
Examples
|
|
319
|
+
--------
|
|
320
|
+
>>> import maxframe.tensor as mt
|
|
321
|
+
>>> arr = mt.array([0, 0, 0, 1, 2, 3, 3, 4, 5])
|
|
322
|
+
>>> mt.histogram_bin_edges(arr, bins='auto', range=(0, 1)).execute()
|
|
323
|
+
array([0. , 0.25, 0.5 , 0.75, 1. ])
|
|
324
|
+
>>> mt.histogram_bin_edges(arr, bins=2).execute()
|
|
325
|
+
array([0. , 2.5, 5. ])
|
|
326
|
+
|
|
327
|
+
For consistency with histogram, a tensor of pre-computed bins is
|
|
328
|
+
passed through unmodified:
|
|
329
|
+
|
|
330
|
+
>>> mt.histogram_bin_edges(arr, [1, 2]).execute()
|
|
331
|
+
array([1, 2])
|
|
332
|
+
|
|
333
|
+
This function allows one set of bins to be computed, and reused across
|
|
334
|
+
multiple histograms:
|
|
335
|
+
|
|
336
|
+
>>> shared_bins = mt.histogram_bin_edges(arr, bins='auto')
|
|
337
|
+
>>> shared_bins.execute()
|
|
338
|
+
array([0., 1., 2., 3., 4., 5.])
|
|
339
|
+
|
|
340
|
+
>>> group_id = mt.array([0, 1, 1, 0, 1, 1, 0, 1, 1])
|
|
341
|
+
>>> a = arr[group_id == 0]
|
|
342
|
+
>>> a.execute()
|
|
343
|
+
array([0, 1, 3])
|
|
344
|
+
>>> hist_0, _ = mt.histogram(a, bins=shared_bins).execute()
|
|
345
|
+
>>> b = arr[group_id == 1]
|
|
346
|
+
>>> b.execute()
|
|
347
|
+
array([0, 0, 2, 3, 4, 5])
|
|
348
|
+
>>> hist_1, _ = mt.histogram(b, bins=shared_bins).execute()
|
|
349
|
+
|
|
350
|
+
>>> hist_0; hist_1
|
|
351
|
+
array([1, 1, 0, 1, 0])
|
|
352
|
+
array([2, 0, 1, 1, 2])
|
|
353
|
+
|
|
354
|
+
Which gives more easily comparable results than using separate bins for
|
|
355
|
+
each histogram:
|
|
356
|
+
|
|
357
|
+
>>> hist_0, bins_0 = mt.histogram(a, bins='auto').execute()
|
|
358
|
+
>>> hist_1, bins_1 = mt.histogram(b, bins='auto').execute()
|
|
359
|
+
>>> hist_0; hist_1
|
|
360
|
+
array([1, 1, 1])
|
|
361
|
+
array([2, 1, 1, 2])
|
|
362
|
+
>>> bins_0; bins_1
|
|
363
|
+
array([0., 1., 2., 3.])
|
|
364
|
+
array([0. , 1.25, 2.5 , 3.75, 5. ])
|
|
365
|
+
|
|
366
|
+
"""
|
|
367
|
+
a, weights = _ravel_and_check_weights(a, weights)
|
|
368
|
+
op = TensorHistogramBinEdges(bins=bins, range=range, weights=weights, dtype=a.dtype)
|
|
369
|
+
return op(a, bins, range, weights)
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
class TensorHistogram(TensorOperator, TensorOperatorMixin):
|
|
373
|
+
_op_type_ = opcodes.HISTOGRAM
|
|
374
|
+
|
|
375
|
+
bins = AnyField("bins", default=None)
|
|
376
|
+
range = TupleField("range", default=None)
|
|
377
|
+
weights = KeyField("weights", default=None)
|
|
378
|
+
density = BoolField("density", default=None)
|
|
379
|
+
ret_bins = BoolField("ret_bins", default=None)
|
|
380
|
+
|
|
381
|
+
@property
|
|
382
|
+
def output_limit(self):
|
|
383
|
+
return 1 if not self.ret_bins else 2
|
|
384
|
+
|
|
385
|
+
@classmethod
|
|
386
|
+
def _set_inputs(cls, op: "TensorHistogram", inputs: List[EntityType]):
|
|
387
|
+
super()._set_inputs(op, inputs)
|
|
388
|
+
inputs_iter = iter(inputs)
|
|
389
|
+
next(inputs_iter)
|
|
390
|
+
if isinstance(op.bins, ENTITY_TYPE):
|
|
391
|
+
op.bins = next(inputs_iter)
|
|
392
|
+
if op.weights is not None:
|
|
393
|
+
op.weights = next(inputs_iter)
|
|
394
|
+
|
|
395
|
+
def __call__(self, a, bins, range, weights):
|
|
396
|
+
a, weights = _ravel_and_check_weights(a, weights)
|
|
397
|
+
histogram_bin_edges_op = TensorHistogramBinEdges(
|
|
398
|
+
bins=bins, range=range, weights=weights, dtype=np.dtype(np.float64)
|
|
399
|
+
)
|
|
400
|
+
bins = self.bins = histogram_bin_edges_op(a, bins, range, weights)
|
|
401
|
+
|
|
402
|
+
inputs = [histogram_bin_edges_op.inputs[0]]
|
|
403
|
+
if isinstance(bins, TENSOR_TYPE):
|
|
404
|
+
inputs.append(bins)
|
|
405
|
+
# Histogram is an integer or a float array depending on the weights.
|
|
406
|
+
if weights is None:
|
|
407
|
+
dtype = np.dtype(np.intp)
|
|
408
|
+
else:
|
|
409
|
+
inputs.append(weights)
|
|
410
|
+
dtype = weights.dtype
|
|
411
|
+
self.dtype = dtype
|
|
412
|
+
|
|
413
|
+
hist = self.new_tensor(
|
|
414
|
+
inputs, shape=(bins.size - 1,), order=TensorOrder.C_ORDER
|
|
415
|
+
)
|
|
416
|
+
return ExecutableTuple([hist, bins])
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
def histogram(a, bins=10, range=None, weights=None, density=None):
|
|
420
|
+
r"""
|
|
421
|
+
Compute the histogram of a set of data.
|
|
422
|
+
|
|
423
|
+
Parameters
|
|
424
|
+
----------
|
|
425
|
+
a : array_like
|
|
426
|
+
Input data. The histogram is computed over the flattened tensor.
|
|
427
|
+
bins : int or sequence of scalars or str, optional
|
|
428
|
+
If `bins` is an int, it defines the number of equal-width
|
|
429
|
+
bins in the given range (10, by default). If `bins` is a
|
|
430
|
+
sequence, it defines a monotonically increasing tensor of bin edges,
|
|
431
|
+
including the rightmost edge, allowing for non-uniform bin widths.
|
|
432
|
+
|
|
433
|
+
If `bins` is a string, it defines the method used to calculate the
|
|
434
|
+
optimal bin width, as defined by `histogram_bin_edges`.
|
|
435
|
+
|
|
436
|
+
range : (float, float), optional
|
|
437
|
+
The lower and upper range of the bins. If not provided, range
|
|
438
|
+
is simply ``(a.min(), a.max())``. Values outside the range are
|
|
439
|
+
ignored. The first element of the range must be less than or
|
|
440
|
+
equal to the second. `range` affects the automatic bin
|
|
441
|
+
computation as well. While bin width is computed to be optimal
|
|
442
|
+
based on the actual data within `range`, the bin count will fill
|
|
443
|
+
the entire range including portions containing no data.
|
|
444
|
+
|
|
445
|
+
weights : array_like, optional
|
|
446
|
+
A tensor of weights, of the same shape as `a`. Each value in
|
|
447
|
+
`a` only contributes its associated weight towards the bin count
|
|
448
|
+
(instead of 1). If `density` is True, the weights are
|
|
449
|
+
normalized, so that the integral of the density over the range
|
|
450
|
+
remains 1.
|
|
451
|
+
density : bool, optional
|
|
452
|
+
If ``False``, the result will contain the number of samples in
|
|
453
|
+
each bin. If ``True``, the result is the value of the
|
|
454
|
+
probability *density* function at the bin, normalized such that
|
|
455
|
+
the *integral* over the range is 1. Note that the sum of the
|
|
456
|
+
histogram values will not be equal to 1 unless bins of unity
|
|
457
|
+
width are chosen; it is not a probability *mass* function.
|
|
458
|
+
|
|
459
|
+
Overrides the ``normed`` keyword if given.
|
|
460
|
+
|
|
461
|
+
Returns
|
|
462
|
+
-------
|
|
463
|
+
hist : tensor
|
|
464
|
+
The values of the histogram. See `density` and `weights` for a
|
|
465
|
+
description of the possible semantics.
|
|
466
|
+
bin_edges : tensor of dtype float
|
|
467
|
+
Return the bin edges ``(length(hist)+1)``.
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
See Also
|
|
471
|
+
--------
|
|
472
|
+
histogramdd, bincount, searchsorted, digitize, histogram_bin_edges
|
|
473
|
+
|
|
474
|
+
Notes
|
|
475
|
+
-----
|
|
476
|
+
All but the last (righthand-most) bin is half-open. In other words,
|
|
477
|
+
if `bins` is::
|
|
478
|
+
|
|
479
|
+
[1, 2, 3, 4]
|
|
480
|
+
|
|
481
|
+
then the first bin is ``[1, 2)`` (including 1, but excluding 2) and
|
|
482
|
+
the second ``[2, 3)``. The last bin, however, is ``[3, 4]``, which
|
|
483
|
+
*includes* 4.
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
Examples
|
|
487
|
+
--------
|
|
488
|
+
>>> import maxframe.tensor as mt
|
|
489
|
+
>>> mt.histogram([1, 2, 1], bins=[0, 1, 2, 3]).execute()
|
|
490
|
+
(array([0, 2, 1]), array([0, 1, 2, 3]))
|
|
491
|
+
>>> mt.histogram(mt.arange(4), bins=mt.arange(5), density=True).execute()
|
|
492
|
+
(array([0.25, 0.25, 0.25, 0.25]), array([0, 1, 2, 3, 4]))
|
|
493
|
+
>>> mt.histogram([[1, 2, 1], [1, 0, 1]], bins=[0,1,2,3]).execute()
|
|
494
|
+
(array([1, 4, 1]), array([0, 1, 2, 3]))
|
|
495
|
+
|
|
496
|
+
>>> a = mt.arange(5)
|
|
497
|
+
>>> hist, bin_edges = mt.histogram(a, density=True)
|
|
498
|
+
>>> hist.execute()
|
|
499
|
+
array([0.5, 0. , 0.5, 0. , 0. , 0.5, 0. , 0.5, 0. , 0.5])
|
|
500
|
+
>>> hist.sum().execute()
|
|
501
|
+
2.4999999999999996
|
|
502
|
+
>>> mt.sum(hist * mt.diff(bin_edges)).execute()
|
|
503
|
+
1.0
|
|
504
|
+
|
|
505
|
+
Automated Bin Selection Methods example, using 2 peak random data
|
|
506
|
+
with 2000 points:
|
|
507
|
+
|
|
508
|
+
>>> import matplotlib.pyplot as plt
|
|
509
|
+
>>> rng = mt.random.RandomState(10) # deterministic random data
|
|
510
|
+
>>> a = mt.hstack((rng.normal(size=1000),
|
|
511
|
+
... rng.normal(loc=5, scale=2, size=1000)))
|
|
512
|
+
>>> _ = plt.hist(np.asarray(a), bins='auto') # arguments are passed to np.histogram
|
|
513
|
+
>>> plt.title("Histogram with 'auto' bins")
|
|
514
|
+
Text(0.5, 1.0, "Histogram with 'auto' bins")
|
|
515
|
+
>>> plt.show()
|
|
516
|
+
|
|
517
|
+
"""
|
|
518
|
+
a, weights = _ravel_and_check_weights(a, weights)
|
|
519
|
+
op = TensorHistogram(bins=bins, range=range, weights=weights, density=density)
|
|
520
|
+
return op(a, bins, range, weights)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Copyright 1999-2025 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
|
+
from .quantile import quantile
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def median(a, axis=None, out=None, overwrite_input=False, keepdims=False):
|
|
19
|
+
"""
|
|
20
|
+
Compute the median along the specified axis.
|
|
21
|
+
|
|
22
|
+
Returns the median of the tensor elements.
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
----------
|
|
26
|
+
a : array_like
|
|
27
|
+
Input tensor or object that can be converted to a tensor.
|
|
28
|
+
axis : {int, sequence of int, None}, optional
|
|
29
|
+
Axis or axes along which the medians are computed. The default
|
|
30
|
+
is to compute the median along a flattened version of the tensor.
|
|
31
|
+
A sequence of axes is supported since version 1.9.0.
|
|
32
|
+
out : Tensor, optional
|
|
33
|
+
Alternative output tensor in which to place the result. It must
|
|
34
|
+
have the same shape and buffer length as the expected output,
|
|
35
|
+
but the type (of the output) will be cast if necessary.
|
|
36
|
+
overwrite_input : bool, optional
|
|
37
|
+
Just for compatibility with Numpy, would not take effect.
|
|
38
|
+
keepdims : bool, optional
|
|
39
|
+
If this is set to True, the axes which are reduced are left
|
|
40
|
+
in the result as dimensions with size one. With this option,
|
|
41
|
+
the result will broadcast correctly against the original `arr`.
|
|
42
|
+
|
|
43
|
+
Returns
|
|
44
|
+
-------
|
|
45
|
+
median : Tensor
|
|
46
|
+
A new tensor holding the result. If the input contains integers
|
|
47
|
+
or floats smaller than ``float64``, then the output data-type is
|
|
48
|
+
``np.float64``. Otherwise, the data-type of the output is the
|
|
49
|
+
same as that of the input. If `out` is specified, that tensor is
|
|
50
|
+
returned instead.
|
|
51
|
+
|
|
52
|
+
See Also
|
|
53
|
+
--------
|
|
54
|
+
mean, percentile
|
|
55
|
+
|
|
56
|
+
Notes
|
|
57
|
+
-----
|
|
58
|
+
Given a vector ``V`` of length ``N``, the median of ``V`` is the
|
|
59
|
+
middle value of a sorted copy of ``V``, ``V_sorted`` - i
|
|
60
|
+
e., ``V_sorted[(N-1)/2]``, when ``N`` is odd, and the average of the
|
|
61
|
+
two middle values of ``V_sorted`` when ``N`` is even.
|
|
62
|
+
|
|
63
|
+
Examples
|
|
64
|
+
--------
|
|
65
|
+
>>> import maxframe.tensor as mt
|
|
66
|
+
>>> a = mt.array([[10, 7, 4], [3, 2, 1]])
|
|
67
|
+
>>> a.execute()
|
|
68
|
+
array([[10, 7, 4],
|
|
69
|
+
[ 3, 2, 1]])
|
|
70
|
+
>>> mt.median(a).execute()
|
|
71
|
+
3.5
|
|
72
|
+
>>> mt.median(a, axis=0).execute()
|
|
73
|
+
array([6.5, 4.5, 2.5])
|
|
74
|
+
>>> mt.median(a, axis=1).execute()
|
|
75
|
+
array([7., 2.])
|
|
76
|
+
>>> m = mt.median(a, axis=0)
|
|
77
|
+
>>> out = mt.zeros_like(m)
|
|
78
|
+
>>> mt.median(a, axis=0, out=m).execute()
|
|
79
|
+
array([6.5, 4.5, 2.5])
|
|
80
|
+
>>> m.execute()
|
|
81
|
+
array([6.5, 4.5, 2.5])
|
|
82
|
+
"""
|
|
83
|
+
return quantile(
|
|
84
|
+
a, 0.5, axis=axis, out=out, overwrite_input=overwrite_input, keepdims=keepdims
|
|
85
|
+
)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Copyright 1999-2025 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
|
+
from ..core import Tensor
|
|
16
|
+
from ..datasource import tensor as astensor
|
|
17
|
+
from ..utils import check_out_param, validate_axis
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def ptp(a, axis=None, out=None, keepdims=None):
|
|
21
|
+
"""
|
|
22
|
+
Range of values (maximum - minimum) along an axis.
|
|
23
|
+
|
|
24
|
+
The name of the function comes from the acronym for 'peak to peak'.
|
|
25
|
+
|
|
26
|
+
Parameters
|
|
27
|
+
----------
|
|
28
|
+
a : array_like
|
|
29
|
+
Input values.
|
|
30
|
+
axis : int, optional
|
|
31
|
+
Axis along which to find the peaks. By default, flatten the
|
|
32
|
+
array.
|
|
33
|
+
out : array_like
|
|
34
|
+
Alternative output tensor in which to place the result. It must
|
|
35
|
+
have the same shape and buffer length as the expected output,
|
|
36
|
+
but the type of the output values will be cast if necessary.
|
|
37
|
+
keepdims : bool, optional
|
|
38
|
+
If this is set to True, the axes which are reduced are left
|
|
39
|
+
in the result as dimensions with size one. With this option,
|
|
40
|
+
the result will broadcast correctly against the input array.
|
|
41
|
+
|
|
42
|
+
If the default value is passed, then `keepdims` will not be
|
|
43
|
+
passed through to the `ptp` method of sub-classes of
|
|
44
|
+
`Tensor`, however any non-default value will be. If the
|
|
45
|
+
sub-class' method does not implement `keepdims` any
|
|
46
|
+
exceptions will be raised.
|
|
47
|
+
|
|
48
|
+
Returns
|
|
49
|
+
-------
|
|
50
|
+
ptp : Tensor
|
|
51
|
+
A new tensor holding the result, unless `out` was
|
|
52
|
+
specified, in which case a reference to `out` is returned.
|
|
53
|
+
|
|
54
|
+
Examples
|
|
55
|
+
--------
|
|
56
|
+
>>> import maxframe.tensor as mt
|
|
57
|
+
|
|
58
|
+
>>> x = mt.arange(4).reshape((2,2))
|
|
59
|
+
>>> x.execute()
|
|
60
|
+
array([[0, 1],
|
|
61
|
+
[2, 3]])
|
|
62
|
+
|
|
63
|
+
>>> mt.ptp(x, axis=0).execute()
|
|
64
|
+
array([2, 2])
|
|
65
|
+
|
|
66
|
+
>>> mt.ptp(x, axis=1).execute()
|
|
67
|
+
array([1, 1])
|
|
68
|
+
|
|
69
|
+
"""
|
|
70
|
+
from ..misc.ravel import ravel
|
|
71
|
+
|
|
72
|
+
a = astensor(a)
|
|
73
|
+
|
|
74
|
+
if axis is None:
|
|
75
|
+
a = ravel(a)
|
|
76
|
+
else:
|
|
77
|
+
validate_axis(a.ndim, axis)
|
|
78
|
+
|
|
79
|
+
t = a.max(axis=axis, keepdims=keepdims) - a.min(axis=axis, keepdims=keepdims)
|
|
80
|
+
|
|
81
|
+
if out is not None:
|
|
82
|
+
if not isinstance(out, Tensor):
|
|
83
|
+
raise TypeError(f"out should be Tensor object, got {type(out)} instead")
|
|
84
|
+
|
|
85
|
+
check_out_param(out, t, "same_kind")
|
|
86
|
+
out.data = t.data
|
|
87
|
+
return out
|
|
88
|
+
|
|
89
|
+
return t
|