opencode-pyneruntime 6.6.4__py3-none-any.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.
- opencode_pyneruntime-6.6.4.dist-info/METADATA +281 -0
- opencode_pyneruntime-6.6.4.dist-info/RECORD +261 -0
- opencode_pyneruntime-6.6.4.dist-info/WHEEL +5 -0
- opencode_pyneruntime-6.6.4.dist-info/entry_points.txt +6 -0
- opencode_pyneruntime-6.6.4.dist-info/licenses/LICENSE +201 -0
- opencode_pyneruntime-6.6.4.dist-info/licenses/NOTICE +21 -0
- opencode_pyneruntime-6.6.4.dist-info/top_level.txt +1 -0
- pynecore/__init__.py +6 -0
- pynecore/cli/__init__.py +2 -0
- pynecore/cli/app.py +238 -0
- pynecore/cli/commands/__init__.py +343 -0
- pynecore/cli/commands/benchmark.py +186 -0
- pynecore/cli/commands/compile.py +198 -0
- pynecore/cli/commands/data.py +857 -0
- pynecore/cli/commands/debug.py +63 -0
- pynecore/cli/commands/optimize.py +956 -0
- pynecore/cli/commands/plugin.py +242 -0
- pynecore/cli/commands/run.py +2006 -0
- pynecore/cli/pluggable.py +132 -0
- pynecore/cli/utils/__init__.py +0 -0
- pynecore/cli/utils/api_error_handler.py +168 -0
- pynecore/cli/utils/broker_picker.py +330 -0
- pynecore/cli/utils/error_hook.py +28 -0
- pynecore/cli/utils/keyreader.py +178 -0
- pynecore/cli/utils/provider_picker.py +19 -0
- pynecore/cli/utils/symbol_browser.py +1149 -0
- pynecore/core/__init__.py +0 -0
- pynecore/core/aggregator.py +257 -0
- pynecore/core/bar_magnifier.py +168 -0
- pynecore/core/broker/__init__.py +64 -0
- pynecore/core/broker/defaults.py +113 -0
- pynecore/core/broker/disappearance.py +927 -0
- pynecore/core/broker/emulator.py +345 -0
- pynecore/core/broker/exceptions.py +346 -0
- pynecore/core/broker/idempotency.py +401 -0
- pynecore/core/broker/intent_builder.py +334 -0
- pynecore/core/broker/journal.py +1785 -0
- pynecore/core/broker/models.py +1600 -0
- pynecore/core/broker/native_failsafe_manager.py +1436 -0
- pynecore/core/broker/one_way_emulator.py +1128 -0
- pynecore/core/broker/position.py +787 -0
- pynecore/core/broker/run_identity.py +126 -0
- pynecore/core/broker/software_entry_stop_engine.py +351 -0
- pynecore/core/broker/software_partial_bracket_engine.py +1379 -0
- pynecore/core/broker/spot_inventory.py +1327 -0
- pynecore/core/broker/storage.py +2655 -0
- pynecore/core/broker/store_helpers.py +2161 -0
- pynecore/core/broker/sync_engine.py +16070 -0
- pynecore/core/broker/validation.py +382 -0
- pynecore/core/class_property.py +7 -0
- pynecore/core/config.py +392 -0
- pynecore/core/csv_file.py +547 -0
- pynecore/core/currency.py +262 -0
- pynecore/core/data_converter.py +1002 -0
- pynecore/core/datetime.py +296 -0
- pynecore/core/download_info.py +71 -0
- pynecore/core/download_runner.py +274 -0
- pynecore/core/htf_aggregator.py +181 -0
- pynecore/core/import_hook.py +358 -0
- pynecore/core/instance_state.py +494 -0
- pynecore/core/live_ltf_collector.py +442 -0
- pynecore/core/live_ltf_window.py +189 -0
- pynecore/core/live_runner.py +1347 -0
- pynecore/core/module_property.py +26 -0
- pynecore/core/ohlcv_file.py +1888 -0
- pynecore/core/overload.py +371 -0
- pynecore/core/pine_cast.py +113 -0
- pynecore/core/pine_export.py +95 -0
- pynecore/core/pine_method.py +244 -0
- pynecore/core/pine_range.py +86 -0
- pynecore/core/pine_udt.py +69 -0
- pynecore/core/plugin/__init__.py +394 -0
- pynecore/core/plugin/broker.py +781 -0
- pynecore/core/plugin/cli.py +96 -0
- pynecore/core/plugin/live_provider.py +208 -0
- pynecore/core/plugin/provider.py +331 -0
- pynecore/core/provider_string.py +148 -0
- pynecore/core/random.py +40 -0
- pynecore/core/resampler.py +686 -0
- pynecore/core/safe_convert.py +64 -0
- pynecore/core/script.py +1011 -0
- pynecore/core/script_runner.py +3202 -0
- pynecore/core/security.py +1749 -0
- pynecore/core/security_process.py +1253 -0
- pynecore/core/security_shm.py +456 -0
- pynecore/core/series.py +417 -0
- pynecore/core/strategy_stats.py +669 -0
- pynecore/core/symbol_map.py +134 -0
- pynecore/core/syminfo.py +505 -0
- pynecore/core/viz.py +591 -0
- pynecore/lib/__init__.py +1771 -0
- pynecore/lib/_fixnan.py +32 -0
- pynecore/lib/_math_stateful.py +202 -0
- pynecore/lib/_timeframe_change.py +101 -0
- pynecore/lib/adjustment.py +6 -0
- pynecore/lib/alert.py +39 -0
- pynecore/lib/alert.pyi +14 -0
- pynecore/lib/array.py +1051 -0
- pynecore/lib/barmerge.py +60 -0
- pynecore/lib/barstate.py +30 -0
- pynecore/lib/box.py +415 -0
- pynecore/lib/chart.py +128 -0
- pynecore/lib/color.py +152 -0
- pynecore/lib/color.pyi +50 -0
- pynecore/lib/currency.py +62 -0
- pynecore/lib/dayofweek.py +36 -0
- pynecore/lib/dayofweek.pyi +18 -0
- pynecore/lib/display.py +8 -0
- pynecore/lib/dividends.py +9 -0
- pynecore/lib/earnings.py +11 -0
- pynecore/lib/extend.py +6 -0
- pynecore/lib/font.py +5 -0
- pynecore/lib/footprint.py +79 -0
- pynecore/lib/format.py +11 -0
- pynecore/lib/hline.py +67 -0
- pynecore/lib/hline.pyi +24 -0
- pynecore/lib/label.py +409 -0
- pynecore/lib/line.py +433 -0
- pynecore/lib/linefill.py +93 -0
- pynecore/lib/location.py +11 -0
- pynecore/lib/log.py +362 -0
- pynecore/lib/map.py +150 -0
- pynecore/lib/math.py +385 -0
- pynecore/lib/matrix.py +708 -0
- pynecore/lib/order.py +8 -0
- pynecore/lib/pivotpointtype.py +8 -0
- pynecore/lib/plot.py +95 -0
- pynecore/lib/plot.pyi +33 -0
- pynecore/lib/polyline.py +91 -0
- pynecore/lib/position.py +15 -0
- pynecore/lib/request.py +281 -0
- pynecore/lib/runtime.py +5 -0
- pynecore/lib/scale.py +9 -0
- pynecore/lib/session.py +267 -0
- pynecore/lib/session.pyi +12 -0
- pynecore/lib/shape.py +18 -0
- pynecore/lib/size.py +12 -0
- pynecore/lib/splits.py +4 -0
- pynecore/lib/strategy/__init__.py +4778 -0
- pynecore/lib/strategy/closedtrades.py +347 -0
- pynecore/lib/strategy/closedtrades.pyi +53 -0
- pynecore/lib/strategy/commission.py +9 -0
- pynecore/lib/strategy/direction.py +9 -0
- pynecore/lib/strategy/oca.py +13 -0
- pynecore/lib/strategy/opentrades.py +281 -0
- pynecore/lib/strategy/opentrades.pyi +49 -0
- pynecore/lib/strategy/risk.py +109 -0
- pynecore/lib/string.py +649 -0
- pynecore/lib/syminfo.py +84 -0
- pynecore/lib/ta.py +2230 -0
- pynecore/lib/table.py +290 -0
- pynecore/lib/text.py +17 -0
- pynecore/lib/ticker.py +207 -0
- pynecore/lib/timeframe.py +293 -0
- pynecore/lib/volume_row.py +67 -0
- pynecore/lib/xloc.py +4 -0
- pynecore/lib/yloc.py +5 -0
- pynecore/providers/__init__.py +0 -0
- pynecore/providers/ccxt.py +664 -0
- pynecore/providers/replay.py +187 -0
- pynecore/pynesys/__init__.py +0 -0
- pynecore/pynesys/api.py +498 -0
- pynecore/pynesys/compiler.py +112 -0
- pynecore/standalone.py +99 -0
- pynecore/testing/__init__.py +1 -0
- pynecore/testing/broker_lab/__init__.py +41 -0
- pynecore/testing/broker_lab/__main__.py +5 -0
- pynecore/testing/broker_lab/cli.py +87 -0
- pynecore/testing/broker_lab/generate.py +47 -0
- pynecore/testing/broker_lab/model.py +84 -0
- pynecore/testing/broker_lab/reference.py +645 -0
- pynecore/testing/broker_lab/runner.py +372 -0
- pynecore/testing/broker_lab/scheduler.py +50 -0
- pynecore/testing/broker_lab/subprocess.py +73 -0
- pynecore/transformers/__init__.py +0 -0
- pynecore/transformers/builtin_shadow.py +136 -0
- pynecore/transformers/closure_arguments_transformer.py +428 -0
- pynecore/transformers/display_rewrite.py +140 -0
- pynecore/transformers/dynamic_default.py +147 -0
- pynecore/transformers/function_isolation.py +757 -0
- pynecore/transformers/import_lifter.py +61 -0
- pynecore/transformers/import_normalizer.py +328 -0
- pynecore/transformers/inline_series_hoist.py +178 -0
- pynecore/transformers/input_transformer.py +175 -0
- pynecore/transformers/lib_series.py +201 -0
- pynecore/transformers/locations.py +70 -0
- pynecore/transformers/module_properties.json +3387 -0
- pynecore/transformers/module_property.py +221 -0
- pynecore/transformers/ne_guard.py +70 -0
- pynecore/transformers/persistent.py +320 -0
- pynecore/transformers/persistent_series.py +76 -0
- pynecore/transformers/safe_convert_transformer.py +97 -0
- pynecore/transformers/safe_division_transformer.py +95 -0
- pynecore/transformers/script_requirements.py +308 -0
- pynecore/transformers/security.py +752 -0
- pynecore/transformers/security_instantiation.py +274 -0
- pynecore/transformers/series.py +275 -0
- pynecore/transformers/slot_layout.py +381 -0
- pynecore/transformers/type_checking_stripper.py +25 -0
- pynecore/transformers/unused_series_detector.py +267 -0
- pynecore/types/__init__.py +21 -0
- pynecore/types/alert.py +5 -0
- pynecore/types/barmerge.py +5 -0
- pynecore/types/base.py +39 -0
- pynecore/types/box.py +37 -0
- pynecore/types/chart.py +17 -0
- pynecore/types/color.py +107 -0
- pynecore/types/currency.py +5 -0
- pynecore/types/datetime.py +6 -0
- pynecore/types/display.py +5 -0
- pynecore/types/dividends.py +5 -0
- pynecore/types/earnings.py +5 -0
- pynecore/types/extend.py +5 -0
- pynecore/types/font.py +5 -0
- pynecore/types/footprint.py +41 -0
- pynecore/types/format.py +5 -0
- pynecore/types/hline.py +24 -0
- pynecore/types/ib_persistent.py +8 -0
- pynecore/types/ib_persistent.pyi +10 -0
- pynecore/types/label.py +35 -0
- pynecore/types/line.py +32 -0
- pynecore/types/linefill.py +13 -0
- pynecore/types/location.py +5 -0
- pynecore/types/matrix.py +999 -0
- pynecore/types/na.py +237 -0
- pynecore/types/na.pyi +83 -0
- pynecore/types/ohlcv.py +12 -0
- pynecore/types/order.py +5 -0
- pynecore/types/persistent.py +8 -0
- pynecore/types/persistent.pyi +13 -0
- pynecore/types/pine_types.py +11 -0
- pynecore/types/pine_types.pyi +15 -0
- pynecore/types/pivotpointtype.py +5 -0
- pynecore/types/plot.py +12 -0
- pynecore/types/plot_meta.py +60 -0
- pynecore/types/polyline.py +40 -0
- pynecore/types/position.py +5 -0
- pynecore/types/scale.py +5 -0
- pynecore/types/script_type.py +15 -0
- pynecore/types/series.py +23 -0
- pynecore/types/series.pyi +19 -0
- pynecore/types/session.py +35 -0
- pynecore/types/shape.py +5 -0
- pynecore/types/size.py +5 -0
- pynecore/types/source.py +33 -0
- pynecore/types/splits.py +5 -0
- pynecore/types/strategy.py +45 -0
- pynecore/types/table.py +87 -0
- pynecore/types/text.py +13 -0
- pynecore/types/type_checker.py +7 -0
- pynecore/types/type_checker.pyi +48 -0
- pynecore/types/volume_row.py +36 -0
- pynecore/types/weekdays.py +11 -0
- pynecore/types/xloc.py +5 -0
- pynecore/types/yloc.py +5 -0
- pynecore/utils/__init__.py +0 -0
- pynecore/utils/file_utils.py +50 -0
- pynecore/utils/rich/__init__.py +0 -0
- pynecore/utils/rich/date_column.py +25 -0
- pynecore/utils/sequence_view.py +92 -0
- pynecore/utils/stdlib_checker.py +17 -0
pynecore/lib/matrix.py
ADDED
|
@@ -0,0 +1,708 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from ..core.module_property import module_property
|
|
5
|
+
from ..types.matrix import Matrix
|
|
6
|
+
from ..types.na import NA, na_float
|
|
7
|
+
|
|
8
|
+
_registry: list[Matrix] = []
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# noinspection PyShadowingNames
|
|
12
|
+
def new(rows: int = 0, columns: int = 0, initial_value: Any = None) -> Matrix:
|
|
13
|
+
"""
|
|
14
|
+
Create a new matrix object.
|
|
15
|
+
|
|
16
|
+
A matrix is a two-dimensional data structure containing rows and columns.
|
|
17
|
+
All elements in the matrix must be of the same type.
|
|
18
|
+
|
|
19
|
+
:param rows: Initial row count of the matrix. Optional, defaults to 0.
|
|
20
|
+
:param columns: Initial column count of the matrix. Optional, defaults to 0.
|
|
21
|
+
:param initial_value: Initial value of all matrix elements. If None, uses NA.
|
|
22
|
+
:return: The ID of the new matrix object.
|
|
23
|
+
"""
|
|
24
|
+
if initial_value is None:
|
|
25
|
+
initial_value = na_float
|
|
26
|
+
|
|
27
|
+
matrix_obj = Matrix(rows, columns, initial_value)
|
|
28
|
+
_registry.append(matrix_obj)
|
|
29
|
+
return matrix_obj
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# noinspection PyShadowingBuiltins
|
|
33
|
+
@module_property
|
|
34
|
+
def all() -> list[Matrix]:
|
|
35
|
+
"""
|
|
36
|
+
Return all matrix objects.
|
|
37
|
+
|
|
38
|
+
:return: List of all created matrix objects.
|
|
39
|
+
"""
|
|
40
|
+
return _registry
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# noinspection PyShadowingBuiltins
|
|
44
|
+
def copy(id: Matrix | NA) -> Matrix | NA:
|
|
45
|
+
"""
|
|
46
|
+
Create a new matrix which is a copy of the original.
|
|
47
|
+
|
|
48
|
+
:param id: A matrix object to copy.
|
|
49
|
+
:return: A new matrix object of the copied matrix.
|
|
50
|
+
"""
|
|
51
|
+
if isinstance(id, NA):
|
|
52
|
+
return NA(Matrix)
|
|
53
|
+
return id.copy()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# noinspection PyShadowingBuiltins
|
|
57
|
+
def delete(id: Matrix | NA) -> None:
|
|
58
|
+
"""
|
|
59
|
+
Delete matrix object.
|
|
60
|
+
|
|
61
|
+
:param id: Matrix object to delete.
|
|
62
|
+
"""
|
|
63
|
+
if isinstance(id, NA):
|
|
64
|
+
return
|
|
65
|
+
try:
|
|
66
|
+
_registry.remove(id)
|
|
67
|
+
except ValueError:
|
|
68
|
+
pass
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
# noinspection PyShadowingBuiltins,PyShadowingNames
|
|
72
|
+
def add_row(id: Matrix | NA, row: int | None = None, array_id: list[Any] | None = None) -> None:
|
|
73
|
+
"""
|
|
74
|
+
Add a row at the specified index of the matrix.
|
|
75
|
+
|
|
76
|
+
:param id: A matrix object.
|
|
77
|
+
:param row: The index where the new row will be inserted. If None, appends to the end.
|
|
78
|
+
:param array_id: Array to use for providing values to the new row.
|
|
79
|
+
"""
|
|
80
|
+
if isinstance(id, NA):
|
|
81
|
+
return
|
|
82
|
+
id.add_row(row, array_id)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# noinspection PyShadowingBuiltins
|
|
86
|
+
def add_col(id: Matrix | NA, column: int | None = None, array_id: list[Any] | None = None) -> None:
|
|
87
|
+
"""
|
|
88
|
+
Add a column at the specified index of the matrix.
|
|
89
|
+
|
|
90
|
+
:param id: A matrix object.
|
|
91
|
+
:param column: The index where the new column will be inserted. If None, appends to the end.
|
|
92
|
+
:param array_id: Array to use for providing values to the new column.
|
|
93
|
+
"""
|
|
94
|
+
if isinstance(id, NA):
|
|
95
|
+
return
|
|
96
|
+
id.add_col(column, array_id)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# noinspection PyShadowingBuiltins
|
|
100
|
+
def avg(id: Matrix | NA) -> float | int | NA:
|
|
101
|
+
"""
|
|
102
|
+
Calculate the average of all elements in the matrix.
|
|
103
|
+
|
|
104
|
+
:param id: A matrix object.
|
|
105
|
+
:return: The average value from the matrix.
|
|
106
|
+
"""
|
|
107
|
+
if isinstance(id, NA):
|
|
108
|
+
return na_float
|
|
109
|
+
return id.avg()
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
# noinspection PyShadowingBuiltins
|
|
113
|
+
def col(id: Matrix | NA, column: int) -> list[Any] | NA:
|
|
114
|
+
"""
|
|
115
|
+
Create a one-dimensional array from the elements of a matrix column.
|
|
116
|
+
|
|
117
|
+
:param id: A matrix object.
|
|
118
|
+
:param column: Index of the required column.
|
|
119
|
+
:return: An array containing the column values.
|
|
120
|
+
"""
|
|
121
|
+
if isinstance(id, NA):
|
|
122
|
+
return NA(list)
|
|
123
|
+
return id.col(column)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
# noinspection PyShadowingBuiltins
|
|
127
|
+
def columns(id: Matrix | NA) -> int | NA:
|
|
128
|
+
"""
|
|
129
|
+
Return the number of columns in the matrix.
|
|
130
|
+
|
|
131
|
+
:param id: A matrix object.
|
|
132
|
+
:return: The number of columns.
|
|
133
|
+
"""
|
|
134
|
+
if isinstance(id, NA):
|
|
135
|
+
return NA(int)
|
|
136
|
+
return id.cols
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
# noinspection PyShadowingBuiltins
|
|
140
|
+
def concat(id1: Matrix | NA, id2: Matrix | NA) -> Matrix | NA:
|
|
141
|
+
"""
|
|
142
|
+
Append the second matrix to the first matrix.
|
|
143
|
+
|
|
144
|
+
:param id1: Matrix object to concatenate into.
|
|
145
|
+
:param id2: Matrix object whose elements will be appended.
|
|
146
|
+
:return: The first matrix after concatenation.
|
|
147
|
+
"""
|
|
148
|
+
if isinstance(id1, NA) or isinstance(id2, NA):
|
|
149
|
+
return NA(Matrix)
|
|
150
|
+
return id1.concat(id2)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
# noinspection PyShadowingBuiltins
|
|
154
|
+
def det(id: Matrix | NA) -> float | int | NA:
|
|
155
|
+
"""
|
|
156
|
+
Return the determinant of a square matrix.
|
|
157
|
+
|
|
158
|
+
:param id: A matrix object.
|
|
159
|
+
:return: The determinant value of the matrix.
|
|
160
|
+
"""
|
|
161
|
+
if isinstance(id, NA):
|
|
162
|
+
return na_float
|
|
163
|
+
return id.det()
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
# noinspection PyShadowingBuiltins
|
|
167
|
+
def diff(id1: Matrix | NA, id2: Matrix | int | float | NA) -> Matrix | NA:
|
|
168
|
+
"""
|
|
169
|
+
Return a new matrix resulting from subtraction.
|
|
170
|
+
|
|
171
|
+
:param id1: Matrix to subtract from.
|
|
172
|
+
:param id2: Matrix object or scalar value to be subtracted.
|
|
173
|
+
:return: A new matrix containing the difference.
|
|
174
|
+
"""
|
|
175
|
+
if isinstance(id1, NA) or isinstance(id2, NA):
|
|
176
|
+
return NA(Matrix)
|
|
177
|
+
return id1.diff(id2)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
# noinspection PyShadowingBuiltins
|
|
181
|
+
def eigenvalues(id: Matrix | NA) -> list[float | int] | NA:
|
|
182
|
+
"""
|
|
183
|
+
Return an array containing the eigenvalues of a square matrix.
|
|
184
|
+
|
|
185
|
+
:param id: A matrix object.
|
|
186
|
+
:return: An array containing the eigenvalues.
|
|
187
|
+
"""
|
|
188
|
+
if isinstance(id, NA):
|
|
189
|
+
return NA(list)
|
|
190
|
+
return id.eigenvalues()
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
# noinspection PyShadowingBuiltins
|
|
194
|
+
def eigenvectors(id: Matrix | NA) -> Matrix | NA:
|
|
195
|
+
"""
|
|
196
|
+
Return a matrix of eigenvectors.
|
|
197
|
+
|
|
198
|
+
:param id: A matrix object.
|
|
199
|
+
:return: A new matrix containing the eigenvectors.
|
|
200
|
+
"""
|
|
201
|
+
if isinstance(id, NA):
|
|
202
|
+
return NA(Matrix)
|
|
203
|
+
return id.eigenvectors()
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
# noinspection PyShadowingBuiltins
|
|
207
|
+
def elements_count(id: Matrix | NA) -> int | NA:
|
|
208
|
+
"""
|
|
209
|
+
Return the total number of all matrix elements.
|
|
210
|
+
|
|
211
|
+
:param id: A matrix object.
|
|
212
|
+
:return: The total number of elements.
|
|
213
|
+
"""
|
|
214
|
+
if isinstance(id, NA):
|
|
215
|
+
return NA(int)
|
|
216
|
+
return id.elements_count()
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
# noinspection PyShadowingBuiltins
|
|
220
|
+
def fill(id: Matrix | NA, value: Any, from_row: int = 0, to_row: int | None = None,
|
|
221
|
+
from_column: int = 0, to_column: int | None = None) -> None:
|
|
222
|
+
"""
|
|
223
|
+
Fill a rectangular area of the matrix with the specified value.
|
|
224
|
+
|
|
225
|
+
:param id: A matrix object.
|
|
226
|
+
:param value: The value to fill with.
|
|
227
|
+
:param from_row: Row index from which the fill will begin (inclusive).
|
|
228
|
+
:param to_row: Row index where the fill will end (exclusive).
|
|
229
|
+
:param from_column: Column index from which the fill will begin (inclusive).
|
|
230
|
+
:param to_column: Column index where the fill will end (exclusive).
|
|
231
|
+
"""
|
|
232
|
+
if isinstance(id, NA):
|
|
233
|
+
return
|
|
234
|
+
id.fill(value, from_row, to_row, from_column, to_column)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
# noinspection PyShadowingBuiltins,PyShadowingNames
|
|
238
|
+
def get(id: Matrix | NA, row: int, column: int) -> Any | NA:
|
|
239
|
+
"""
|
|
240
|
+
Return the element with the specified index of the matrix.
|
|
241
|
+
|
|
242
|
+
:param id: A matrix object.
|
|
243
|
+
:param row: Index of the required row.
|
|
244
|
+
:param column: Index of the required column.
|
|
245
|
+
:return: The value at the specified position.
|
|
246
|
+
"""
|
|
247
|
+
if isinstance(id, NA):
|
|
248
|
+
return NA(object)
|
|
249
|
+
return id.get(row, column)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
# noinspection PyShadowingBuiltins
|
|
253
|
+
def inv(id: Matrix | NA) -> Matrix | NA:
|
|
254
|
+
"""
|
|
255
|
+
Return the inverse of a square matrix.
|
|
256
|
+
|
|
257
|
+
:param id: A matrix object.
|
|
258
|
+
:return: A new matrix which is the inverse.
|
|
259
|
+
"""
|
|
260
|
+
if isinstance(id, NA):
|
|
261
|
+
return NA(Matrix)
|
|
262
|
+
return id.inv()
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
# noinspection PyShadowingBuiltins
|
|
266
|
+
def is_antidiagonal(id: Matrix | NA) -> bool | NA:
|
|
267
|
+
"""
|
|
268
|
+
Determine if the matrix is anti-diagonal.
|
|
269
|
+
|
|
270
|
+
:param id: Matrix object to test.
|
|
271
|
+
:return: True if the matrix is anti-diagonal, False otherwise.
|
|
272
|
+
"""
|
|
273
|
+
if isinstance(id, NA):
|
|
274
|
+
return NA(bool)
|
|
275
|
+
return id.is_antidiagonal()
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
# noinspection PyShadowingBuiltins
|
|
279
|
+
def is_antisymmetric(id: Matrix | NA) -> bool | NA:
|
|
280
|
+
"""
|
|
281
|
+
Determine if a matrix is antisymmetric.
|
|
282
|
+
|
|
283
|
+
:param id: Matrix object to test.
|
|
284
|
+
:return: True if the matrix is antisymmetric, False otherwise.
|
|
285
|
+
"""
|
|
286
|
+
if isinstance(id, NA):
|
|
287
|
+
return NA(bool)
|
|
288
|
+
return id.is_antisymmetric()
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
# noinspection PyShadowingBuiltins
|
|
292
|
+
def is_binary(id: Matrix | NA) -> bool | NA:
|
|
293
|
+
"""
|
|
294
|
+
Determine if the matrix is binary.
|
|
295
|
+
|
|
296
|
+
:param id: Matrix object to test.
|
|
297
|
+
:return: True if the matrix is binary, False otherwise.
|
|
298
|
+
"""
|
|
299
|
+
if isinstance(id, NA):
|
|
300
|
+
return NA(bool)
|
|
301
|
+
return id.is_binary()
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
# noinspection PyShadowingBuiltins
|
|
305
|
+
def is_diagonal(id: Matrix | NA) -> bool | NA:
|
|
306
|
+
"""
|
|
307
|
+
Determine if the matrix is diagonal.
|
|
308
|
+
|
|
309
|
+
:param id: Matrix object to test.
|
|
310
|
+
:return: True if the matrix is diagonal, False otherwise.
|
|
311
|
+
"""
|
|
312
|
+
if isinstance(id, NA):
|
|
313
|
+
return NA(bool)
|
|
314
|
+
return id.is_diagonal()
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
# noinspection PyShadowingBuiltins
|
|
318
|
+
def is_identity(id: Matrix | NA) -> bool | NA:
|
|
319
|
+
"""
|
|
320
|
+
Determine if a matrix is an identity matrix.
|
|
321
|
+
|
|
322
|
+
:param id: Matrix object to test.
|
|
323
|
+
:return: True if the matrix is identity, False otherwise.
|
|
324
|
+
"""
|
|
325
|
+
if isinstance(id, NA):
|
|
326
|
+
return NA(bool)
|
|
327
|
+
return id.is_identity()
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
# noinspection PyShadowingBuiltins
|
|
331
|
+
def is_square(id: Matrix | NA) -> bool | NA:
|
|
332
|
+
"""
|
|
333
|
+
Determine if the matrix is square.
|
|
334
|
+
|
|
335
|
+
:param id: Matrix object to test.
|
|
336
|
+
:return: True if the matrix is square, False otherwise.
|
|
337
|
+
"""
|
|
338
|
+
if isinstance(id, NA):
|
|
339
|
+
return NA(bool)
|
|
340
|
+
return id.is_square()
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
# noinspection PyShadowingBuiltins
|
|
344
|
+
def is_stochastic(id: Matrix | NA) -> bool | NA:
|
|
345
|
+
"""
|
|
346
|
+
Determine if the matrix is stochastic.
|
|
347
|
+
|
|
348
|
+
:param id: Matrix object to test.
|
|
349
|
+
:return: True if the matrix is stochastic, False otherwise.
|
|
350
|
+
"""
|
|
351
|
+
if isinstance(id, NA):
|
|
352
|
+
return NA(bool)
|
|
353
|
+
return id.is_stochastic()
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
# noinspection PyShadowingBuiltins
|
|
357
|
+
def is_symmetric(id: Matrix | NA) -> bool | NA:
|
|
358
|
+
"""
|
|
359
|
+
Determine if a square matrix is symmetric.
|
|
360
|
+
|
|
361
|
+
:param id: Matrix object to test.
|
|
362
|
+
:return: True if the matrix is symmetric, False otherwise.
|
|
363
|
+
"""
|
|
364
|
+
if isinstance(id, NA):
|
|
365
|
+
return NA(bool)
|
|
366
|
+
return id.is_symmetric()
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
# noinspection PyShadowingBuiltins
|
|
370
|
+
def is_triangular(id: Matrix | NA) -> bool | NA:
|
|
371
|
+
"""
|
|
372
|
+
Determine if the matrix is triangular.
|
|
373
|
+
|
|
374
|
+
:param id: Matrix object to test.
|
|
375
|
+
:return: True if the matrix is triangular, False otherwise.
|
|
376
|
+
"""
|
|
377
|
+
if isinstance(id, NA):
|
|
378
|
+
return NA(bool)
|
|
379
|
+
return id.is_triangular()
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
# noinspection PyShadowingBuiltins
|
|
383
|
+
def is_zero(id: Matrix | NA) -> bool | NA:
|
|
384
|
+
"""
|
|
385
|
+
Determine if all elements of the matrix are zero.
|
|
386
|
+
|
|
387
|
+
:param id: Matrix object to check.
|
|
388
|
+
:return: True if all elements are zero, False otherwise.
|
|
389
|
+
"""
|
|
390
|
+
if isinstance(id, NA):
|
|
391
|
+
return NA(bool)
|
|
392
|
+
return id.is_zero()
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
# noinspection PyShadowingBuiltins
|
|
396
|
+
def kron(id1: Matrix | NA, id2: Matrix | NA) -> Matrix | NA:
|
|
397
|
+
"""
|
|
398
|
+
Return the Kronecker product for two matrices.
|
|
399
|
+
|
|
400
|
+
:param id1: First matrix object.
|
|
401
|
+
:param id2: Second matrix object.
|
|
402
|
+
:return: A new matrix containing the Kronecker product.
|
|
403
|
+
"""
|
|
404
|
+
if isinstance(id1, NA) or isinstance(id2, NA):
|
|
405
|
+
return NA(Matrix)
|
|
406
|
+
return id1.kron(id2)
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
# noinspection PyShadowingBuiltins
|
|
410
|
+
def max(id: Matrix | NA) -> float | int | NA:
|
|
411
|
+
"""
|
|
412
|
+
Return the largest value from the matrix elements.
|
|
413
|
+
|
|
414
|
+
:param id: A matrix object.
|
|
415
|
+
:return: The maximum value from the matrix.
|
|
416
|
+
"""
|
|
417
|
+
if isinstance(id, NA):
|
|
418
|
+
return na_float
|
|
419
|
+
return id.max()
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
# noinspection PyShadowingBuiltins
|
|
423
|
+
def median(id: Matrix | NA) -> float | int | NA:
|
|
424
|
+
"""
|
|
425
|
+
Calculate the median of matrix elements.
|
|
426
|
+
|
|
427
|
+
:param id: A matrix object.
|
|
428
|
+
:return: The median value from the matrix.
|
|
429
|
+
"""
|
|
430
|
+
if isinstance(id, NA):
|
|
431
|
+
return na_float
|
|
432
|
+
return id.median()
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
# noinspection PyShadowingBuiltins
|
|
436
|
+
def min(id: Matrix | NA) -> float | int | NA:
|
|
437
|
+
"""
|
|
438
|
+
Return the smallest value from the matrix elements.
|
|
439
|
+
|
|
440
|
+
:param id: A matrix object.
|
|
441
|
+
:return: The minimum value from the matrix.
|
|
442
|
+
"""
|
|
443
|
+
if isinstance(id, NA):
|
|
444
|
+
return na_float
|
|
445
|
+
return id.min()
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
# noinspection PyShadowingBuiltins
|
|
449
|
+
def mode(id: Matrix | NA) -> float | int | NA:
|
|
450
|
+
"""
|
|
451
|
+
Calculate the mode of the matrix.
|
|
452
|
+
|
|
453
|
+
:param id: A matrix object.
|
|
454
|
+
:return: The most frequently occurring value from the matrix.
|
|
455
|
+
"""
|
|
456
|
+
if isinstance(id, NA):
|
|
457
|
+
return na_float
|
|
458
|
+
return id.mode()
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
# noinspection PyShadowingBuiltins
|
|
462
|
+
def mult(id1: Matrix | NA, id2: Matrix | list[Any] | int | float | NA) -> Matrix | list[Any] | NA:
|
|
463
|
+
"""
|
|
464
|
+
Return the product of matrices, matrix and vector, or matrix and scalar.
|
|
465
|
+
|
|
466
|
+
:param id1: First matrix object.
|
|
467
|
+
:param id2: Second matrix object, array, or scalar value.
|
|
468
|
+
:return: A new matrix or array containing the product.
|
|
469
|
+
"""
|
|
470
|
+
if isinstance(id1, NA) or isinstance(id2, NA):
|
|
471
|
+
return NA(Matrix)
|
|
472
|
+
return id1.mult(id2)
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
# noinspection PyShadowingBuiltins
|
|
476
|
+
def pinv(id: Matrix | NA) -> Matrix | NA:
|
|
477
|
+
"""
|
|
478
|
+
Return the pseudoinverse of a matrix.
|
|
479
|
+
|
|
480
|
+
:param id: A matrix object.
|
|
481
|
+
:return: A new matrix containing the pseudoinverse.
|
|
482
|
+
"""
|
|
483
|
+
if isinstance(id, NA):
|
|
484
|
+
return NA(Matrix)
|
|
485
|
+
return id.pinv()
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
# noinspection PyShadowingBuiltins
|
|
489
|
+
def pow(id: Matrix | NA, power: int) -> Matrix | NA:
|
|
490
|
+
"""
|
|
491
|
+
Calculate the product of the matrix by itself power times.
|
|
492
|
+
|
|
493
|
+
:param id: A matrix object.
|
|
494
|
+
:param power: The number of times the matrix will be multiplied by itself.
|
|
495
|
+
:return: The matrix raised to the specified power.
|
|
496
|
+
"""
|
|
497
|
+
if isinstance(id, NA):
|
|
498
|
+
return NA(Matrix)
|
|
499
|
+
return id.pow(power)
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
# noinspection PyShadowingBuiltins
|
|
503
|
+
def rank(id: Matrix | NA) -> int | NA:
|
|
504
|
+
"""
|
|
505
|
+
Calculate the rank of the matrix.
|
|
506
|
+
|
|
507
|
+
:param id: A matrix object.
|
|
508
|
+
:return: The rank of the matrix.
|
|
509
|
+
"""
|
|
510
|
+
if isinstance(id, NA):
|
|
511
|
+
return NA(int)
|
|
512
|
+
return id.rank()
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
# noinspection PyShadowingBuiltins
|
|
516
|
+
def remove_col(id: Matrix | NA, column: int | None = None) -> list[Any] | NA:
|
|
517
|
+
"""
|
|
518
|
+
Remove the column at the specified index and return its values.
|
|
519
|
+
|
|
520
|
+
:param id: A matrix object.
|
|
521
|
+
:param column: The index of the column to be removed.
|
|
522
|
+
:return: An array containing the removed column's values.
|
|
523
|
+
"""
|
|
524
|
+
if isinstance(id, NA):
|
|
525
|
+
return NA(list)
|
|
526
|
+
return id.remove_col(column)
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
# noinspection PyShadowingBuiltins,PyShadowingNames
|
|
530
|
+
def remove_row(id: Matrix | NA, row: int | None = None) -> list[Any] | NA:
|
|
531
|
+
"""
|
|
532
|
+
Remove the row at the specified index and return its values.
|
|
533
|
+
|
|
534
|
+
:param id: A matrix object.
|
|
535
|
+
:param row: The index of the row to be removed.
|
|
536
|
+
:return: An array containing the removed row's values.
|
|
537
|
+
"""
|
|
538
|
+
if isinstance(id, NA):
|
|
539
|
+
return NA(list)
|
|
540
|
+
return id.remove_row(row)
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
# noinspection PyShadowingBuiltins,PyShadowingNames
|
|
544
|
+
def reshape(id: Matrix | NA, rows: int, columns: int) -> None:
|
|
545
|
+
"""
|
|
546
|
+
Rebuild the matrix to the specified dimensions.
|
|
547
|
+
|
|
548
|
+
:param id: A matrix object.
|
|
549
|
+
:param rows: The number of rows of the reshaped matrix.
|
|
550
|
+
:param columns: The number of columns of the reshaped matrix.
|
|
551
|
+
"""
|
|
552
|
+
if isinstance(id, NA):
|
|
553
|
+
return
|
|
554
|
+
id.reshape(rows, columns)
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
# noinspection PyShadowingBuiltins
|
|
558
|
+
def reverse(id: Matrix | NA) -> None:
|
|
559
|
+
"""
|
|
560
|
+
Reverse the order of rows and columns in the matrix.
|
|
561
|
+
|
|
562
|
+
:param id: A matrix object.
|
|
563
|
+
"""
|
|
564
|
+
if isinstance(id, NA):
|
|
565
|
+
return
|
|
566
|
+
id.reverse()
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
# noinspection PyShadowingBuiltins,PyShadowingNames
|
|
570
|
+
def row(id: Matrix | NA, row: int) -> list[Any] | NA:
|
|
571
|
+
"""
|
|
572
|
+
Create a one-dimensional array from the elements of a matrix row.
|
|
573
|
+
|
|
574
|
+
:param id: A matrix object.
|
|
575
|
+
:param row: Index of the required row.
|
|
576
|
+
:return: An array containing the row values.
|
|
577
|
+
"""
|
|
578
|
+
if isinstance(id, NA):
|
|
579
|
+
return NA(list)
|
|
580
|
+
return id.row(row)
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
# noinspection PyShadowingBuiltins
|
|
584
|
+
def rows(id: Matrix | NA) -> int | NA:
|
|
585
|
+
"""
|
|
586
|
+
Return the number of rows in the matrix.
|
|
587
|
+
|
|
588
|
+
:param id: A matrix object.
|
|
589
|
+
:return: The number of rows.
|
|
590
|
+
"""
|
|
591
|
+
if isinstance(id, NA):
|
|
592
|
+
return NA(int)
|
|
593
|
+
return id.rows
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
# noinspection PyShadowingBuiltins,PyShadowingNames
|
|
597
|
+
def set(id: Matrix | NA, row: int, column: int, value: Any) -> None:
|
|
598
|
+
"""
|
|
599
|
+
Assign value to the element at the specified row and column.
|
|
600
|
+
|
|
601
|
+
:param id: A matrix object.
|
|
602
|
+
:param row: The row index of the element to be modified.
|
|
603
|
+
:param column: The column index of the element to be modified.
|
|
604
|
+
:param value: The new value to be set.
|
|
605
|
+
"""
|
|
606
|
+
if isinstance(id, NA):
|
|
607
|
+
return
|
|
608
|
+
id.set(row, column, value)
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
# noinspection PyShadowingBuiltins
|
|
612
|
+
def sort(id: Matrix | NA, column: int = 0, order: str = 'ascending') -> None:
|
|
613
|
+
"""
|
|
614
|
+
Rearrange rows following the sorted order of values in the specified column.
|
|
615
|
+
|
|
616
|
+
:param id: A matrix object to be sorted.
|
|
617
|
+
:param column: Index of the column whose sorted values determine the new order of rows.
|
|
618
|
+
:param order: The sort order ('ascending' or 'descending').
|
|
619
|
+
"""
|
|
620
|
+
if isinstance(id, NA):
|
|
621
|
+
return
|
|
622
|
+
id.sort(column, order)
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
# noinspection PyShadowingBuiltins
|
|
626
|
+
def submatrix(id: Matrix | NA, from_row: int = 0, to_row: int | None = None,
|
|
627
|
+
from_column: int = 0, to_column: int | None = None) -> Matrix | NA:
|
|
628
|
+
"""
|
|
629
|
+
Extract a submatrix within the specified indices.
|
|
630
|
+
|
|
631
|
+
:param id: A matrix object.
|
|
632
|
+
:param from_row: Row index from which extraction begins (inclusive).
|
|
633
|
+
:param to_row: Row index where extraction ends (exclusive).
|
|
634
|
+
:param from_column: Column index from which extraction begins (inclusive).
|
|
635
|
+
:param to_column: Column index where extraction ends (exclusive).
|
|
636
|
+
:return: A new matrix containing the submatrix.
|
|
637
|
+
"""
|
|
638
|
+
if isinstance(id, NA):
|
|
639
|
+
return NA(Matrix)
|
|
640
|
+
return id.submatrix(from_row, to_row, from_column, to_column)
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
# noinspection PyShadowingBuiltins
|
|
644
|
+
def sum(id1: Matrix | NA, id2: Matrix | int | float | NA) -> Matrix | NA:
|
|
645
|
+
"""
|
|
646
|
+
Return a new matrix resulting from addition.
|
|
647
|
+
|
|
648
|
+
:param id1: First matrix object.
|
|
649
|
+
:param id2: Second matrix object or scalar value.
|
|
650
|
+
:return: A new matrix containing the sum.
|
|
651
|
+
"""
|
|
652
|
+
if isinstance(id1, NA) or isinstance(id2, NA):
|
|
653
|
+
return NA(Matrix)
|
|
654
|
+
return id1.sum(id2)
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
# noinspection PyShadowingBuiltins
|
|
658
|
+
def swap_columns(id: Matrix | NA, column1: int, column2: int) -> None:
|
|
659
|
+
"""
|
|
660
|
+
Swap the columns at the specified indices.
|
|
661
|
+
|
|
662
|
+
:param id: A matrix object.
|
|
663
|
+
:param column1: Index of the first column to be swapped.
|
|
664
|
+
:param column2: Index of the second column to be swapped.
|
|
665
|
+
"""
|
|
666
|
+
if isinstance(id, NA):
|
|
667
|
+
return
|
|
668
|
+
id.swap_columns(column1, column2)
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
# noinspection PyShadowingBuiltins
|
|
672
|
+
def swap_rows(id: Matrix | NA, row1: int, row2: int) -> None:
|
|
673
|
+
"""
|
|
674
|
+
Swap the rows at the specified indices.
|
|
675
|
+
|
|
676
|
+
:param id: A matrix object.
|
|
677
|
+
:param row1: Index of the first row to be swapped.
|
|
678
|
+
:param row2: Index of the second row to be swapped.
|
|
679
|
+
"""
|
|
680
|
+
if isinstance(id, NA):
|
|
681
|
+
return
|
|
682
|
+
id.swap_rows(row1, row2)
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
# noinspection PyShadowingBuiltins
|
|
686
|
+
def trace(id: Matrix | NA) -> float | int | NA:
|
|
687
|
+
"""
|
|
688
|
+
Calculate the trace of a matrix.
|
|
689
|
+
|
|
690
|
+
:param id: A matrix object.
|
|
691
|
+
:return: The trace value of the matrix.
|
|
692
|
+
"""
|
|
693
|
+
if isinstance(id, NA):
|
|
694
|
+
return na_float
|
|
695
|
+
return id.trace()
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
# noinspection PyShadowingBuiltins
|
|
699
|
+
def transpose(id: Matrix | NA) -> Matrix | NA:
|
|
700
|
+
"""
|
|
701
|
+
Create a new transposed version of the matrix.
|
|
702
|
+
|
|
703
|
+
:param id: A matrix object.
|
|
704
|
+
:return: A new matrix containing the transposed version.
|
|
705
|
+
"""
|
|
706
|
+
if isinstance(id, NA):
|
|
707
|
+
return NA(Matrix)
|
|
708
|
+
return id.transpose()
|