maxframe 0.1.0b5__cp311-cp311-macosx_11_0_arm64.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 +32 -0
- maxframe/_utils.cpython-311-darwin.so +0 -0
- maxframe/_utils.pxd +33 -0
- maxframe/_utils.pyx +547 -0
- maxframe/codegen.py +528 -0
- maxframe/config/__init__.py +15 -0
- maxframe/config/config.py +443 -0
- maxframe/config/tests/__init__.py +13 -0
- maxframe/config/tests/test_config.py +103 -0
- maxframe/config/tests/test_validators.py +34 -0
- maxframe/config/validators.py +57 -0
- maxframe/conftest.py +139 -0
- maxframe/core/__init__.py +65 -0
- maxframe/core/base.py +156 -0
- maxframe/core/entity/__init__.py +44 -0
- maxframe/core/entity/chunks.py +68 -0
- maxframe/core/entity/core.py +152 -0
- maxframe/core/entity/executable.py +337 -0
- maxframe/core/entity/fuse.py +73 -0
- maxframe/core/entity/objects.py +100 -0
- maxframe/core/entity/output_types.py +90 -0
- maxframe/core/entity/tileables.py +438 -0
- maxframe/core/entity/utils.py +24 -0
- maxframe/core/graph/__init__.py +17 -0
- maxframe/core/graph/builder/__init__.py +16 -0
- maxframe/core/graph/builder/base.py +86 -0
- maxframe/core/graph/builder/chunk.py +430 -0
- maxframe/core/graph/builder/tileable.py +34 -0
- maxframe/core/graph/builder/utils.py +41 -0
- maxframe/core/graph/core.cpython-311-darwin.so +0 -0
- maxframe/core/graph/core.pyx +467 -0
- maxframe/core/graph/entity.py +171 -0
- maxframe/core/graph/tests/__init__.py +13 -0
- maxframe/core/graph/tests/test_graph.py +205 -0
- maxframe/core/mode.py +96 -0
- maxframe/core/operator/__init__.py +34 -0
- maxframe/core/operator/base.py +450 -0
- maxframe/core/operator/core.py +276 -0
- maxframe/core/operator/fetch.py +53 -0
- maxframe/core/operator/fuse.py +29 -0
- maxframe/core/operator/objects.py +72 -0
- maxframe/core/operator/shuffle.py +111 -0
- maxframe/core/operator/tests/__init__.py +13 -0
- maxframe/core/operator/tests/test_core.py +64 -0
- maxframe/core/tests/__init__.py +13 -0
- maxframe/core/tests/test_mode.py +75 -0
- maxframe/dataframe/__init__.py +81 -0
- maxframe/dataframe/arithmetic/__init__.py +359 -0
- maxframe/dataframe/arithmetic/abs.py +33 -0
- maxframe/dataframe/arithmetic/add.py +60 -0
- maxframe/dataframe/arithmetic/arccos.py +28 -0
- maxframe/dataframe/arithmetic/arccosh.py +28 -0
- maxframe/dataframe/arithmetic/arcsin.py +28 -0
- maxframe/dataframe/arithmetic/arcsinh.py +28 -0
- maxframe/dataframe/arithmetic/arctan.py +28 -0
- maxframe/dataframe/arithmetic/arctanh.py +28 -0
- maxframe/dataframe/arithmetic/around.py +152 -0
- maxframe/dataframe/arithmetic/bitwise_and.py +46 -0
- maxframe/dataframe/arithmetic/bitwise_or.py +50 -0
- maxframe/dataframe/arithmetic/bitwise_xor.py +46 -0
- maxframe/dataframe/arithmetic/ceil.py +28 -0
- maxframe/dataframe/arithmetic/core.py +342 -0
- maxframe/dataframe/arithmetic/cos.py +28 -0
- maxframe/dataframe/arithmetic/cosh.py +28 -0
- maxframe/dataframe/arithmetic/degrees.py +28 -0
- maxframe/dataframe/arithmetic/docstring.py +442 -0
- maxframe/dataframe/arithmetic/equal.py +56 -0
- maxframe/dataframe/arithmetic/exp.py +28 -0
- maxframe/dataframe/arithmetic/exp2.py +28 -0
- maxframe/dataframe/arithmetic/expm1.py +28 -0
- maxframe/dataframe/arithmetic/floor.py +28 -0
- maxframe/dataframe/arithmetic/floordiv.py +64 -0
- maxframe/dataframe/arithmetic/greater.py +57 -0
- maxframe/dataframe/arithmetic/greater_equal.py +57 -0
- maxframe/dataframe/arithmetic/invert.py +33 -0
- maxframe/dataframe/arithmetic/is_ufuncs.py +62 -0
- maxframe/dataframe/arithmetic/less.py +57 -0
- maxframe/dataframe/arithmetic/less_equal.py +57 -0
- maxframe/dataframe/arithmetic/log.py +28 -0
- maxframe/dataframe/arithmetic/log10.py +28 -0
- maxframe/dataframe/arithmetic/log2.py +28 -0
- maxframe/dataframe/arithmetic/mod.py +60 -0
- maxframe/dataframe/arithmetic/multiply.py +60 -0
- maxframe/dataframe/arithmetic/negative.py +33 -0
- maxframe/dataframe/arithmetic/not_equal.py +56 -0
- maxframe/dataframe/arithmetic/power.py +68 -0
- maxframe/dataframe/arithmetic/radians.py +28 -0
- maxframe/dataframe/arithmetic/sin.py +28 -0
- maxframe/dataframe/arithmetic/sinh.py +28 -0
- maxframe/dataframe/arithmetic/sqrt.py +28 -0
- maxframe/dataframe/arithmetic/subtract.py +64 -0
- maxframe/dataframe/arithmetic/tan.py +28 -0
- maxframe/dataframe/arithmetic/tanh.py +28 -0
- maxframe/dataframe/arithmetic/tests/__init__.py +13 -0
- maxframe/dataframe/arithmetic/tests/test_arithmetic.py +695 -0
- maxframe/dataframe/arithmetic/truediv.py +64 -0
- maxframe/dataframe/arithmetic/trunc.py +28 -0
- maxframe/dataframe/arrays.py +864 -0
- maxframe/dataframe/core.py +2417 -0
- maxframe/dataframe/datasource/__init__.py +15 -0
- maxframe/dataframe/datasource/core.py +81 -0
- maxframe/dataframe/datasource/dataframe.py +59 -0
- maxframe/dataframe/datasource/date_range.py +504 -0
- maxframe/dataframe/datasource/from_index.py +54 -0
- maxframe/dataframe/datasource/from_records.py +107 -0
- maxframe/dataframe/datasource/from_tensor.py +419 -0
- maxframe/dataframe/datasource/index.py +117 -0
- maxframe/dataframe/datasource/read_csv.py +528 -0
- maxframe/dataframe/datasource/read_odps_query.py +299 -0
- maxframe/dataframe/datasource/read_odps_table.py +253 -0
- maxframe/dataframe/datasource/read_parquet.py +421 -0
- maxframe/dataframe/datasource/series.py +55 -0
- maxframe/dataframe/datasource/tests/__init__.py +13 -0
- maxframe/dataframe/datasource/tests/test_datasource.py +401 -0
- maxframe/dataframe/datastore/__init__.py +26 -0
- maxframe/dataframe/datastore/core.py +19 -0
- maxframe/dataframe/datastore/to_csv.py +227 -0
- maxframe/dataframe/datastore/to_odps.py +162 -0
- maxframe/dataframe/extensions/__init__.py +41 -0
- maxframe/dataframe/extensions/accessor.py +50 -0
- maxframe/dataframe/extensions/reshuffle.py +83 -0
- maxframe/dataframe/extensions/tests/__init__.py +13 -0
- maxframe/dataframe/extensions/tests/test_extensions.py +38 -0
- maxframe/dataframe/fetch/__init__.py +15 -0
- maxframe/dataframe/fetch/core.py +86 -0
- maxframe/dataframe/groupby/__init__.py +82 -0
- maxframe/dataframe/groupby/aggregation.py +350 -0
- maxframe/dataframe/groupby/apply.py +251 -0
- maxframe/dataframe/groupby/core.py +179 -0
- maxframe/dataframe/groupby/cum.py +124 -0
- maxframe/dataframe/groupby/fill.py +141 -0
- maxframe/dataframe/groupby/getitem.py +92 -0
- maxframe/dataframe/groupby/head.py +105 -0
- maxframe/dataframe/groupby/sample.py +214 -0
- maxframe/dataframe/groupby/tests/__init__.py +13 -0
- maxframe/dataframe/groupby/tests/test_groupby.py +374 -0
- maxframe/dataframe/groupby/transform.py +255 -0
- maxframe/dataframe/indexing/__init__.py +84 -0
- maxframe/dataframe/indexing/add_prefix_suffix.py +110 -0
- maxframe/dataframe/indexing/align.py +349 -0
- maxframe/dataframe/indexing/at.py +83 -0
- maxframe/dataframe/indexing/getitem.py +204 -0
- maxframe/dataframe/indexing/iat.py +37 -0
- maxframe/dataframe/indexing/iloc.py +566 -0
- maxframe/dataframe/indexing/insert.py +86 -0
- maxframe/dataframe/indexing/loc.py +411 -0
- maxframe/dataframe/indexing/reindex.py +526 -0
- maxframe/dataframe/indexing/rename.py +462 -0
- maxframe/dataframe/indexing/rename_axis.py +209 -0
- maxframe/dataframe/indexing/reset_index.py +402 -0
- maxframe/dataframe/indexing/sample.py +221 -0
- maxframe/dataframe/indexing/set_axis.py +194 -0
- maxframe/dataframe/indexing/set_index.py +61 -0
- maxframe/dataframe/indexing/setitem.py +130 -0
- maxframe/dataframe/indexing/tests/__init__.py +13 -0
- maxframe/dataframe/indexing/tests/test_indexing.py +488 -0
- maxframe/dataframe/indexing/where.py +308 -0
- maxframe/dataframe/initializer.py +288 -0
- maxframe/dataframe/merge/__init__.py +32 -0
- maxframe/dataframe/merge/append.py +121 -0
- maxframe/dataframe/merge/concat.py +325 -0
- maxframe/dataframe/merge/merge.py +593 -0
- maxframe/dataframe/merge/tests/__init__.py +13 -0
- maxframe/dataframe/merge/tests/test_merge.py +215 -0
- maxframe/dataframe/misc/__init__.py +134 -0
- maxframe/dataframe/misc/_duplicate.py +46 -0
- maxframe/dataframe/misc/accessor.py +276 -0
- maxframe/dataframe/misc/apply.py +692 -0
- maxframe/dataframe/misc/astype.py +236 -0
- maxframe/dataframe/misc/case_when.py +141 -0
- maxframe/dataframe/misc/check_monotonic.py +84 -0
- maxframe/dataframe/misc/cut.py +383 -0
- maxframe/dataframe/misc/datetimes.py +79 -0
- maxframe/dataframe/misc/describe.py +108 -0
- maxframe/dataframe/misc/diff.py +210 -0
- maxframe/dataframe/misc/drop.py +440 -0
- maxframe/dataframe/misc/drop_duplicates.py +248 -0
- maxframe/dataframe/misc/duplicated.py +292 -0
- maxframe/dataframe/misc/eval.py +728 -0
- maxframe/dataframe/misc/explode.py +171 -0
- maxframe/dataframe/misc/get_dummies.py +208 -0
- maxframe/dataframe/misc/isin.py +217 -0
- maxframe/dataframe/misc/map.py +236 -0
- maxframe/dataframe/misc/melt.py +162 -0
- maxframe/dataframe/misc/memory_usage.py +248 -0
- maxframe/dataframe/misc/pct_change.py +150 -0
- maxframe/dataframe/misc/pivot_table.py +262 -0
- maxframe/dataframe/misc/qcut.py +104 -0
- maxframe/dataframe/misc/select_dtypes.py +104 -0
- maxframe/dataframe/misc/shift.py +256 -0
- maxframe/dataframe/misc/stack.py +238 -0
- maxframe/dataframe/misc/string_.py +221 -0
- maxframe/dataframe/misc/tests/__init__.py +13 -0
- maxframe/dataframe/misc/tests/test_misc.py +468 -0
- maxframe/dataframe/misc/to_numeric.py +178 -0
- maxframe/dataframe/misc/transform.py +361 -0
- maxframe/dataframe/misc/transpose.py +136 -0
- maxframe/dataframe/misc/value_counts.py +182 -0
- maxframe/dataframe/missing/__init__.py +53 -0
- maxframe/dataframe/missing/checkna.py +223 -0
- maxframe/dataframe/missing/dropna.py +280 -0
- maxframe/dataframe/missing/fillna.py +275 -0
- maxframe/dataframe/missing/replace.py +439 -0
- maxframe/dataframe/missing/tests/__init__.py +13 -0
- maxframe/dataframe/missing/tests/test_missing.py +89 -0
- maxframe/dataframe/operators.py +273 -0
- maxframe/dataframe/plotting/__init__.py +40 -0
- maxframe/dataframe/plotting/core.py +78 -0
- maxframe/dataframe/plotting/tests/__init__.py +13 -0
- maxframe/dataframe/plotting/tests/test_plotting.py +136 -0
- maxframe/dataframe/reduction/__init__.py +107 -0
- maxframe/dataframe/reduction/aggregation.py +344 -0
- maxframe/dataframe/reduction/all.py +78 -0
- maxframe/dataframe/reduction/any.py +78 -0
- maxframe/dataframe/reduction/core.py +837 -0
- maxframe/dataframe/reduction/count.py +59 -0
- maxframe/dataframe/reduction/cummax.py +30 -0
- maxframe/dataframe/reduction/cummin.py +30 -0
- maxframe/dataframe/reduction/cumprod.py +30 -0
- maxframe/dataframe/reduction/cumsum.py +30 -0
- maxframe/dataframe/reduction/custom_reduction.py +42 -0
- maxframe/dataframe/reduction/kurtosis.py +104 -0
- maxframe/dataframe/reduction/max.py +65 -0
- maxframe/dataframe/reduction/mean.py +61 -0
- maxframe/dataframe/reduction/min.py +65 -0
- maxframe/dataframe/reduction/nunique.py +141 -0
- maxframe/dataframe/reduction/prod.py +76 -0
- maxframe/dataframe/reduction/reduction_size.py +36 -0
- maxframe/dataframe/reduction/sem.py +69 -0
- maxframe/dataframe/reduction/skew.py +89 -0
- maxframe/dataframe/reduction/std.py +53 -0
- maxframe/dataframe/reduction/str_concat.py +48 -0
- maxframe/dataframe/reduction/sum.py +77 -0
- maxframe/dataframe/reduction/tests/__init__.py +13 -0
- maxframe/dataframe/reduction/tests/test_reduction.py +486 -0
- maxframe/dataframe/reduction/unique.py +90 -0
- maxframe/dataframe/reduction/var.py +72 -0
- maxframe/dataframe/sort/__init__.py +34 -0
- maxframe/dataframe/sort/core.py +36 -0
- maxframe/dataframe/sort/sort_index.py +153 -0
- maxframe/dataframe/sort/sort_values.py +311 -0
- maxframe/dataframe/sort/tests/__init__.py +13 -0
- maxframe/dataframe/sort/tests/test_sort.py +81 -0
- maxframe/dataframe/statistics/__init__.py +33 -0
- maxframe/dataframe/statistics/corr.py +280 -0
- maxframe/dataframe/statistics/quantile.py +341 -0
- maxframe/dataframe/statistics/tests/__init__.py +13 -0
- maxframe/dataframe/statistics/tests/test_statistics.py +82 -0
- maxframe/dataframe/tests/__init__.py +13 -0
- maxframe/dataframe/tests/test_initializer.py +29 -0
- maxframe/dataframe/tseries/__init__.py +13 -0
- maxframe/dataframe/tseries/tests/__init__.py +13 -0
- maxframe/dataframe/tseries/tests/test_tseries.py +30 -0
- maxframe/dataframe/tseries/to_datetime.py +297 -0
- maxframe/dataframe/ufunc/__init__.py +27 -0
- maxframe/dataframe/ufunc/tensor.py +54 -0
- maxframe/dataframe/ufunc/ufunc.py +52 -0
- maxframe/dataframe/utils.py +1267 -0
- maxframe/dataframe/window/__init__.py +29 -0
- maxframe/dataframe/window/aggregation.py +96 -0
- maxframe/dataframe/window/core.py +69 -0
- maxframe/dataframe/window/ewm.py +249 -0
- maxframe/dataframe/window/expanding.py +147 -0
- maxframe/dataframe/window/rolling.py +376 -0
- maxframe/dataframe/window/tests/__init__.py +13 -0
- maxframe/dataframe/window/tests/test_ewm.py +70 -0
- maxframe/dataframe/window/tests/test_expanding.py +66 -0
- maxframe/dataframe/window/tests/test_rolling.py +57 -0
- maxframe/env.py +33 -0
- maxframe/errors.py +21 -0
- maxframe/extension.py +81 -0
- maxframe/learn/__init__.py +17 -0
- maxframe/learn/contrib/__init__.py +17 -0
- maxframe/learn/contrib/pytorch/__init__.py +16 -0
- maxframe/learn/contrib/pytorch/run_function.py +110 -0
- maxframe/learn/contrib/pytorch/run_script.py +102 -0
- maxframe/learn/contrib/pytorch/tests/__init__.py +13 -0
- maxframe/learn/contrib/pytorch/tests/test_pytorch.py +42 -0
- maxframe/learn/contrib/utils.py +52 -0
- maxframe/learn/contrib/xgboost/__init__.py +26 -0
- maxframe/learn/contrib/xgboost/classifier.py +86 -0
- maxframe/learn/contrib/xgboost/core.py +156 -0
- maxframe/learn/contrib/xgboost/dmatrix.py +150 -0
- maxframe/learn/contrib/xgboost/predict.py +138 -0
- maxframe/learn/contrib/xgboost/regressor.py +78 -0
- maxframe/learn/contrib/xgboost/tests/__init__.py +13 -0
- maxframe/learn/contrib/xgboost/tests/test_core.py +43 -0
- maxframe/learn/contrib/xgboost/train.py +121 -0
- maxframe/learn/utils/__init__.py +15 -0
- maxframe/learn/utils/core.py +29 -0
- maxframe/lib/__init__.py +15 -0
- maxframe/lib/aio/__init__.py +27 -0
- maxframe/lib/aio/_runners.py +162 -0
- maxframe/lib/aio/_threads.py +35 -0
- maxframe/lib/aio/base.py +82 -0
- maxframe/lib/aio/file.py +85 -0
- maxframe/lib/aio/isolation.py +100 -0
- maxframe/lib/aio/lru.py +242 -0
- maxframe/lib/aio/parallelism.py +37 -0
- maxframe/lib/aio/tests/__init__.py +13 -0
- maxframe/lib/aio/tests/test_aio_file.py +55 -0
- maxframe/lib/compression.py +55 -0
- maxframe/lib/cython/__init__.py +13 -0
- maxframe/lib/cython/libcpp.pxd +30 -0
- maxframe/lib/filesystem/__init__.py +21 -0
- maxframe/lib/filesystem/_glob.py +173 -0
- maxframe/lib/filesystem/_oss_lib/__init__.py +13 -0
- maxframe/lib/filesystem/_oss_lib/common.py +198 -0
- maxframe/lib/filesystem/_oss_lib/glob.py +147 -0
- maxframe/lib/filesystem/_oss_lib/handle.py +156 -0
- maxframe/lib/filesystem/arrow.py +236 -0
- maxframe/lib/filesystem/base.py +263 -0
- maxframe/lib/filesystem/core.py +95 -0
- maxframe/lib/filesystem/fsmap.py +164 -0
- maxframe/lib/filesystem/hdfs.py +31 -0
- maxframe/lib/filesystem/local.py +112 -0
- maxframe/lib/filesystem/oss.py +157 -0
- maxframe/lib/filesystem/tests/__init__.py +13 -0
- maxframe/lib/filesystem/tests/test_filesystem.py +223 -0
- maxframe/lib/filesystem/tests/test_oss.py +182 -0
- maxframe/lib/functools_compat.py +81 -0
- maxframe/lib/mmh3.cpython-311-darwin.so +0 -0
- maxframe/lib/mmh3_src/MurmurHash3.cpp +339 -0
- maxframe/lib/mmh3_src/MurmurHash3.h +43 -0
- maxframe/lib/mmh3_src/mmh3module.cpp +387 -0
- maxframe/lib/sparse/__init__.py +861 -0
- maxframe/lib/sparse/array.py +1604 -0
- maxframe/lib/sparse/core.py +92 -0
- maxframe/lib/sparse/matrix.py +241 -0
- maxframe/lib/sparse/tests/__init__.py +15 -0
- maxframe/lib/sparse/tests/test_sparse.py +476 -0
- maxframe/lib/sparse/vector.py +150 -0
- maxframe/lib/tblib/LICENSE +20 -0
- maxframe/lib/tblib/__init__.py +327 -0
- maxframe/lib/tblib/cpython.py +83 -0
- maxframe/lib/tblib/decorators.py +44 -0
- maxframe/lib/tblib/pickling_support.py +90 -0
- maxframe/lib/tests/__init__.py +13 -0
- maxframe/lib/tests/test_wrapped_pickle.py +51 -0
- maxframe/lib/version.py +620 -0
- maxframe/lib/wrapped_pickle.py +139 -0
- maxframe/mixin.py +100 -0
- maxframe/odpsio/__init__.py +21 -0
- maxframe/odpsio/arrow.py +91 -0
- maxframe/odpsio/schema.py +364 -0
- maxframe/odpsio/tableio.py +322 -0
- maxframe/odpsio/tests/__init__.py +13 -0
- maxframe/odpsio/tests/test_arrow.py +88 -0
- maxframe/odpsio/tests/test_schema.py +297 -0
- maxframe/odpsio/tests/test_tableio.py +136 -0
- maxframe/odpsio/tests/test_volumeio.py +90 -0
- maxframe/odpsio/volumeio.py +95 -0
- maxframe/opcodes.py +590 -0
- maxframe/protocol.py +415 -0
- maxframe/remote/__init__.py +18 -0
- maxframe/remote/core.py +210 -0
- maxframe/remote/run_script.py +121 -0
- maxframe/serialization/__init__.py +26 -0
- maxframe/serialization/arrow.py +95 -0
- maxframe/serialization/core.cpython-311-darwin.so +0 -0
- maxframe/serialization/core.pxd +44 -0
- maxframe/serialization/core.pyi +61 -0
- maxframe/serialization/core.pyx +1094 -0
- maxframe/serialization/exception.py +86 -0
- maxframe/serialization/maxframe_objects.py +39 -0
- maxframe/serialization/numpy.py +91 -0
- maxframe/serialization/pandas.py +202 -0
- maxframe/serialization/scipy.py +71 -0
- maxframe/serialization/serializables/__init__.py +55 -0
- maxframe/serialization/serializables/core.py +262 -0
- maxframe/serialization/serializables/field.py +624 -0
- maxframe/serialization/serializables/field_type.py +589 -0
- maxframe/serialization/serializables/tests/__init__.py +13 -0
- maxframe/serialization/serializables/tests/test_field_type.py +121 -0
- maxframe/serialization/serializables/tests/test_serializable.py +250 -0
- maxframe/serialization/tests/__init__.py +13 -0
- maxframe/serialization/tests/test_serial.py +412 -0
- maxframe/session.py +1310 -0
- maxframe/tensor/__init__.py +183 -0
- maxframe/tensor/arithmetic/__init__.py +315 -0
- maxframe/tensor/arithmetic/abs.py +68 -0
- maxframe/tensor/arithmetic/absolute.py +68 -0
- maxframe/tensor/arithmetic/add.py +82 -0
- maxframe/tensor/arithmetic/angle.py +72 -0
- maxframe/tensor/arithmetic/arccos.py +104 -0
- maxframe/tensor/arithmetic/arccosh.py +91 -0
- maxframe/tensor/arithmetic/arcsin.py +94 -0
- maxframe/tensor/arithmetic/arcsinh.py +86 -0
- maxframe/tensor/arithmetic/arctan.py +106 -0
- maxframe/tensor/arithmetic/arctan2.py +128 -0
- maxframe/tensor/arithmetic/arctanh.py +86 -0
- maxframe/tensor/arithmetic/around.py +114 -0
- maxframe/tensor/arithmetic/bitand.py +95 -0
- maxframe/tensor/arithmetic/bitor.py +102 -0
- maxframe/tensor/arithmetic/bitxor.py +95 -0
- maxframe/tensor/arithmetic/cbrt.py +66 -0
- maxframe/tensor/arithmetic/ceil.py +71 -0
- maxframe/tensor/arithmetic/clip.py +165 -0
- maxframe/tensor/arithmetic/conj.py +74 -0
- maxframe/tensor/arithmetic/copysign.py +78 -0
- maxframe/tensor/arithmetic/core.py +544 -0
- maxframe/tensor/arithmetic/cos.py +85 -0
- maxframe/tensor/arithmetic/cosh.py +72 -0
- maxframe/tensor/arithmetic/deg2rad.py +72 -0
- maxframe/tensor/arithmetic/degrees.py +77 -0
- maxframe/tensor/arithmetic/divide.py +114 -0
- maxframe/tensor/arithmetic/equal.py +76 -0
- maxframe/tensor/arithmetic/exp.py +106 -0
- maxframe/tensor/arithmetic/exp2.py +67 -0
- maxframe/tensor/arithmetic/expm1.py +79 -0
- maxframe/tensor/arithmetic/fabs.py +74 -0
- maxframe/tensor/arithmetic/fix.py +69 -0
- maxframe/tensor/arithmetic/float_power.py +103 -0
- maxframe/tensor/arithmetic/floor.py +77 -0
- maxframe/tensor/arithmetic/floordiv.py +94 -0
- maxframe/tensor/arithmetic/fmax.py +105 -0
- maxframe/tensor/arithmetic/fmin.py +106 -0
- maxframe/tensor/arithmetic/fmod.py +99 -0
- maxframe/tensor/arithmetic/frexp.py +92 -0
- maxframe/tensor/arithmetic/greater.py +77 -0
- maxframe/tensor/arithmetic/greater_equal.py +69 -0
- maxframe/tensor/arithmetic/hypot.py +77 -0
- maxframe/tensor/arithmetic/i0.py +89 -0
- maxframe/tensor/arithmetic/imag.py +67 -0
- maxframe/tensor/arithmetic/invert.py +110 -0
- maxframe/tensor/arithmetic/isclose.py +115 -0
- maxframe/tensor/arithmetic/iscomplex.py +64 -0
- maxframe/tensor/arithmetic/isfinite.py +106 -0
- maxframe/tensor/arithmetic/isinf.py +103 -0
- maxframe/tensor/arithmetic/isnan.py +82 -0
- maxframe/tensor/arithmetic/isreal.py +63 -0
- maxframe/tensor/arithmetic/ldexp.py +99 -0
- maxframe/tensor/arithmetic/less.py +69 -0
- maxframe/tensor/arithmetic/less_equal.py +69 -0
- maxframe/tensor/arithmetic/log.py +92 -0
- maxframe/tensor/arithmetic/log10.py +85 -0
- maxframe/tensor/arithmetic/log1p.py +95 -0
- maxframe/tensor/arithmetic/log2.py +85 -0
- maxframe/tensor/arithmetic/logaddexp.py +80 -0
- maxframe/tensor/arithmetic/logaddexp2.py +78 -0
- maxframe/tensor/arithmetic/logical_and.py +81 -0
- maxframe/tensor/arithmetic/logical_not.py +74 -0
- maxframe/tensor/arithmetic/logical_or.py +82 -0
- maxframe/tensor/arithmetic/logical_xor.py +88 -0
- maxframe/tensor/arithmetic/lshift.py +82 -0
- maxframe/tensor/arithmetic/maximum.py +108 -0
- maxframe/tensor/arithmetic/minimum.py +108 -0
- maxframe/tensor/arithmetic/mod.py +104 -0
- maxframe/tensor/arithmetic/modf.py +83 -0
- maxframe/tensor/arithmetic/multiply.py +81 -0
- maxframe/tensor/arithmetic/nan_to_num.py +99 -0
- maxframe/tensor/arithmetic/negative.py +65 -0
- maxframe/tensor/arithmetic/nextafter.py +68 -0
- maxframe/tensor/arithmetic/not_equal.py +72 -0
- maxframe/tensor/arithmetic/positive.py +47 -0
- maxframe/tensor/arithmetic/power.py +106 -0
- maxframe/tensor/arithmetic/rad2deg.py +71 -0
- maxframe/tensor/arithmetic/radians.py +77 -0
- maxframe/tensor/arithmetic/real.py +70 -0
- maxframe/tensor/arithmetic/reciprocal.py +76 -0
- maxframe/tensor/arithmetic/rint.py +68 -0
- maxframe/tensor/arithmetic/rshift.py +81 -0
- maxframe/tensor/arithmetic/setimag.py +29 -0
- maxframe/tensor/arithmetic/setreal.py +29 -0
- maxframe/tensor/arithmetic/sign.py +81 -0
- maxframe/tensor/arithmetic/signbit.py +65 -0
- maxframe/tensor/arithmetic/sin.py +98 -0
- maxframe/tensor/arithmetic/sinc.py +102 -0
- maxframe/tensor/arithmetic/sinh.py +93 -0
- maxframe/tensor/arithmetic/spacing.py +72 -0
- maxframe/tensor/arithmetic/sqrt.py +81 -0
- maxframe/tensor/arithmetic/square.py +69 -0
- maxframe/tensor/arithmetic/subtract.py +81 -0
- maxframe/tensor/arithmetic/tan.py +88 -0
- maxframe/tensor/arithmetic/tanh.py +92 -0
- maxframe/tensor/arithmetic/tests/__init__.py +15 -0
- maxframe/tensor/arithmetic/tests/test_arithmetic.py +414 -0
- maxframe/tensor/arithmetic/truediv.py +104 -0
- maxframe/tensor/arithmetic/trunc.py +72 -0
- maxframe/tensor/arithmetic/utils.py +65 -0
- maxframe/tensor/array_utils.py +186 -0
- maxframe/tensor/base/__init__.py +34 -0
- maxframe/tensor/base/astype.py +119 -0
- maxframe/tensor/base/atleast_1d.py +74 -0
- maxframe/tensor/base/broadcast_to.py +89 -0
- maxframe/tensor/base/ravel.py +92 -0
- maxframe/tensor/base/tests/__init__.py +13 -0
- maxframe/tensor/base/tests/test_base.py +114 -0
- maxframe/tensor/base/transpose.py +125 -0
- maxframe/tensor/base/unique.py +205 -0
- maxframe/tensor/base/where.py +127 -0
- maxframe/tensor/core.py +724 -0
- maxframe/tensor/datasource/__init__.py +32 -0
- maxframe/tensor/datasource/arange.py +156 -0
- maxframe/tensor/datasource/array.py +415 -0
- maxframe/tensor/datasource/core.py +109 -0
- maxframe/tensor/datasource/empty.py +169 -0
- maxframe/tensor/datasource/from_dataframe.py +70 -0
- maxframe/tensor/datasource/from_dense.py +54 -0
- maxframe/tensor/datasource/from_sparse.py +47 -0
- maxframe/tensor/datasource/full.py +186 -0
- maxframe/tensor/datasource/ones.py +173 -0
- maxframe/tensor/datasource/scalar.py +40 -0
- maxframe/tensor/datasource/tests/__init__.py +13 -0
- maxframe/tensor/datasource/tests/test_datasource.py +278 -0
- maxframe/tensor/datasource/zeros.py +188 -0
- maxframe/tensor/fetch/__init__.py +15 -0
- maxframe/tensor/fetch/core.py +54 -0
- maxframe/tensor/indexing/__init__.py +47 -0
- maxframe/tensor/indexing/choose.py +196 -0
- maxframe/tensor/indexing/compress.py +124 -0
- maxframe/tensor/indexing/core.py +190 -0
- maxframe/tensor/indexing/extract.py +71 -0
- maxframe/tensor/indexing/fill_diagonal.py +183 -0
- maxframe/tensor/indexing/flatnonzero.py +60 -0
- maxframe/tensor/indexing/getitem.py +175 -0
- maxframe/tensor/indexing/nonzero.py +120 -0
- maxframe/tensor/indexing/setitem.py +132 -0
- maxframe/tensor/indexing/slice.py +29 -0
- maxframe/tensor/indexing/take.py +130 -0
- maxframe/tensor/indexing/tests/__init__.py +15 -0
- maxframe/tensor/indexing/tests/test_indexing.py +234 -0
- maxframe/tensor/indexing/unravel_index.py +103 -0
- maxframe/tensor/merge/__init__.py +15 -0
- maxframe/tensor/merge/stack.py +132 -0
- maxframe/tensor/merge/tests/__init__.py +13 -0
- maxframe/tensor/merge/tests/test_merge.py +52 -0
- maxframe/tensor/operators.py +123 -0
- maxframe/tensor/random/__init__.py +168 -0
- maxframe/tensor/random/beta.py +87 -0
- maxframe/tensor/random/binomial.py +137 -0
- maxframe/tensor/random/bytes.py +39 -0
- maxframe/tensor/random/chisquare.py +110 -0
- maxframe/tensor/random/choice.py +186 -0
- maxframe/tensor/random/core.py +234 -0
- maxframe/tensor/random/dirichlet.py +123 -0
- maxframe/tensor/random/exponential.py +94 -0
- maxframe/tensor/random/f.py +135 -0
- maxframe/tensor/random/gamma.py +128 -0
- maxframe/tensor/random/geometric.py +93 -0
- maxframe/tensor/random/gumbel.py +167 -0
- maxframe/tensor/random/hypergeometric.py +148 -0
- maxframe/tensor/random/laplace.py +133 -0
- maxframe/tensor/random/logistic.py +129 -0
- maxframe/tensor/random/lognormal.py +159 -0
- maxframe/tensor/random/logseries.py +122 -0
- maxframe/tensor/random/multinomial.py +133 -0
- maxframe/tensor/random/multivariate_normal.py +192 -0
- maxframe/tensor/random/negative_binomial.py +125 -0
- maxframe/tensor/random/noncentral_chisquare.py +132 -0
- maxframe/tensor/random/noncentral_f.py +126 -0
- maxframe/tensor/random/normal.py +143 -0
- maxframe/tensor/random/pareto.py +140 -0
- maxframe/tensor/random/permutation.py +104 -0
- maxframe/tensor/random/poisson.py +111 -0
- maxframe/tensor/random/power.py +142 -0
- maxframe/tensor/random/rand.py +82 -0
- maxframe/tensor/random/randint.py +121 -0
- maxframe/tensor/random/randn.py +96 -0
- maxframe/tensor/random/random_integers.py +123 -0
- maxframe/tensor/random/random_sample.py +86 -0
- maxframe/tensor/random/rayleigh.py +110 -0
- maxframe/tensor/random/shuffle.py +61 -0
- maxframe/tensor/random/standard_cauchy.py +105 -0
- maxframe/tensor/random/standard_exponential.py +72 -0
- maxframe/tensor/random/standard_gamma.py +120 -0
- maxframe/tensor/random/standard_normal.py +74 -0
- maxframe/tensor/random/standard_t.py +135 -0
- maxframe/tensor/random/tests/__init__.py +15 -0
- maxframe/tensor/random/tests/test_random.py +167 -0
- maxframe/tensor/random/triangular.py +119 -0
- maxframe/tensor/random/uniform.py +131 -0
- maxframe/tensor/random/vonmises.py +131 -0
- maxframe/tensor/random/wald.py +114 -0
- maxframe/tensor/random/weibull.py +140 -0
- maxframe/tensor/random/zipf.py +122 -0
- maxframe/tensor/rechunk/__init__.py +26 -0
- maxframe/tensor/rechunk/rechunk.py +43 -0
- maxframe/tensor/reduction/__init__.py +66 -0
- maxframe/tensor/reduction/all.py +103 -0
- maxframe/tensor/reduction/allclose.py +88 -0
- maxframe/tensor/reduction/any.py +105 -0
- maxframe/tensor/reduction/argmax.py +103 -0
- maxframe/tensor/reduction/argmin.py +103 -0
- maxframe/tensor/reduction/array_equal.py +64 -0
- maxframe/tensor/reduction/core.py +168 -0
- maxframe/tensor/reduction/count_nonzero.py +81 -0
- maxframe/tensor/reduction/cumprod.py +97 -0
- maxframe/tensor/reduction/cumsum.py +101 -0
- maxframe/tensor/reduction/max.py +120 -0
- maxframe/tensor/reduction/mean.py +123 -0
- maxframe/tensor/reduction/min.py +120 -0
- maxframe/tensor/reduction/nanargmax.py +82 -0
- maxframe/tensor/reduction/nanargmin.py +76 -0
- maxframe/tensor/reduction/nancumprod.py +91 -0
- maxframe/tensor/reduction/nancumsum.py +94 -0
- maxframe/tensor/reduction/nanmax.py +111 -0
- maxframe/tensor/reduction/nanmean.py +106 -0
- maxframe/tensor/reduction/nanmin.py +111 -0
- maxframe/tensor/reduction/nanprod.py +94 -0
- maxframe/tensor/reduction/nanstd.py +126 -0
- maxframe/tensor/reduction/nansum.py +115 -0
- maxframe/tensor/reduction/nanvar.py +149 -0
- maxframe/tensor/reduction/prod.py +130 -0
- maxframe/tensor/reduction/std.py +134 -0
- maxframe/tensor/reduction/sum.py +125 -0
- maxframe/tensor/reduction/tests/__init__.py +13 -0
- maxframe/tensor/reduction/tests/test_reduction.py +181 -0
- maxframe/tensor/reduction/var.py +176 -0
- maxframe/tensor/reshape/__init__.py +17 -0
- maxframe/tensor/reshape/reshape.py +188 -0
- maxframe/tensor/reshape/tests/__init__.py +15 -0
- maxframe/tensor/reshape/tests/test_reshape.py +37 -0
- maxframe/tensor/statistics/__init__.py +13 -0
- maxframe/tensor/statistics/percentile.py +175 -0
- maxframe/tensor/statistics/quantile.py +288 -0
- maxframe/tensor/ufunc/__init__.py +26 -0
- maxframe/tensor/ufunc/ufunc.py +200 -0
- maxframe/tensor/utils.py +718 -0
- maxframe/tests/__init__.py +13 -0
- maxframe/tests/test_codegen.py +69 -0
- maxframe/tests/test_protocol.py +144 -0
- maxframe/tests/test_utils.py +376 -0
- maxframe/tests/utils.py +164 -0
- maxframe/typing_.py +37 -0
- maxframe/udf.py +134 -0
- maxframe/utils.py +1114 -0
- maxframe-0.1.0b5.dist-info/METADATA +104 -0
- maxframe-0.1.0b5.dist-info/RECORD +647 -0
- maxframe-0.1.0b5.dist-info/WHEEL +5 -0
- maxframe-0.1.0b5.dist-info/top_level.txt +3 -0
- maxframe_client/__init__.py +17 -0
- maxframe_client/clients/__init__.py +13 -0
- maxframe_client/clients/framedriver.py +118 -0
- maxframe_client/clients/spe.py +104 -0
- maxframe_client/conftest.py +15 -0
- maxframe_client/fetcher.py +264 -0
- maxframe_client/session/__init__.py +22 -0
- maxframe_client/session/consts.py +36 -0
- maxframe_client/session/graph.py +119 -0
- maxframe_client/session/odps.py +482 -0
- maxframe_client/session/task.py +280 -0
- maxframe_client/session/tests/__init__.py +13 -0
- maxframe_client/session/tests/test_task.py +85 -0
- maxframe_client/tests/__init__.py +13 -0
- maxframe_client/tests/test_fetcher.py +89 -0
- maxframe_client/tests/test_session.py +255 -0
|
@@ -0,0 +1,1604 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# Copyright 1999-2024 Alibaba Group Holding Ltd.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
from functools import partialmethod
|
|
18
|
+
|
|
19
|
+
from ...utils import ceildiv
|
|
20
|
+
from .core import (
|
|
21
|
+
cp,
|
|
22
|
+
cps,
|
|
23
|
+
get_array_module,
|
|
24
|
+
get_sparse_module,
|
|
25
|
+
is_cupy,
|
|
26
|
+
issparse,
|
|
27
|
+
naked,
|
|
28
|
+
np,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class SparseNDArray:
|
|
33
|
+
__slots__ = ("__weakref__",)
|
|
34
|
+
__array_priority__ = 21
|
|
35
|
+
|
|
36
|
+
def __new__(cls, *args, **kwargs):
|
|
37
|
+
shape = kwargs.get("shape", None)
|
|
38
|
+
if shape is not None and len(shape) == 1:
|
|
39
|
+
from .vector import SparseVector
|
|
40
|
+
|
|
41
|
+
return object.__new__(SparseVector)
|
|
42
|
+
if len(args) == 1 and issparse(args[0]) and args[0].ndim == 2:
|
|
43
|
+
from .matrix import SparseMatrix
|
|
44
|
+
|
|
45
|
+
return object.__new__(SparseMatrix)
|
|
46
|
+
|
|
47
|
+
else:
|
|
48
|
+
if cls is not SparseNDArray:
|
|
49
|
+
return object.__new__(cls)
|
|
50
|
+
else:
|
|
51
|
+
raise ValueError(
|
|
52
|
+
f"The construct params of {cls.__name__} are invalid: "
|
|
53
|
+
f"args={args}, kwargs={kwargs}"
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def raw(self):
|
|
58
|
+
raise NotImplementedError
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def call_sparse(method, *args, **kwargs):
|
|
62
|
+
new_args = []
|
|
63
|
+
make_dense = False
|
|
64
|
+
matrix = None
|
|
65
|
+
for arg in args:
|
|
66
|
+
if hasattr(arg, "spmatrix"):
|
|
67
|
+
# todo add support for multiple sparse arrays
|
|
68
|
+
if make_dense or matrix is not None:
|
|
69
|
+
make_dense = True
|
|
70
|
+
matrix = arg
|
|
71
|
+
new_args.append(matrix.spmatrix.data)
|
|
72
|
+
else:
|
|
73
|
+
if isinstance(arg, np.ndarray):
|
|
74
|
+
make_dense = True
|
|
75
|
+
new_args.append(arg)
|
|
76
|
+
|
|
77
|
+
spmatrix = matrix.spmatrix
|
|
78
|
+
if make_dense:
|
|
79
|
+
new_args = [arg.toarray() if hasattr(arg, "spmatrix") else arg for arg in args]
|
|
80
|
+
|
|
81
|
+
xp = get_array_module(spmatrix)
|
|
82
|
+
try:
|
|
83
|
+
new_data = getattr(xp, method)(*new_args, **kwargs)
|
|
84
|
+
except AttributeError:
|
|
85
|
+
if xp is np:
|
|
86
|
+
from scipy import special
|
|
87
|
+
else:
|
|
88
|
+
from cupyx.scipy import special
|
|
89
|
+
new_data = getattr(special, method)(*new_args, **kwargs)
|
|
90
|
+
|
|
91
|
+
if not make_dense:
|
|
92
|
+
new_spmatrix = get_sparse_module(spmatrix).csr_matrix(
|
|
93
|
+
(new_data, spmatrix.indices, spmatrix.indptr), spmatrix.shape
|
|
94
|
+
)
|
|
95
|
+
else:
|
|
96
|
+
new_spmatrix = get_sparse_module(spmatrix).csr_matrix(new_data)
|
|
97
|
+
return SparseNDArray(new_spmatrix, shape=matrix.shape)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class SparseArray(SparseNDArray):
|
|
101
|
+
__slots__ = ("spmatrix",)
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def ndim(self):
|
|
105
|
+
return len(self.shape)
|
|
106
|
+
|
|
107
|
+
def tocsr(self):
|
|
108
|
+
return self
|
|
109
|
+
|
|
110
|
+
def toarray(self):
|
|
111
|
+
if self.shape != self.spmatrix.shape:
|
|
112
|
+
return self.spmatrix.toarray().reshape(self.shape)
|
|
113
|
+
else:
|
|
114
|
+
return self.spmatrix.toarray()
|
|
115
|
+
|
|
116
|
+
def todense(self):
|
|
117
|
+
return self.toarray()
|
|
118
|
+
|
|
119
|
+
def ascupy(self):
|
|
120
|
+
is_cp = get_array_module(self.spmatrix) is cp
|
|
121
|
+
if is_cp:
|
|
122
|
+
return self
|
|
123
|
+
mat_tuple = (
|
|
124
|
+
cp.asarray(self.data),
|
|
125
|
+
cp.asarray(self.indices),
|
|
126
|
+
cp.asarray(self.indptr),
|
|
127
|
+
)
|
|
128
|
+
return SparseNDArray(
|
|
129
|
+
cps.csr_matrix(mat_tuple, shape=self.spmatrix.shape), shape=self.shape
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
def asscipy(self):
|
|
133
|
+
is_cp = get_array_module(self.spmatrix) is cp
|
|
134
|
+
if not is_cp:
|
|
135
|
+
return self
|
|
136
|
+
return SparseNDArray(self.spmatrix.get(), shape=self.shape)
|
|
137
|
+
|
|
138
|
+
def __array__(self, dtype=None):
|
|
139
|
+
x = self.toarray()
|
|
140
|
+
if dtype and x.dtype != dtype:
|
|
141
|
+
return x.astype(dtype)
|
|
142
|
+
return x
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
def nbytes(self):
|
|
146
|
+
return (
|
|
147
|
+
self.spmatrix.data.nbytes
|
|
148
|
+
+ self.spmatrix.indptr.nbytes
|
|
149
|
+
+ self.spmatrix.indices.nbytes
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
@property
|
|
153
|
+
def raw(self):
|
|
154
|
+
return self.spmatrix
|
|
155
|
+
|
|
156
|
+
@property
|
|
157
|
+
def data(self):
|
|
158
|
+
return self.spmatrix.data
|
|
159
|
+
|
|
160
|
+
@property
|
|
161
|
+
def indptr(self):
|
|
162
|
+
return self.spmatrix.indptr
|
|
163
|
+
|
|
164
|
+
@property
|
|
165
|
+
def indices(self):
|
|
166
|
+
return self.spmatrix.indices
|
|
167
|
+
|
|
168
|
+
@property
|
|
169
|
+
def nnz(self):
|
|
170
|
+
return self.spmatrix.nnz
|
|
171
|
+
|
|
172
|
+
@property
|
|
173
|
+
def shape(self):
|
|
174
|
+
raise self.spmatrix.shape
|
|
175
|
+
|
|
176
|
+
@property
|
|
177
|
+
def dtype(self):
|
|
178
|
+
return self.spmatrix.dtype
|
|
179
|
+
|
|
180
|
+
def copy(self):
|
|
181
|
+
return SparseNDArray(self.spmatrix.copy(), shape=self.shape)
|
|
182
|
+
|
|
183
|
+
@property
|
|
184
|
+
def real(self):
|
|
185
|
+
xps = get_sparse_module(self.spmatrix)
|
|
186
|
+
return SparseNDArray(
|
|
187
|
+
xps.csr_matrix(
|
|
188
|
+
(self.spmatrix.data.real, self.spmatrix.indices, self.spmatrix.indptr),
|
|
189
|
+
self.spmatrix.shape,
|
|
190
|
+
),
|
|
191
|
+
shape=self.shape,
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
@real.setter
|
|
195
|
+
def real(self, r):
|
|
196
|
+
xps = get_sparse_module(self.spmatrix)
|
|
197
|
+
x = self.spmatrix.toarray()
|
|
198
|
+
if issparse(r):
|
|
199
|
+
r = r.toarray()
|
|
200
|
+
x.real = r
|
|
201
|
+
self.spmatrix = xps.csr_matrix(x)
|
|
202
|
+
|
|
203
|
+
@property
|
|
204
|
+
def imag(self):
|
|
205
|
+
xps = get_sparse_module(self.spmatrix)
|
|
206
|
+
return SparseNDArray(
|
|
207
|
+
xps.csr_matrix(
|
|
208
|
+
(self.spmatrix.data.imag, self.spmatrix.indices, self.spmatrix.indptr),
|
|
209
|
+
self.spmatrix.shape,
|
|
210
|
+
),
|
|
211
|
+
shape=self.shape,
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
@imag.setter
|
|
215
|
+
def imag(self, imag):
|
|
216
|
+
xps = get_sparse_module(self.spmatrix)
|
|
217
|
+
x = self.spmatrix.toarray()
|
|
218
|
+
if issparse(imag):
|
|
219
|
+
imag = imag.toarray()
|
|
220
|
+
x.imag = imag
|
|
221
|
+
self.spmatrix = xps.csr_matrix(x)
|
|
222
|
+
|
|
223
|
+
def __getattr__(self, attr):
|
|
224
|
+
is_cp = get_array_module(self.spmatrix) is cp
|
|
225
|
+
if attr == "device" and is_cp:
|
|
226
|
+
try:
|
|
227
|
+
return self.spmatrix.device
|
|
228
|
+
except NotImplementedError:
|
|
229
|
+
return cp.cuda.Device(0)
|
|
230
|
+
if attr == "get" and is_cp:
|
|
231
|
+
return lambda: SparseNDArray(self.spmatrix.get(), shape=self.shape)
|
|
232
|
+
|
|
233
|
+
return super().__getattribute__(attr)
|
|
234
|
+
|
|
235
|
+
def __getstate__(self):
|
|
236
|
+
return self.spmatrix
|
|
237
|
+
|
|
238
|
+
def __setstate__(self, state):
|
|
239
|
+
self.spmatrix = state
|
|
240
|
+
|
|
241
|
+
def astype(self, dtype, **_):
|
|
242
|
+
dtype = np.dtype(dtype)
|
|
243
|
+
if self.dtype == dtype:
|
|
244
|
+
return self
|
|
245
|
+
return SparseNDArray(self.spmatrix.astype(dtype), shape=self.shape)
|
|
246
|
+
|
|
247
|
+
def transpose(self, axes=None):
|
|
248
|
+
raise NotImplementedError
|
|
249
|
+
|
|
250
|
+
def swapaxes(self, axis1, axis2):
|
|
251
|
+
if axis1 == 0 and axis2 == 1:
|
|
252
|
+
return self
|
|
253
|
+
|
|
254
|
+
assert axis1 == 1 and axis2 == 0
|
|
255
|
+
return self.transpose()
|
|
256
|
+
|
|
257
|
+
def reshape(self, shape, **_):
|
|
258
|
+
sp_shape = shape if len(shape) == 2 else (1, shape[0])
|
|
259
|
+
spmatrix = self.spmatrix.tolil().reshape(sp_shape)
|
|
260
|
+
return SparseNDArray(spmatrix, shape=shape)
|
|
261
|
+
|
|
262
|
+
def broadcast_to(self, shape):
|
|
263
|
+
# TODO(jisheng): implement broadcast_to
|
|
264
|
+
raise NotImplementedError
|
|
265
|
+
|
|
266
|
+
def squeeze(self, axis=None):
|
|
267
|
+
# TODO(jisheng): implement squeeze
|
|
268
|
+
raise NotImplementedError
|
|
269
|
+
|
|
270
|
+
@property
|
|
271
|
+
def T(self):
|
|
272
|
+
raise NotImplementedError
|
|
273
|
+
|
|
274
|
+
# ---------------- arithmetic ----------------------
|
|
275
|
+
|
|
276
|
+
def __add__(self, other):
|
|
277
|
+
try:
|
|
278
|
+
naked_other = naked(other)
|
|
279
|
+
except TypeError:
|
|
280
|
+
return NotImplemented
|
|
281
|
+
other_xp = get_array_module(naked_other)
|
|
282
|
+
if other_xp.isscalar(naked_other):
|
|
283
|
+
return call_sparse("add", self, naked_other)
|
|
284
|
+
if issparse(naked_other):
|
|
285
|
+
x = self.spmatrix + naked_other
|
|
286
|
+
else:
|
|
287
|
+
x = self.toarray() + naked_other
|
|
288
|
+
if issparse(x):
|
|
289
|
+
return SparseNDArray(x, shape=self.shape)
|
|
290
|
+
return get_array_module(x).asarray(x)
|
|
291
|
+
|
|
292
|
+
def __radd__(self, other):
|
|
293
|
+
try:
|
|
294
|
+
naked_other = naked(other)
|
|
295
|
+
except TypeError:
|
|
296
|
+
return NotImplemented
|
|
297
|
+
other_xp = get_array_module(naked_other)
|
|
298
|
+
if other_xp.isscalar(naked_other):
|
|
299
|
+
return call_sparse("add", naked_other, self)
|
|
300
|
+
if issparse(naked_other):
|
|
301
|
+
x = self.spmatrix + naked_other
|
|
302
|
+
else:
|
|
303
|
+
x = self.toarray() + naked_other
|
|
304
|
+
if issparse(x):
|
|
305
|
+
return SparseNDArray(x, shape=self.shape)
|
|
306
|
+
return get_array_module(x).asarray(x)
|
|
307
|
+
|
|
308
|
+
def __sub__(self, other):
|
|
309
|
+
try:
|
|
310
|
+
naked_other = naked(other)
|
|
311
|
+
except TypeError:
|
|
312
|
+
return NotImplemented
|
|
313
|
+
other_xp = get_array_module(naked_other)
|
|
314
|
+
if other_xp.isscalar(naked_other):
|
|
315
|
+
return call_sparse("subtract", self, naked_other)
|
|
316
|
+
if issparse(naked_other):
|
|
317
|
+
x = self.spmatrix - naked_other
|
|
318
|
+
else:
|
|
319
|
+
x = self.toarray() - naked_other
|
|
320
|
+
if issparse(x):
|
|
321
|
+
return SparseNDArray(x, shape=self.shape)
|
|
322
|
+
return get_array_module(x).asarray(x)
|
|
323
|
+
|
|
324
|
+
def __rsub__(self, other):
|
|
325
|
+
try:
|
|
326
|
+
naked_other = naked(other)
|
|
327
|
+
except TypeError:
|
|
328
|
+
return NotImplemented
|
|
329
|
+
other_xp = get_array_module(naked_other)
|
|
330
|
+
if other_xp.isscalar(naked_other):
|
|
331
|
+
return call_sparse("subtract", naked_other, self)
|
|
332
|
+
if issparse(naked_other):
|
|
333
|
+
x = naked_other - self.spmatrix
|
|
334
|
+
else:
|
|
335
|
+
x = naked_other - self.toarray()
|
|
336
|
+
if issparse(x):
|
|
337
|
+
return SparseNDArray(x, shape=self.shape)
|
|
338
|
+
return get_array_module(x).asarray(x)
|
|
339
|
+
|
|
340
|
+
def __mul__(self, other):
|
|
341
|
+
try:
|
|
342
|
+
naked_other = naked(other)
|
|
343
|
+
except TypeError:
|
|
344
|
+
return NotImplemented
|
|
345
|
+
if is_cupy(self.spmatrix):
|
|
346
|
+
if not cp.isscalar(naked_other):
|
|
347
|
+
# TODO(jisheng): cupy does not implement multiply method
|
|
348
|
+
is_other_sparse = issparse(naked_other)
|
|
349
|
+
if (
|
|
350
|
+
is_other_sparse
|
|
351
|
+
and self.spmatrix.nnz == naked_other.nnz
|
|
352
|
+
and cp.all(self.spmatrix.indptr == naked_other.indptr)
|
|
353
|
+
and cp.all(self.spmatrix.indices == naked_other.indices)
|
|
354
|
+
):
|
|
355
|
+
x = cps.csr_matrix(
|
|
356
|
+
(
|
|
357
|
+
self.spmatrix.data * naked_other.data,
|
|
358
|
+
self.spmatrix.indices,
|
|
359
|
+
self.spmatrix.indptr,
|
|
360
|
+
),
|
|
361
|
+
self.spmatrix.shape,
|
|
362
|
+
)
|
|
363
|
+
else:
|
|
364
|
+
if is_other_sparse:
|
|
365
|
+
naked_other = other.toarray()
|
|
366
|
+
dense = self.spmatrix.toarray()
|
|
367
|
+
res = cp.multiply(dense, naked_other, out=dense)
|
|
368
|
+
x = cps.csr_matrix(res)
|
|
369
|
+
else:
|
|
370
|
+
x = self.spmatrix * naked_other
|
|
371
|
+
else:
|
|
372
|
+
x = self.spmatrix.multiply(naked_other)
|
|
373
|
+
if issparse(x):
|
|
374
|
+
return SparseNDArray(x, shape=self.shape)
|
|
375
|
+
return get_array_module(x).asarray(x)
|
|
376
|
+
|
|
377
|
+
def __rmul__(self, other):
|
|
378
|
+
try:
|
|
379
|
+
naked_other = naked(other)
|
|
380
|
+
except TypeError:
|
|
381
|
+
return NotImplemented
|
|
382
|
+
if is_cupy(self.spmatrix):
|
|
383
|
+
if not cp.isscalar(naked_other):
|
|
384
|
+
# TODO(jisheng): cupy does not implement multiply method
|
|
385
|
+
is_other_sparse = issparse(naked_other)
|
|
386
|
+
if (
|
|
387
|
+
is_other_sparse
|
|
388
|
+
and self.spmatrix.nnz == naked_other.nnz
|
|
389
|
+
and cp.all(self.spmatrix.indptr == naked_other.indptr)
|
|
390
|
+
and cp.all(self.spmatrix.indices == naked_other.indices)
|
|
391
|
+
):
|
|
392
|
+
x = cps.csr_matrix(
|
|
393
|
+
(
|
|
394
|
+
naked_other.data * self.spmatrix.data,
|
|
395
|
+
self.spmatrix.indices,
|
|
396
|
+
self.spmatrix.indptr,
|
|
397
|
+
),
|
|
398
|
+
self.spmatrix.shape,
|
|
399
|
+
)
|
|
400
|
+
else:
|
|
401
|
+
if is_other_sparse:
|
|
402
|
+
naked_other = other.toarray()
|
|
403
|
+
dense = self.spmatrix.toarray()
|
|
404
|
+
res = cp.multiply(naked_other, dense, out=dense)
|
|
405
|
+
x = cps.csr_matrix(res)
|
|
406
|
+
else:
|
|
407
|
+
x = naked_other * self.spmatrix
|
|
408
|
+
else:
|
|
409
|
+
x = self.spmatrix.multiply(naked_other)
|
|
410
|
+
if issparse(x):
|
|
411
|
+
return SparseNDArray(x, shape=self.shape)
|
|
412
|
+
return get_array_module(x).asarray(x)
|
|
413
|
+
|
|
414
|
+
def __matmul__(self, other):
|
|
415
|
+
from . import matmul
|
|
416
|
+
|
|
417
|
+
return matmul(self, other)
|
|
418
|
+
|
|
419
|
+
def __rmatmul__(self, other):
|
|
420
|
+
from . import matmul
|
|
421
|
+
|
|
422
|
+
return matmul(other, self)
|
|
423
|
+
|
|
424
|
+
def __div__(self, other):
|
|
425
|
+
return self.__truediv__(other)
|
|
426
|
+
|
|
427
|
+
def __rdiv__(self, other):
|
|
428
|
+
return self.__rtruediv__(other)
|
|
429
|
+
|
|
430
|
+
def __truediv__(self, other):
|
|
431
|
+
try:
|
|
432
|
+
naked_other = naked(other)
|
|
433
|
+
except TypeError:
|
|
434
|
+
return NotImplemented
|
|
435
|
+
x = self.spmatrix / naked_other
|
|
436
|
+
if issparse(x):
|
|
437
|
+
return SparseNDArray(x, shape=self.shape)
|
|
438
|
+
return get_array_module(x).asarray(x)
|
|
439
|
+
|
|
440
|
+
def __rtruediv__(self, other):
|
|
441
|
+
try:
|
|
442
|
+
naked_other = naked(other)
|
|
443
|
+
except TypeError:
|
|
444
|
+
return NotImplemented
|
|
445
|
+
try:
|
|
446
|
+
x = naked_other / self.spmatrix
|
|
447
|
+
except TypeError:
|
|
448
|
+
x = naked_other / self.spmatrix.toarray()
|
|
449
|
+
if issparse(x):
|
|
450
|
+
return SparseNDArray(x, shape=self.shape)
|
|
451
|
+
return get_array_module(x).asarray(x)
|
|
452
|
+
|
|
453
|
+
def __floordiv__(self, other):
|
|
454
|
+
try:
|
|
455
|
+
naked_other = naked(other)
|
|
456
|
+
except TypeError:
|
|
457
|
+
return NotImplemented
|
|
458
|
+
other_xp = get_array_module(naked_other)
|
|
459
|
+
if other_xp.isscalar(naked_other):
|
|
460
|
+
return call_sparse("floor_divide", self, naked_other)
|
|
461
|
+
else:
|
|
462
|
+
if issparse(naked_other):
|
|
463
|
+
naked_other = other.toarray()
|
|
464
|
+
x = get_sparse_module(self.spmatrix).csr_matrix(
|
|
465
|
+
self.toarray() // naked_other
|
|
466
|
+
)
|
|
467
|
+
else:
|
|
468
|
+
x = self.toarray() // naked_other
|
|
469
|
+
if issparse(x):
|
|
470
|
+
return SparseNDArray(x, shape=self.shape)
|
|
471
|
+
return get_array_module(x).asarray(x)
|
|
472
|
+
|
|
473
|
+
def __rfloordiv__(self, other):
|
|
474
|
+
try:
|
|
475
|
+
naked_other = naked(other)
|
|
476
|
+
except TypeError:
|
|
477
|
+
return NotImplemented
|
|
478
|
+
other_xp = get_array_module(naked_other)
|
|
479
|
+
if other_xp.isscalar(naked_other):
|
|
480
|
+
return call_sparse("floor_divide", naked_other, self)
|
|
481
|
+
else:
|
|
482
|
+
if issparse(naked_other):
|
|
483
|
+
naked_other = other.toarray()
|
|
484
|
+
x = get_sparse_module(self.spmatrix).csr_matrix(
|
|
485
|
+
naked_other // self.toarray()
|
|
486
|
+
)
|
|
487
|
+
else:
|
|
488
|
+
x = naked_other // self.toarray()
|
|
489
|
+
if issparse(x):
|
|
490
|
+
return SparseNDArray(x, shape=self.shape)
|
|
491
|
+
return get_array_module(x).asarray(x)
|
|
492
|
+
|
|
493
|
+
def __pow__(self, other, modulo=None):
|
|
494
|
+
if modulo is not None:
|
|
495
|
+
return NotImplemented
|
|
496
|
+
|
|
497
|
+
try:
|
|
498
|
+
naked_other = naked(other)
|
|
499
|
+
except TypeError:
|
|
500
|
+
return NotImplemented
|
|
501
|
+
if get_array_module(naked_other).isscalar(naked_other):
|
|
502
|
+
try:
|
|
503
|
+
x = self.spmatrix.power(naked_other)
|
|
504
|
+
except ValueError as e: # pragma: no cover
|
|
505
|
+
# https://github.com/scipy/scipy/issues/8678
|
|
506
|
+
assert "WRITEBACKIFCOPY" in e.args[0]
|
|
507
|
+
self.spmatrix = self.spmatrix.copy()
|
|
508
|
+
x = self.spmatrix.power(naked_other)
|
|
509
|
+
else:
|
|
510
|
+
if issparse(naked_other):
|
|
511
|
+
naked_other = other.toarray()
|
|
512
|
+
x = self.toarray() ** naked_other
|
|
513
|
+
if issparse(x):
|
|
514
|
+
return SparseNDArray(x, shape=self.shape)
|
|
515
|
+
return get_array_module(x).asarray(x)
|
|
516
|
+
|
|
517
|
+
def __rpow__(self, other):
|
|
518
|
+
try:
|
|
519
|
+
naked_other = naked(other)
|
|
520
|
+
except TypeError:
|
|
521
|
+
return NotImplemented
|
|
522
|
+
if issparse(naked_other):
|
|
523
|
+
naked_other = other.toarray()
|
|
524
|
+
x = naked_other ** self.toarray()
|
|
525
|
+
return get_array_module(x).asarray(x)
|
|
526
|
+
|
|
527
|
+
def float_power(self, other):
|
|
528
|
+
ret = self.__pow__(other)
|
|
529
|
+
ret = naked(ret).astype(float)
|
|
530
|
+
if issparse(ret):
|
|
531
|
+
return SparseNDArray(ret, shape=self.shape)
|
|
532
|
+
return ret
|
|
533
|
+
|
|
534
|
+
def __mod__(self, other):
|
|
535
|
+
try:
|
|
536
|
+
naked_other = naked(other)
|
|
537
|
+
except TypeError:
|
|
538
|
+
return NotImplemented
|
|
539
|
+
if get_array_module(naked_other).isscalar(naked_other):
|
|
540
|
+
data = self.spmatrix.data % naked_other
|
|
541
|
+
x = get_sparse_module(self.spmatrix).csr_matrix(
|
|
542
|
+
(data, self.spmatrix.indices, self.spmatrix.indptr), self.spmatrix.shape
|
|
543
|
+
)
|
|
544
|
+
else:
|
|
545
|
+
if issparse(naked_other):
|
|
546
|
+
naked_other = other.toarray()
|
|
547
|
+
x = get_sparse_module(self.spmatrix).csr_matrix(
|
|
548
|
+
self.toarray() % naked_other
|
|
549
|
+
)
|
|
550
|
+
if issparse(x):
|
|
551
|
+
return SparseNDArray(x, shape=self.shape)
|
|
552
|
+
return get_array_module(x).asarray(x)
|
|
553
|
+
|
|
554
|
+
def __rmod__(self, other):
|
|
555
|
+
try:
|
|
556
|
+
naked_other = naked(other)
|
|
557
|
+
except TypeError:
|
|
558
|
+
return NotImplemented
|
|
559
|
+
is_sparse = issparse(naked_other)
|
|
560
|
+
if issparse(naked_other):
|
|
561
|
+
naked_other = other.toarray()
|
|
562
|
+
if get_array_module(naked_other).isscalar(naked_other):
|
|
563
|
+
data = naked_other % self.spmatrix.data
|
|
564
|
+
x = get_sparse_module(self.spmatrix).csr_matrix(
|
|
565
|
+
(data, self.spmatrix.indices, self.spmatrix.indptr), self.spmatrix.shape
|
|
566
|
+
)
|
|
567
|
+
else:
|
|
568
|
+
x = naked_other % self.toarray()
|
|
569
|
+
if is_sparse:
|
|
570
|
+
x = get_sparse_module(self.spmatrix).csr_matrix(x)
|
|
571
|
+
if issparse(x):
|
|
572
|
+
return SparseNDArray(x, shape=self.shape)
|
|
573
|
+
return get_array_module(x).asarray(x)
|
|
574
|
+
|
|
575
|
+
def fmod(self, other):
|
|
576
|
+
try:
|
|
577
|
+
naked_other = naked(other)
|
|
578
|
+
except TypeError:
|
|
579
|
+
return NotImplemented
|
|
580
|
+
|
|
581
|
+
xp = get_array_module(self.spmatrix)
|
|
582
|
+
if get_array_module(naked_other).isscalar(naked_other):
|
|
583
|
+
return call_sparse("fmod", self, naked_other)
|
|
584
|
+
else:
|
|
585
|
+
if issparse(naked_other):
|
|
586
|
+
naked_other = other.toarray()
|
|
587
|
+
x = get_sparse_module(self.spmatrix).csr_matrix(
|
|
588
|
+
xp.fmod(self.toarray(), naked_other)
|
|
589
|
+
)
|
|
590
|
+
if issparse(x):
|
|
591
|
+
return SparseNDArray(x, shape=self.shape)
|
|
592
|
+
return get_array_module(x).asarray(x)
|
|
593
|
+
|
|
594
|
+
def logaddexp(self, other):
|
|
595
|
+
try:
|
|
596
|
+
naked_other = naked(other)
|
|
597
|
+
except TypeError:
|
|
598
|
+
return NotImplemented
|
|
599
|
+
|
|
600
|
+
xp = get_array_module(self.spmatrix)
|
|
601
|
+
if get_array_module(naked_other).isscalar(naked_other):
|
|
602
|
+
return call_sparse("logaddexp", self, naked_other)
|
|
603
|
+
if issparse(naked_other):
|
|
604
|
+
naked_other = other.toarray()
|
|
605
|
+
return xp.logaddexp(self.toarray(), naked_other)
|
|
606
|
+
|
|
607
|
+
def logaddexp2(self, other):
|
|
608
|
+
try:
|
|
609
|
+
naked_other = naked(other)
|
|
610
|
+
except TypeError:
|
|
611
|
+
return NotImplemented
|
|
612
|
+
|
|
613
|
+
xp = get_array_module(self.spmatrix)
|
|
614
|
+
if get_array_module(naked_other).isscalar(naked_other):
|
|
615
|
+
return call_sparse("logaddexp2", self, naked_other)
|
|
616
|
+
if issparse(naked_other):
|
|
617
|
+
naked_other = other.toarray()
|
|
618
|
+
return xp.logaddexp2(self.toarray(), naked_other)
|
|
619
|
+
|
|
620
|
+
def __neg__(self):
|
|
621
|
+
return SparseNDArray(-self.spmatrix, shape=self.shape)
|
|
622
|
+
|
|
623
|
+
def __pos__(self):
|
|
624
|
+
return SparseNDArray(self.spmatrix.copy(), shape=self.shape)
|
|
625
|
+
|
|
626
|
+
def __abs__(self):
|
|
627
|
+
return SparseNDArray(abs(self.spmatrix), shape=self.shape)
|
|
628
|
+
|
|
629
|
+
def fabs(self):
|
|
630
|
+
xp = get_array_module(self.spmatrix)
|
|
631
|
+
return SparseNDArray(
|
|
632
|
+
get_sparse_module(self.spmatrix).csr_matrix(
|
|
633
|
+
xp.abs(self.spmatrix), dtype="f8"
|
|
634
|
+
),
|
|
635
|
+
shape=self.shape,
|
|
636
|
+
)
|
|
637
|
+
|
|
638
|
+
def rint(self):
|
|
639
|
+
return SparseNDArray(self.spmatrix.rint(), shape=self.shape)
|
|
640
|
+
|
|
641
|
+
def sign(self):
|
|
642
|
+
return SparseNDArray(self.spmatrix.sign(), shape=self.shape)
|
|
643
|
+
|
|
644
|
+
def conj(self):
|
|
645
|
+
return SparseNDArray(self.spmatrix.conj(), shape=self.shape)
|
|
646
|
+
|
|
647
|
+
def exp(self):
|
|
648
|
+
return call_sparse("exp", self)
|
|
649
|
+
|
|
650
|
+
def exp2(self):
|
|
651
|
+
return call_sparse("exp2", self)
|
|
652
|
+
|
|
653
|
+
def log(self):
|
|
654
|
+
return call_sparse("log", self)
|
|
655
|
+
|
|
656
|
+
def log2(self):
|
|
657
|
+
return call_sparse("log2", self)
|
|
658
|
+
|
|
659
|
+
def log10(self):
|
|
660
|
+
return call_sparse("log10", self)
|
|
661
|
+
|
|
662
|
+
def expm1(self):
|
|
663
|
+
return SparseNDArray(self.spmatrix.expm1(), shape=self.shape)
|
|
664
|
+
|
|
665
|
+
def log1p(self):
|
|
666
|
+
return SparseNDArray(self.spmatrix.log1p(), shape=self.shape)
|
|
667
|
+
|
|
668
|
+
def sqrt(self):
|
|
669
|
+
return SparseNDArray(self.spmatrix.sqrt(), shape=self.shape)
|
|
670
|
+
|
|
671
|
+
def square(self):
|
|
672
|
+
return call_sparse("square", self)
|
|
673
|
+
|
|
674
|
+
def cbrt(self):
|
|
675
|
+
return call_sparse("cbrt", self)
|
|
676
|
+
|
|
677
|
+
def reciprocal(self):
|
|
678
|
+
return call_sparse("reciprocal", self)
|
|
679
|
+
|
|
680
|
+
def _scipy_unary(self, func_name):
|
|
681
|
+
spmatrix = self.spmatrix
|
|
682
|
+
xp = get_array_module(spmatrix)
|
|
683
|
+
if xp is np:
|
|
684
|
+
from scipy import special
|
|
685
|
+
else:
|
|
686
|
+
from cupyx.scipy import special
|
|
687
|
+
|
|
688
|
+
new_data = getattr(special, func_name)(spmatrix.data)
|
|
689
|
+
new_spmatrix = get_sparse_module(spmatrix).csr_matrix(
|
|
690
|
+
(new_data, spmatrix.indices, spmatrix.indptr), spmatrix.shape
|
|
691
|
+
)
|
|
692
|
+
return SparseNDArray(new_spmatrix, shape=self.shape)
|
|
693
|
+
|
|
694
|
+
def _scipy_binary(self, func_name, other):
|
|
695
|
+
try:
|
|
696
|
+
naked_other = naked(other)
|
|
697
|
+
except TypeError: # pragma: no cover
|
|
698
|
+
return NotImplemented
|
|
699
|
+
|
|
700
|
+
xp = get_array_module(self.spmatrix)
|
|
701
|
+
|
|
702
|
+
if xp is np:
|
|
703
|
+
from scipy import special
|
|
704
|
+
else: # pragma: no cover
|
|
705
|
+
from cupyx.scipy import special
|
|
706
|
+
|
|
707
|
+
func = getattr(special, func_name)
|
|
708
|
+
|
|
709
|
+
if get_array_module(naked_other).isscalar(naked_other): # pragma: no cover
|
|
710
|
+
return call_sparse(func, self, naked_other)
|
|
711
|
+
else:
|
|
712
|
+
if issparse(naked_other): # pragma: no cover
|
|
713
|
+
naked_other = other.toarray()
|
|
714
|
+
x = get_sparse_module(self.spmatrix).csr_matrix(
|
|
715
|
+
func(self.toarray(), naked_other)
|
|
716
|
+
)
|
|
717
|
+
if issparse(x):
|
|
718
|
+
return SparseNDArray(x, shape=self.shape)
|
|
719
|
+
return get_array_module(x).asarray(x)
|
|
720
|
+
|
|
721
|
+
gamma = partialmethod(_scipy_unary, "gamma")
|
|
722
|
+
gammaln = partialmethod(_scipy_unary, "gammaln")
|
|
723
|
+
loggamma = partialmethod(_scipy_unary, "loggamma")
|
|
724
|
+
gammasgn = partialmethod(_scipy_unary, "gammasgn")
|
|
725
|
+
gammainc = partialmethod(_scipy_binary, "gammainc")
|
|
726
|
+
gammaincinv = partialmethod(_scipy_binary, "gammaincinv")
|
|
727
|
+
gammaincc = partialmethod(_scipy_binary, "gammaincc")
|
|
728
|
+
gammainccinv = partialmethod(_scipy_binary, "gammainccinv")
|
|
729
|
+
beta = partialmethod(_scipy_binary, "beta")
|
|
730
|
+
betaln = partialmethod(_scipy_binary, "betaln")
|
|
731
|
+
psi = partialmethod(_scipy_unary, "psi")
|
|
732
|
+
rgamma = partialmethod(_scipy_unary, "rgamma")
|
|
733
|
+
polygamma = partialmethod(_scipy_binary, "polygamma")
|
|
734
|
+
multigammaln = partialmethod(_scipy_binary, "multigammaln")
|
|
735
|
+
digamma = partialmethod(_scipy_unary, "digamma")
|
|
736
|
+
poch = partialmethod(_scipy_binary, "poch")
|
|
737
|
+
|
|
738
|
+
erf = partialmethod(_scipy_unary, "erf")
|
|
739
|
+
erfc = partialmethod(_scipy_unary, "erfc")
|
|
740
|
+
erfcx = partialmethod(_scipy_unary, "erfcx")
|
|
741
|
+
erfi = partialmethod(_scipy_unary, "erfi")
|
|
742
|
+
erfinv = partialmethod(_scipy_unary, "erfinv")
|
|
743
|
+
erfcinv = partialmethod(_scipy_unary, "erfcinv")
|
|
744
|
+
wofz = partialmethod(_scipy_unary, "wofz")
|
|
745
|
+
dawsn = partialmethod(_scipy_unary, "dawsn")
|
|
746
|
+
entr = partialmethod(_scipy_unary, "entr")
|
|
747
|
+
|
|
748
|
+
ellipk = partialmethod(_scipy_unary, "ellipk")
|
|
749
|
+
ellipkm1 = partialmethod(_scipy_unary, "ellipkm1")
|
|
750
|
+
ellipkinc = partialmethod(_scipy_binary, "ellipkinc")
|
|
751
|
+
ellipe = partialmethod(_scipy_unary, "ellipe")
|
|
752
|
+
ellipeinc = partialmethod(_scipy_binary, "ellipeinc")
|
|
753
|
+
elliprc = partialmethod(_scipy_binary, "elliprc")
|
|
754
|
+
|
|
755
|
+
rel_entr = partialmethod(_scipy_binary, "rel_entr")
|
|
756
|
+
kl_div = partialmethod(_scipy_binary, "kl_div")
|
|
757
|
+
xlogy = partialmethod(_scipy_binary, "xlogy")
|
|
758
|
+
|
|
759
|
+
jv = partialmethod(_scipy_binary, "jv")
|
|
760
|
+
jve = partialmethod(_scipy_binary, "jve")
|
|
761
|
+
yn = partialmethod(_scipy_binary, "yn")
|
|
762
|
+
yv = partialmethod(_scipy_binary, "yv")
|
|
763
|
+
yve = partialmethod(_scipy_binary, "yve")
|
|
764
|
+
kn = partialmethod(_scipy_binary, "kn")
|
|
765
|
+
kv = partialmethod(_scipy_binary, "kv")
|
|
766
|
+
kve = partialmethod(_scipy_binary, "kve")
|
|
767
|
+
iv = partialmethod(_scipy_binary, "iv")
|
|
768
|
+
ive = partialmethod(_scipy_binary, "ive")
|
|
769
|
+
hankel1 = partialmethod(_scipy_binary, "hankel1")
|
|
770
|
+
hankel1e = partialmethod(_scipy_binary, "hankel1e")
|
|
771
|
+
hankel2 = partialmethod(_scipy_binary, "hankel2")
|
|
772
|
+
hankel2e = partialmethod(_scipy_binary, "hankel2e")
|
|
773
|
+
|
|
774
|
+
hyp0f1 = partialmethod(_scipy_binary, "hyp0f1")
|
|
775
|
+
|
|
776
|
+
airy = partialmethod(_scipy_unary, "airy")
|
|
777
|
+
airye = partialmethod(_scipy_unary, "airye")
|
|
778
|
+
itairy = partialmethod(_scipy_unary, "itairy")
|
|
779
|
+
|
|
780
|
+
def __eq__(self, other):
|
|
781
|
+
try:
|
|
782
|
+
naked_other = naked(other)
|
|
783
|
+
except TypeError:
|
|
784
|
+
return NotImplemented
|
|
785
|
+
|
|
786
|
+
if get_array_module(naked_other).isscalar(naked_other):
|
|
787
|
+
return call_sparse("equal", self, naked_other)
|
|
788
|
+
if is_cupy(self.spmatrix):
|
|
789
|
+
return NotImplemented
|
|
790
|
+
else:
|
|
791
|
+
if issparse(naked_other):
|
|
792
|
+
x = self.spmatrix == naked_other
|
|
793
|
+
else:
|
|
794
|
+
x = self.toarray() == other
|
|
795
|
+
if issparse(x):
|
|
796
|
+
return SparseNDArray(x, shape=self.shape)
|
|
797
|
+
return get_array_module(x).asarray(x)
|
|
798
|
+
|
|
799
|
+
def __ne__(self, other):
|
|
800
|
+
try:
|
|
801
|
+
naked_other = naked(other)
|
|
802
|
+
except TypeError:
|
|
803
|
+
return NotImplemented
|
|
804
|
+
|
|
805
|
+
if get_array_module(naked_other).isscalar(naked_other):
|
|
806
|
+
return call_sparse("not_equal", self, naked_other)
|
|
807
|
+
if is_cupy(self.spmatrix):
|
|
808
|
+
return NotImplemented
|
|
809
|
+
else:
|
|
810
|
+
if issparse(naked_other):
|
|
811
|
+
x = self.spmatrix != naked_other
|
|
812
|
+
else:
|
|
813
|
+
x = self.toarray() != other
|
|
814
|
+
if issparse(x):
|
|
815
|
+
return SparseNDArray(x, shape=self.shape)
|
|
816
|
+
return get_array_module(x).asarray(x)
|
|
817
|
+
|
|
818
|
+
def __lt__(self, other):
|
|
819
|
+
try:
|
|
820
|
+
naked_other = naked(other)
|
|
821
|
+
except TypeError:
|
|
822
|
+
return NotImplemented
|
|
823
|
+
|
|
824
|
+
if get_array_module(naked_other).isscalar(naked_other):
|
|
825
|
+
return call_sparse("less", self, naked_other)
|
|
826
|
+
if is_cupy(self.spmatrix):
|
|
827
|
+
return NotImplemented
|
|
828
|
+
else:
|
|
829
|
+
if issparse(naked_other):
|
|
830
|
+
x = self.spmatrix < naked_other
|
|
831
|
+
else:
|
|
832
|
+
x = self.toarray() < other
|
|
833
|
+
if issparse(x):
|
|
834
|
+
return SparseNDArray(x, shape=self.shape)
|
|
835
|
+
return get_array_module(x).asarray(x)
|
|
836
|
+
|
|
837
|
+
def __le__(self, other):
|
|
838
|
+
try:
|
|
839
|
+
naked_other = naked(other)
|
|
840
|
+
except TypeError:
|
|
841
|
+
return NotImplemented
|
|
842
|
+
|
|
843
|
+
if get_array_module(naked_other).isscalar(naked_other):
|
|
844
|
+
return call_sparse("less_equal", self, naked_other)
|
|
845
|
+
if is_cupy(self.spmatrix):
|
|
846
|
+
return NotImplemented
|
|
847
|
+
else:
|
|
848
|
+
if issparse(naked_other):
|
|
849
|
+
x = self.spmatrix <= naked_other
|
|
850
|
+
else:
|
|
851
|
+
x = self.toarray() <= other
|
|
852
|
+
if issparse(x):
|
|
853
|
+
return SparseNDArray(x, shape=self.shape)
|
|
854
|
+
return get_array_module(x).asarray(x)
|
|
855
|
+
|
|
856
|
+
def __gt__(self, other):
|
|
857
|
+
try:
|
|
858
|
+
naked_other = naked(other)
|
|
859
|
+
except TypeError:
|
|
860
|
+
return NotImplemented
|
|
861
|
+
|
|
862
|
+
if get_array_module(naked_other).isscalar(naked_other):
|
|
863
|
+
return call_sparse("greater", self, naked_other)
|
|
864
|
+
if is_cupy(self.spmatrix):
|
|
865
|
+
return NotImplemented
|
|
866
|
+
else:
|
|
867
|
+
if issparse(naked_other):
|
|
868
|
+
x = self.spmatrix > naked_other
|
|
869
|
+
else:
|
|
870
|
+
x = self.toarray() > other
|
|
871
|
+
if issparse(x):
|
|
872
|
+
return SparseNDArray(x, shape=self.shape)
|
|
873
|
+
return get_array_module(x).asarray(x)
|
|
874
|
+
|
|
875
|
+
def __ge__(self, other):
|
|
876
|
+
try:
|
|
877
|
+
naked_other = naked(other)
|
|
878
|
+
except TypeError:
|
|
879
|
+
return NotImplemented
|
|
880
|
+
|
|
881
|
+
if get_array_module(naked_other).isscalar(naked_other):
|
|
882
|
+
return call_sparse("greater_equal", self, naked_other)
|
|
883
|
+
if is_cupy(self.spmatrix):
|
|
884
|
+
return NotImplemented
|
|
885
|
+
else:
|
|
886
|
+
if issparse(naked_other):
|
|
887
|
+
x = self.spmatrix >= naked_other
|
|
888
|
+
else:
|
|
889
|
+
x = self.toarray() >= other
|
|
890
|
+
if issparse(x):
|
|
891
|
+
return SparseNDArray(x, shape=self.shape)
|
|
892
|
+
return get_array_module(x).asarray(x)
|
|
893
|
+
|
|
894
|
+
def logical_and(self, other):
|
|
895
|
+
try:
|
|
896
|
+
naked_other = naked(other)
|
|
897
|
+
except TypeError:
|
|
898
|
+
return NotImplemented
|
|
899
|
+
|
|
900
|
+
if is_cupy(self.spmatrix):
|
|
901
|
+
return NotImplemented
|
|
902
|
+
else:
|
|
903
|
+
other_xp = get_array_module(naked_other)
|
|
904
|
+
if other_xp.isscalar(naked_other):
|
|
905
|
+
naked_other = other_xp.array(naked_other).astype(bool)
|
|
906
|
+
else:
|
|
907
|
+
naked_other = naked_other.astype(bool)
|
|
908
|
+
x = self.spmatrix.astype(bool).multiply(naked_other)
|
|
909
|
+
if issparse(x):
|
|
910
|
+
return SparseNDArray(x, shape=self.shape)
|
|
911
|
+
return get_array_module(x).asarray(x)
|
|
912
|
+
|
|
913
|
+
def logical_or(self, other):
|
|
914
|
+
try:
|
|
915
|
+
naked_other = naked(other)
|
|
916
|
+
except TypeError:
|
|
917
|
+
return NotImplemented
|
|
918
|
+
|
|
919
|
+
if is_cupy(self.spmatrix):
|
|
920
|
+
return NotImplemented
|
|
921
|
+
else:
|
|
922
|
+
other_xp = get_array_module(naked_other)
|
|
923
|
+
if other_xp.isscalar(naked_other):
|
|
924
|
+
if naked_other != 0:
|
|
925
|
+
x = np.logical_and(self.toarray(), naked_other)
|
|
926
|
+
else:
|
|
927
|
+
x = self.spmatrix.astype(bool)
|
|
928
|
+
else:
|
|
929
|
+
naked_other = naked_other.astype(bool)
|
|
930
|
+
x = (self.spmatrix.astype(bool) + naked_other).astype(bool)
|
|
931
|
+
if issparse(x):
|
|
932
|
+
return SparseNDArray(x, shape=self.shape)
|
|
933
|
+
return get_array_module(x).asarray(x)
|
|
934
|
+
|
|
935
|
+
def logical_xor(self, other):
|
|
936
|
+
try:
|
|
937
|
+
naked_other = naked(other)
|
|
938
|
+
except TypeError:
|
|
939
|
+
return NotImplemented
|
|
940
|
+
|
|
941
|
+
if is_cupy(self.spmatrix):
|
|
942
|
+
return NotImplemented
|
|
943
|
+
else:
|
|
944
|
+
other_xp = get_array_module(naked_other)
|
|
945
|
+
if other_xp.isscalar(naked_other):
|
|
946
|
+
naked_other = other_xp.array(naked_other).astype(bool)
|
|
947
|
+
else:
|
|
948
|
+
naked_other = naked_other.astype(bool)
|
|
949
|
+
x = self.spmatrix.astype(bool) != naked_other
|
|
950
|
+
if issparse(x):
|
|
951
|
+
return SparseNDArray(x, shape=self.shape)
|
|
952
|
+
return get_array_module(x).asarray(x)
|
|
953
|
+
|
|
954
|
+
def logical_not(self):
|
|
955
|
+
return call_sparse("logical_not", self)
|
|
956
|
+
|
|
957
|
+
@staticmethod
|
|
958
|
+
def _bitwise(this, other, method_name):
|
|
959
|
+
try:
|
|
960
|
+
naked_this = naked(this)
|
|
961
|
+
except TypeError:
|
|
962
|
+
return NotImplemented
|
|
963
|
+
try:
|
|
964
|
+
naked_other = naked(other)
|
|
965
|
+
except TypeError:
|
|
966
|
+
return NotImplemented
|
|
967
|
+
|
|
968
|
+
if not issparse(naked_this):
|
|
969
|
+
return SparseArray._bitwise(naked_other, naked_this, method_name)
|
|
970
|
+
|
|
971
|
+
if issparse(naked_other):
|
|
972
|
+
naked_other = other.toarray()
|
|
973
|
+
|
|
974
|
+
xp = get_array_module(naked_this)
|
|
975
|
+
xps = get_sparse_module(naked_this)
|
|
976
|
+
return SparseNDArray(
|
|
977
|
+
xps.csr_matrix(getattr(xp, method_name)(this.toarray(), naked_other)),
|
|
978
|
+
shape=naked_this.shape,
|
|
979
|
+
)
|
|
980
|
+
|
|
981
|
+
def __and__(self, other):
|
|
982
|
+
if get_array_module(other).isscalar(other):
|
|
983
|
+
return call_sparse("bitwise_and", self, other)
|
|
984
|
+
return self._bitwise(self.spmatrix, other, "bitwise_and")
|
|
985
|
+
|
|
986
|
+
def __rand__(self, other):
|
|
987
|
+
if get_array_module(other).isscalar(other):
|
|
988
|
+
return call_sparse("bitwise_and", other, self)
|
|
989
|
+
return self._bitwise(other, self.spmatrix, "bitwise_and")
|
|
990
|
+
|
|
991
|
+
def __or__(self, other):
|
|
992
|
+
if get_array_module(other).isscalar(other):
|
|
993
|
+
return call_sparse("bitwise_or", self, other)
|
|
994
|
+
return self._bitwise(self.spmatrix, other, "bitwise_or")
|
|
995
|
+
|
|
996
|
+
def __ror__(self, other):
|
|
997
|
+
if get_array_module(other).isscalar(other):
|
|
998
|
+
return call_sparse("bitwise_or", other, self)
|
|
999
|
+
return self._bitwise(other, self.spmatrix, "bitwise_or")
|
|
1000
|
+
|
|
1001
|
+
def __xor__(self, other):
|
|
1002
|
+
if get_array_module(other).isscalar(other):
|
|
1003
|
+
return call_sparse("bitwise_xor", self, other)
|
|
1004
|
+
return self._bitwise(self.spmatrix, other, "bitwise_xor")
|
|
1005
|
+
|
|
1006
|
+
def __rxor__(self, other):
|
|
1007
|
+
if get_array_module(other).isscalar(other):
|
|
1008
|
+
return call_sparse("bitwise_xor", other, self)
|
|
1009
|
+
return self._bitwise(other, self.spmatrix, "bitwise_xor")
|
|
1010
|
+
|
|
1011
|
+
def isclose(self, other, **kw):
|
|
1012
|
+
try:
|
|
1013
|
+
naked_other = naked(other)
|
|
1014
|
+
except TypeError:
|
|
1015
|
+
return NotImplemented
|
|
1016
|
+
|
|
1017
|
+
xp = get_array_module(naked_other)
|
|
1018
|
+
if issparse(naked_other):
|
|
1019
|
+
naked_other = other.toarray()
|
|
1020
|
+
return xp.isclose(self.toarray(), naked_other, **kw)
|
|
1021
|
+
|
|
1022
|
+
def __invert__(self):
|
|
1023
|
+
return call_sparse("invert", self)
|
|
1024
|
+
|
|
1025
|
+
@staticmethod
|
|
1026
|
+
def _shift(this, other, method_name):
|
|
1027
|
+
try:
|
|
1028
|
+
naked_this = naked(this)
|
|
1029
|
+
except TypeError:
|
|
1030
|
+
return NotImplemented
|
|
1031
|
+
try:
|
|
1032
|
+
naked_other = naked(other)
|
|
1033
|
+
except TypeError:
|
|
1034
|
+
return NotImplemented
|
|
1035
|
+
|
|
1036
|
+
xps = get_sparse_module(naked_this)
|
|
1037
|
+
xp = get_array_module(naked_this)
|
|
1038
|
+
|
|
1039
|
+
if xp.isscalar(naked_this):
|
|
1040
|
+
other_xp = get_array_module(naked_other)
|
|
1041
|
+
data = getattr(other_xp, method_name)(naked_this, naked_other.data)
|
|
1042
|
+
indices, indptr, shape = (
|
|
1043
|
+
naked_other.indices,
|
|
1044
|
+
naked_other.indptr,
|
|
1045
|
+
naked_other.shape,
|
|
1046
|
+
)
|
|
1047
|
+
elif isinstance(naked_this, xp.ndarray):
|
|
1048
|
+
# dense
|
|
1049
|
+
return getattr(xp, method_name)(naked_this, other.toarray())
|
|
1050
|
+
else:
|
|
1051
|
+
tp = (
|
|
1052
|
+
np.int32 if is_cupy(naked_this) else np.bool_
|
|
1053
|
+
) # cupy.sparse does not support bool
|
|
1054
|
+
mask = xps.csr_matrix(
|
|
1055
|
+
(
|
|
1056
|
+
(naked_this.data > 0).astype(tp),
|
|
1057
|
+
naked_this.indices,
|
|
1058
|
+
naked_this.indptr,
|
|
1059
|
+
),
|
|
1060
|
+
naked_this.shape,
|
|
1061
|
+
)
|
|
1062
|
+
naked_other = mask.multiply(naked_other)
|
|
1063
|
+
indices, indptr, shape = (
|
|
1064
|
+
naked_this.indices,
|
|
1065
|
+
naked_this.indptr,
|
|
1066
|
+
naked_this.shape,
|
|
1067
|
+
)
|
|
1068
|
+
data = getattr(xp, method_name)(naked_this.data, naked_other.data)
|
|
1069
|
+
|
|
1070
|
+
return SparseNDArray(
|
|
1071
|
+
xps.csr_matrix((data, indices, indptr), shape), shape=shape
|
|
1072
|
+
)
|
|
1073
|
+
|
|
1074
|
+
def __lshift__(self, other):
|
|
1075
|
+
return self._shift(self.spmatrix, other, "left_shift")
|
|
1076
|
+
|
|
1077
|
+
def __rlshift__(self, other):
|
|
1078
|
+
return self._shift(other, self.spmatrix, "left_shift")
|
|
1079
|
+
|
|
1080
|
+
def __rshift__(self, other):
|
|
1081
|
+
return self._shift(self.spmatrix, other, "right_shift")
|
|
1082
|
+
|
|
1083
|
+
def __rrshift__(self, other):
|
|
1084
|
+
return self._shift(other, self.spmatrix, "right_shift")
|
|
1085
|
+
|
|
1086
|
+
def sin(self):
|
|
1087
|
+
return SparseNDArray(self.spmatrix.sin(), shape=self.shape)
|
|
1088
|
+
|
|
1089
|
+
def cos(self):
|
|
1090
|
+
return call_sparse("cos", self)
|
|
1091
|
+
|
|
1092
|
+
def tan(self):
|
|
1093
|
+
return SparseNDArray(self.spmatrix.tan(), shape=self.shape)
|
|
1094
|
+
|
|
1095
|
+
def arcsin(self):
|
|
1096
|
+
return SparseNDArray(self.spmatrix.arcsin(), shape=self.shape)
|
|
1097
|
+
|
|
1098
|
+
def arccos(self):
|
|
1099
|
+
return call_sparse("arccos", self)
|
|
1100
|
+
|
|
1101
|
+
def arctan(self):
|
|
1102
|
+
return SparseNDArray(self.spmatrix.arctan(), shape=self.shape)
|
|
1103
|
+
|
|
1104
|
+
def arctan2(self, other):
|
|
1105
|
+
try:
|
|
1106
|
+
naked_other = naked(other)
|
|
1107
|
+
except TypeError:
|
|
1108
|
+
return NotImplemented
|
|
1109
|
+
|
|
1110
|
+
xp = get_array_module(self.spmatrix)
|
|
1111
|
+
other_xp = get_array_module(naked_other)
|
|
1112
|
+
if other_xp.isscalar(naked_other):
|
|
1113
|
+
return call_sparse("arctan2", self, naked_other)
|
|
1114
|
+
if issparse(naked_other):
|
|
1115
|
+
naked_other = other.toarray()
|
|
1116
|
+
x = xp.arctan2(self.toarray(), naked_other)
|
|
1117
|
+
return SparseNDArray(get_sparse_module(x).csr_matrix(x), shape=self.shape)
|
|
1118
|
+
|
|
1119
|
+
def hypot(self, other):
|
|
1120
|
+
try:
|
|
1121
|
+
naked_other = naked(other)
|
|
1122
|
+
except TypeError:
|
|
1123
|
+
return NotImplemented
|
|
1124
|
+
|
|
1125
|
+
xp = get_array_module(self.spmatrix)
|
|
1126
|
+
other_xp = get_array_module(naked_other)
|
|
1127
|
+
if other_xp.isscalar(naked_other):
|
|
1128
|
+
return call_sparse("hypot", self, naked_other)
|
|
1129
|
+
if issparse(naked_other):
|
|
1130
|
+
naked_other = other.toarray()
|
|
1131
|
+
x = xp.hypot(self.toarray(), naked_other)
|
|
1132
|
+
return SparseNDArray(get_sparse_module(x).csr_matrix(x), shape=self.shape)
|
|
1133
|
+
|
|
1134
|
+
def sinh(self):
|
|
1135
|
+
return SparseNDArray(self.spmatrix.sinh(), shape=self.shape)
|
|
1136
|
+
|
|
1137
|
+
def cosh(self):
|
|
1138
|
+
xp = get_array_module(self.spmatrix)
|
|
1139
|
+
return xp.cosh(self.toarray())
|
|
1140
|
+
|
|
1141
|
+
def tanh(self):
|
|
1142
|
+
return SparseNDArray(self.spmatrix.tanh(), shape=self.shape)
|
|
1143
|
+
|
|
1144
|
+
def arcsinh(self):
|
|
1145
|
+
return SparseNDArray(self.spmatrix.arcsinh(), shape=self.shape)
|
|
1146
|
+
|
|
1147
|
+
def arccosh(self):
|
|
1148
|
+
return call_sparse("arccosh", self)
|
|
1149
|
+
|
|
1150
|
+
def arctanh(self):
|
|
1151
|
+
return SparseNDArray(self.spmatrix.arctanh(), shape=self.shape)
|
|
1152
|
+
|
|
1153
|
+
def around(self, decimals=0):
|
|
1154
|
+
return call_sparse("around", self, decimals=decimals)
|
|
1155
|
+
|
|
1156
|
+
def deg2rad(self):
|
|
1157
|
+
return SparseNDArray(self.spmatrix.deg2rad(), shape=self.shape)
|
|
1158
|
+
|
|
1159
|
+
def rad2deg(self):
|
|
1160
|
+
return SparseNDArray(self.spmatrix.rad2deg(), shape=self.shape)
|
|
1161
|
+
|
|
1162
|
+
def angle(self, deg=0):
|
|
1163
|
+
return call_sparse("angle", self, deg=deg)
|
|
1164
|
+
|
|
1165
|
+
def dot(self, other, sparse=True):
|
|
1166
|
+
raise NotImplementedError
|
|
1167
|
+
|
|
1168
|
+
def concatenate(self, other, axis=0):
|
|
1169
|
+
raise NotImplementedError
|
|
1170
|
+
|
|
1171
|
+
def _reduction(
|
|
1172
|
+
self, method_name, axis=None, dtype=None, keepdims=None, todense=False, **kw
|
|
1173
|
+
):
|
|
1174
|
+
raise NotImplementedError
|
|
1175
|
+
|
|
1176
|
+
def sum(self, axis=None, dtype=None, keepdims=None):
|
|
1177
|
+
return self._reduction("sum", axis=axis, dtype=dtype, keepdims=keepdims)
|
|
1178
|
+
|
|
1179
|
+
def prod(self, axis=None, dtype=None, keepdims=None):
|
|
1180
|
+
return self._reduction(
|
|
1181
|
+
"sum", axis=axis, dtype=dtype, keepdims=keepdims, todense=True
|
|
1182
|
+
)
|
|
1183
|
+
|
|
1184
|
+
def amax(self, axis=None, dtype=None, keepdims=None):
|
|
1185
|
+
return self._reduction("max", axis=axis, dtype=dtype, keepdims=keepdims)
|
|
1186
|
+
|
|
1187
|
+
def amin(self, axis=None, dtype=None, keepdims=None):
|
|
1188
|
+
return self._reduction("min", axis=axis, dtype=dtype, keepdims=keepdims)
|
|
1189
|
+
|
|
1190
|
+
def all(self, axis=None, dtype=None, keepdims=None):
|
|
1191
|
+
ret = self._reduction(
|
|
1192
|
+
"all", axis=axis, dtype=dtype, keepdims=keepdims, todense=True
|
|
1193
|
+
)
|
|
1194
|
+
if not issparse(ret):
|
|
1195
|
+
if get_array_module(ret).isscalar(ret):
|
|
1196
|
+
return ret
|
|
1197
|
+
xps = get_sparse_module(self.spmatrix)
|
|
1198
|
+
ret = SparseNDArray(xps.csr_matrix(ret))
|
|
1199
|
+
return ret
|
|
1200
|
+
return ret
|
|
1201
|
+
|
|
1202
|
+
def any(self, axis=None, dtype=None, keepdims=None):
|
|
1203
|
+
ret = self._reduction(
|
|
1204
|
+
"any", axis=axis, dtype=dtype, keepdims=keepdims, todense=True
|
|
1205
|
+
)
|
|
1206
|
+
if not issparse(ret):
|
|
1207
|
+
if get_array_module(ret).isscalar(ret):
|
|
1208
|
+
return ret
|
|
1209
|
+
xps = get_sparse_module(self.spmatrix)
|
|
1210
|
+
ret = SparseNDArray(xps.csr_matrix(ret))
|
|
1211
|
+
return ret
|
|
1212
|
+
return ret
|
|
1213
|
+
|
|
1214
|
+
def mean(self, axis=None, dtype=None, keepdims=None):
|
|
1215
|
+
return self._reduction("mean", axis=axis, dtype=dtype, keepdims=keepdims)
|
|
1216
|
+
|
|
1217
|
+
def nansum(self, axis=None, dtype=None, keepdims=None):
|
|
1218
|
+
return self._reduction(
|
|
1219
|
+
"nansum", axis=axis, dtype=dtype, keepdims=keepdims, todense=True
|
|
1220
|
+
)
|
|
1221
|
+
|
|
1222
|
+
def nanprod(self, axis=None, dtype=None, keepdims=None):
|
|
1223
|
+
return self._reduction(
|
|
1224
|
+
"nanprod", axis=axis, dtype=dtype, keepdims=keepdims, todense=True
|
|
1225
|
+
)
|
|
1226
|
+
|
|
1227
|
+
def nanmax(self, axis=None, dtype=None, keepdims=None):
|
|
1228
|
+
ret = self._reduction(
|
|
1229
|
+
"nanmax", axis=axis, dtype=dtype, keepdims=keepdims, todense=True
|
|
1230
|
+
)
|
|
1231
|
+
if not issparse(ret):
|
|
1232
|
+
if get_array_module(ret).isscalar(ret):
|
|
1233
|
+
return ret
|
|
1234
|
+
xps = get_sparse_module(self.spmatrix)
|
|
1235
|
+
ret = SparseNDArray(xps.csr_matrix(ret))
|
|
1236
|
+
return ret
|
|
1237
|
+
return ret
|
|
1238
|
+
|
|
1239
|
+
def nanmin(self, axis=None, dtype=None, keepdims=None):
|
|
1240
|
+
ret = self._reduction(
|
|
1241
|
+
"nanmin", axis=axis, dtype=dtype, keepdims=keepdims, todense=True
|
|
1242
|
+
)
|
|
1243
|
+
if not issparse(ret):
|
|
1244
|
+
if get_array_module(ret).isscalar(ret):
|
|
1245
|
+
return ret
|
|
1246
|
+
xps = get_sparse_module(self.spmatrix)
|
|
1247
|
+
ret = SparseNDArray(xps.csr_matrix(ret))
|
|
1248
|
+
return ret
|
|
1249
|
+
return ret
|
|
1250
|
+
|
|
1251
|
+
def nanmean(self, axis=None, dtype=None, keepdims=None):
|
|
1252
|
+
return self._reduction(
|
|
1253
|
+
"nanmean", axis=axis, dtype=dtype, keepdims=keepdims, todense=True
|
|
1254
|
+
)
|
|
1255
|
+
|
|
1256
|
+
def argmax(self, axis=None, dtype=None, keepdims=None):
|
|
1257
|
+
return self._reduction("argmax", axis=axis, dtype=dtype, keepdims=keepdims)
|
|
1258
|
+
|
|
1259
|
+
def nanargmax(self, axis=None, dtype=None, keepdims=None):
|
|
1260
|
+
return self._reduction(
|
|
1261
|
+
"nanargmax", axis=axis, dtype=dtype, keepdims=keepdims, todense=True
|
|
1262
|
+
)
|
|
1263
|
+
|
|
1264
|
+
def argmin(self, axis=None, dtype=None, keepdims=None):
|
|
1265
|
+
return self._reduction("argmin", axis=axis, dtype=dtype, keepdims=keepdims)
|
|
1266
|
+
|
|
1267
|
+
def nanargmin(self, axis=None, dtype=None, keepdims=None):
|
|
1268
|
+
return self._reduction(
|
|
1269
|
+
"nanargmin", axis=axis, dtype=dtype, keepdims=keepdims, todense=True
|
|
1270
|
+
)
|
|
1271
|
+
|
|
1272
|
+
def var(self, axis=None, dtype=None, ddof=0, keepdims=None):
|
|
1273
|
+
return self._reduction(
|
|
1274
|
+
"var", axis=axis, dtype=dtype, ddof=ddof, keepdims=keepdims, todense=True
|
|
1275
|
+
)
|
|
1276
|
+
|
|
1277
|
+
def cumsum(self, axis=None, dtype=None):
|
|
1278
|
+
return self.toarray().cumsum(axis=axis)
|
|
1279
|
+
|
|
1280
|
+
def cumprod(self, axis=None, dtype=None):
|
|
1281
|
+
return self.toarray().cumprod(axis=axis)
|
|
1282
|
+
|
|
1283
|
+
def nancumsum(self, axis=None, dtype=None):
|
|
1284
|
+
xp = get_array_module(self.spmatrix)
|
|
1285
|
+
return xp.nancumsum(self.toarray(), axis=axis)
|
|
1286
|
+
|
|
1287
|
+
def nancumprod(self, axis=None, dtype=None):
|
|
1288
|
+
xp = get_array_module(self.spmatrix)
|
|
1289
|
+
return xp.nancumprod(self.toarray(), axis=axis)
|
|
1290
|
+
|
|
1291
|
+
def count_nonzero(self, axis=None, dtype=None, keepdims=None):
|
|
1292
|
+
if axis is None:
|
|
1293
|
+
return get_array_module(self.spmatrix).array(
|
|
1294
|
+
[self.spmatrix.count_nonzero()]
|
|
1295
|
+
)[0]
|
|
1296
|
+
else:
|
|
1297
|
+
return get_array_module(self.spmatrix).count_nonzero(
|
|
1298
|
+
self.toarray(), axis=axis
|
|
1299
|
+
)
|
|
1300
|
+
|
|
1301
|
+
def __getitem__(self, item):
|
|
1302
|
+
if isinstance(item, SparseArray):
|
|
1303
|
+
item = item.spmatrix
|
|
1304
|
+
if isinstance(item, list):
|
|
1305
|
+
item = tuple(item)
|
|
1306
|
+
|
|
1307
|
+
x = self.spmatrix[item]
|
|
1308
|
+
if issparse(x):
|
|
1309
|
+
return SparseNDArray(x, shape=self.shape)
|
|
1310
|
+
return get_array_module(x).asarray(x)
|
|
1311
|
+
|
|
1312
|
+
def __setitem__(self, key, value):
|
|
1313
|
+
if is_cupy(self.spmatrix):
|
|
1314
|
+
return NotImplemented
|
|
1315
|
+
else:
|
|
1316
|
+
x = self.spmatrix.tolil()
|
|
1317
|
+
x[key] = value
|
|
1318
|
+
x = x.tocsr()
|
|
1319
|
+
self.spmatrix = x
|
|
1320
|
+
|
|
1321
|
+
def _maximum_minimum(self, other, method_name):
|
|
1322
|
+
try:
|
|
1323
|
+
naked_other = naked(other)
|
|
1324
|
+
except TypeError:
|
|
1325
|
+
return NotImplemented
|
|
1326
|
+
|
|
1327
|
+
if is_cupy(self.spmatrix):
|
|
1328
|
+
# TODO(jisheng): cupy does not implement sparse maximum and minimum
|
|
1329
|
+
return NotImplemented
|
|
1330
|
+
|
|
1331
|
+
xps = get_sparse_module(self.spmatrix)
|
|
1332
|
+
xp = get_array_module(self.spmatrix)
|
|
1333
|
+
has_nan = xps.csr_matrix(
|
|
1334
|
+
(xp.isnan(self.spmatrix.data), self.spmatrix.indices, self.spmatrix.indptr),
|
|
1335
|
+
self.spmatrix.shape,
|
|
1336
|
+
)
|
|
1337
|
+
if issparse(naked_other):
|
|
1338
|
+
has_nan += xps.csr_matrix(
|
|
1339
|
+
(xp.isnan(naked_other.data), naked_other.indices, naked_other.indptr),
|
|
1340
|
+
naked_other.shape,
|
|
1341
|
+
)
|
|
1342
|
+
|
|
1343
|
+
if issparse(naked_other):
|
|
1344
|
+
x = getattr(self.spmatrix, method_name)(naked_other)
|
|
1345
|
+
else:
|
|
1346
|
+
x = getattr(xp, method_name)(self.toarray(), naked_other)
|
|
1347
|
+
|
|
1348
|
+
if has_nan.sum() > 0:
|
|
1349
|
+
x = x + (has_nan * np.nan)
|
|
1350
|
+
|
|
1351
|
+
if issparse(x):
|
|
1352
|
+
return SparseNDArray(x, shape=self.shape)
|
|
1353
|
+
|
|
1354
|
+
return get_array_module(x).asarray(x)
|
|
1355
|
+
|
|
1356
|
+
def maximum(self, other):
|
|
1357
|
+
return self._maximum_minimum(other, "maximum")
|
|
1358
|
+
|
|
1359
|
+
def minimum(self, other):
|
|
1360
|
+
return self._maximum_minimum(other, "minimum")
|
|
1361
|
+
|
|
1362
|
+
def fmax(self, other):
|
|
1363
|
+
try:
|
|
1364
|
+
naked_other = naked(other)
|
|
1365
|
+
except TypeError:
|
|
1366
|
+
return NotImplemented
|
|
1367
|
+
|
|
1368
|
+
x = self.spmatrix.maximum(naked_other)
|
|
1369
|
+
if issparse(x):
|
|
1370
|
+
return SparseArray(x, shape=self.shape)
|
|
1371
|
+
return get_array_module(x).asarray(x)
|
|
1372
|
+
|
|
1373
|
+
def fmin(self, other):
|
|
1374
|
+
try:
|
|
1375
|
+
naked_other = naked(other)
|
|
1376
|
+
except TypeError:
|
|
1377
|
+
return NotImplemented
|
|
1378
|
+
|
|
1379
|
+
x = self.spmatrix.minimum(naked_other)
|
|
1380
|
+
if issparse(x):
|
|
1381
|
+
return SparseNDArray(x, shape=self.shape)
|
|
1382
|
+
return get_array_module(x).asarray(x)
|
|
1383
|
+
|
|
1384
|
+
def isinf(self):
|
|
1385
|
+
return call_sparse("isinf", self)
|
|
1386
|
+
|
|
1387
|
+
def isnan(self):
|
|
1388
|
+
return call_sparse("isnan", self)
|
|
1389
|
+
|
|
1390
|
+
def signbit(self):
|
|
1391
|
+
return call_sparse("signbit", self)
|
|
1392
|
+
|
|
1393
|
+
def floor(self):
|
|
1394
|
+
return SparseNDArray(self.spmatrix.floor(), shape=self.shape)
|
|
1395
|
+
|
|
1396
|
+
def ceil(self):
|
|
1397
|
+
return SparseNDArray(self.spmatrix.ceil(), shape=self.shape)
|
|
1398
|
+
|
|
1399
|
+
def trunc(self):
|
|
1400
|
+
return SparseNDArray(self.spmatrix.trunc(), shape=self.shape)
|
|
1401
|
+
|
|
1402
|
+
def degrees(self):
|
|
1403
|
+
return call_sparse("degrees", self)
|
|
1404
|
+
|
|
1405
|
+
def radians(self):
|
|
1406
|
+
return call_sparse("radians", self)
|
|
1407
|
+
|
|
1408
|
+
def clip(self, a_min, a_max):
|
|
1409
|
+
try:
|
|
1410
|
+
a_min = naked(a_min)
|
|
1411
|
+
except TypeError:
|
|
1412
|
+
return NotImplemented
|
|
1413
|
+
|
|
1414
|
+
try:
|
|
1415
|
+
a_max = naked(a_max)
|
|
1416
|
+
except TypeError:
|
|
1417
|
+
return NotImplemented
|
|
1418
|
+
|
|
1419
|
+
x = self.spmatrix.maximum(a_min)
|
|
1420
|
+
if issparse(x):
|
|
1421
|
+
x = x.minimum(a_max)
|
|
1422
|
+
elif issparse(a_max):
|
|
1423
|
+
x = a_max.minimum(x)
|
|
1424
|
+
else:
|
|
1425
|
+
xp = get_array_module(x)
|
|
1426
|
+
x = xp.minimum(x, a_max)
|
|
1427
|
+
if issparse(x):
|
|
1428
|
+
return SparseNDArray(x, shape=self.shape)
|
|
1429
|
+
return get_array_module(x).asarray(x)
|
|
1430
|
+
|
|
1431
|
+
def iscomplex(self):
|
|
1432
|
+
return call_sparse("iscomplex", self)
|
|
1433
|
+
|
|
1434
|
+
def fix(self):
|
|
1435
|
+
return call_sparse("fix", self)
|
|
1436
|
+
|
|
1437
|
+
def i0(self):
|
|
1438
|
+
xp = get_array_module(self.spmatrix)
|
|
1439
|
+
data = xp.i0(self.spmatrix.data).reshape(self.spmatrix.data.shape)
|
|
1440
|
+
x = get_sparse_module(self.spmatrix).csr_matrix(
|
|
1441
|
+
(data, self.spmatrix.indices, self.spmatrix.indptr), self.spmatrix.shape
|
|
1442
|
+
)
|
|
1443
|
+
return SparseNDArray(x, shape=self.shape)
|
|
1444
|
+
|
|
1445
|
+
def nan_to_num(self):
|
|
1446
|
+
return call_sparse("nan_to_num", self)
|
|
1447
|
+
|
|
1448
|
+
def copysign(self, other):
|
|
1449
|
+
try:
|
|
1450
|
+
naked_other = naked(other)
|
|
1451
|
+
except TypeError:
|
|
1452
|
+
return NotImplemented
|
|
1453
|
+
|
|
1454
|
+
if get_array_module(naked_other).isscalar(naked_other):
|
|
1455
|
+
return call_sparse("copysign", self, naked_other)
|
|
1456
|
+
|
|
1457
|
+
if issparse(naked_other):
|
|
1458
|
+
naked_other = other.toarray()
|
|
1459
|
+
|
|
1460
|
+
xp = get_array_module(self.spmatrix)
|
|
1461
|
+
return xp.copysign(self.toarray(), naked_other)
|
|
1462
|
+
|
|
1463
|
+
def nextafter(self, other):
|
|
1464
|
+
try:
|
|
1465
|
+
naked_other = naked(other)
|
|
1466
|
+
except TypeError:
|
|
1467
|
+
return NotImplemented
|
|
1468
|
+
|
|
1469
|
+
ret_sparse = False
|
|
1470
|
+
if issparse(naked_other):
|
|
1471
|
+
ret_sparse = True
|
|
1472
|
+
naked_other = other.toarray()
|
|
1473
|
+
|
|
1474
|
+
xp = get_array_module(self.spmatrix)
|
|
1475
|
+
xps = get_sparse_module(self.spmatrix)
|
|
1476
|
+
|
|
1477
|
+
x = xp.nextafter(self.toarray(), naked_other)
|
|
1478
|
+
if ret_sparse:
|
|
1479
|
+
return SparseNDArray(xps.csr_matrix(x), shape=self.shape)
|
|
1480
|
+
return x
|
|
1481
|
+
|
|
1482
|
+
def spacing(self):
|
|
1483
|
+
if is_cupy(self.spmatrix):
|
|
1484
|
+
raise NotImplementedError
|
|
1485
|
+
return call_sparse("spacing", self)
|
|
1486
|
+
|
|
1487
|
+
def ldexp(self, other):
|
|
1488
|
+
try:
|
|
1489
|
+
naked_other = naked(other)
|
|
1490
|
+
except TypeError:
|
|
1491
|
+
return NotImplemented
|
|
1492
|
+
|
|
1493
|
+
if get_array_module(naked_other).isscalar(naked_other):
|
|
1494
|
+
return call_sparse("ldexp", self, naked_other)
|
|
1495
|
+
|
|
1496
|
+
if issparse(naked_other):
|
|
1497
|
+
naked_other = other.toarray()
|
|
1498
|
+
|
|
1499
|
+
return SparseNDArray(self.spmatrix.multiply(2**naked_other))
|
|
1500
|
+
|
|
1501
|
+
def frexp(self, **kw):
|
|
1502
|
+
xp = get_array_module(self.spmatrix)
|
|
1503
|
+
xps = get_sparse_module(self.spmatrix)
|
|
1504
|
+
x, y = xp.frexp(self.toarray(), **kw)
|
|
1505
|
+
return (
|
|
1506
|
+
SparseNDArray(xps.csr_matrix(x), shape=self.shape),
|
|
1507
|
+
SparseNDArray(xps.csr_matrix(y), shape=self.shape),
|
|
1508
|
+
)
|
|
1509
|
+
|
|
1510
|
+
def modf(self, **kw):
|
|
1511
|
+
xp = get_array_module(self.spmatrix)
|
|
1512
|
+
xps = get_sparse_module(self.spmatrix)
|
|
1513
|
+
x, y = xp.modf(self.toarray(), **kw)
|
|
1514
|
+
return (
|
|
1515
|
+
SparseNDArray(xps.csr_matrix(x), shape=self.shape),
|
|
1516
|
+
SparseNDArray(xps.csr_matrix(y), shape=self.shape),
|
|
1517
|
+
)
|
|
1518
|
+
|
|
1519
|
+
def sinc(self):
|
|
1520
|
+
return call_sparse("sinc", self)
|
|
1521
|
+
|
|
1522
|
+
def isfinite(self):
|
|
1523
|
+
return call_sparse("isfinite", self)
|
|
1524
|
+
|
|
1525
|
+
def isreal(self):
|
|
1526
|
+
return call_sparse("isreal", self)
|
|
1527
|
+
|
|
1528
|
+
def digitize(self, bins, right=False):
|
|
1529
|
+
return call_sparse("digitize", self, bins=bins, right=right)
|
|
1530
|
+
|
|
1531
|
+
def repeat(self, repeats, axis=None):
|
|
1532
|
+
if axis is None:
|
|
1533
|
+
raise NotImplementedError
|
|
1534
|
+
|
|
1535
|
+
xp = get_array_module(self.spmatrix)
|
|
1536
|
+
xps = get_sparse_module(self.spmatrix)
|
|
1537
|
+
r = xp.repeat(self.toarray(), repeats, axis=axis)
|
|
1538
|
+
x = xps.csr_matrix(r)
|
|
1539
|
+
return SparseNDArray(x, shape=r.shape)
|
|
1540
|
+
|
|
1541
|
+
@staticmethod
|
|
1542
|
+
def _expand_val(val, expect_val_size, xp):
|
|
1543
|
+
if val.size > expect_val_size:
|
|
1544
|
+
val = val[:expect_val_size]
|
|
1545
|
+
elif val.size < expect_val_size:
|
|
1546
|
+
n_repeat = ceildiv(expect_val_size, val.size)
|
|
1547
|
+
val = xp.tile(val, n_repeat)[:expect_val_size]
|
|
1548
|
+
return val
|
|
1549
|
+
|
|
1550
|
+
def fill_diagonal(self, val, wrap=False):
|
|
1551
|
+
lil_matrix = self.spmatrix.tolil()
|
|
1552
|
+
|
|
1553
|
+
xp = get_array_module(self.spmatrix)
|
|
1554
|
+
val = xp.asarray(val)
|
|
1555
|
+
if val.ndim > 1:
|
|
1556
|
+
val = val.ravel()
|
|
1557
|
+
is_tall_matrix = lil_matrix.shape[0] > lil_matrix.shape[1] + 1
|
|
1558
|
+
n_rows, n_cols = lil_matrix.shape
|
|
1559
|
+
|
|
1560
|
+
if not wrap or not is_tall_matrix:
|
|
1561
|
+
if val.ndim > 0:
|
|
1562
|
+
# check if val is long enough
|
|
1563
|
+
expect_val_size = min(n_rows, n_cols)
|
|
1564
|
+
val = self._expand_val(val, expect_val_size, xp)
|
|
1565
|
+
lil_matrix.setdiag(val)
|
|
1566
|
+
matrix = lil_matrix
|
|
1567
|
+
else:
|
|
1568
|
+
block_size = n_cols + 1
|
|
1569
|
+
|
|
1570
|
+
n_block = n_rows // block_size
|
|
1571
|
+
n_vals = n_cols * n_block
|
|
1572
|
+
if n_rows % block_size > 0:
|
|
1573
|
+
# 1 chunk left
|
|
1574
|
+
n_block += 1
|
|
1575
|
+
n_vals += min(n_rows % block_size, n_cols)
|
|
1576
|
+
|
|
1577
|
+
if val.ndim > 0:
|
|
1578
|
+
val = self._expand_val(val, n_vals, xp)
|
|
1579
|
+
|
|
1580
|
+
sub_matrices = []
|
|
1581
|
+
for i in range(n_block):
|
|
1582
|
+
sub_lil_matrix = lil_matrix[i * block_size : (i + 1) * block_size]
|
|
1583
|
+
if val.ndim > 0:
|
|
1584
|
+
sub_val = val[i * n_cols : (i + 1) * n_cols]
|
|
1585
|
+
else:
|
|
1586
|
+
sub_val = val
|
|
1587
|
+
sub_lil_matrix.setdiag(sub_val)
|
|
1588
|
+
sub_matrices.append(sub_lil_matrix)
|
|
1589
|
+
|
|
1590
|
+
xps = get_sparse_module(self.spmatrix)
|
|
1591
|
+
matrix = SparseArray(xps.vstack(sub_matrices, format="csr"))
|
|
1592
|
+
|
|
1593
|
+
self.spmatrix = matrix.tocsr()
|
|
1594
|
+
|
|
1595
|
+
def unique(
|
|
1596
|
+
self, return_index=False, return_inverse=False, return_counts=False, axis=None
|
|
1597
|
+
):
|
|
1598
|
+
if return_inverse or return_index: # pragma: no cover
|
|
1599
|
+
raise NotImplementedError
|
|
1600
|
+
if self.ndim == 2 and axis is not None: # pragma: no cover
|
|
1601
|
+
raise NotImplementedError
|
|
1602
|
+
|
|
1603
|
+
xp = get_array_module(self.spmatrix)
|
|
1604
|
+
return xp.unique(self.spmatrix.data, return_counts=return_counts)
|