rsnumpy 0.1.6__tar.gz → 0.1.7__tar.gz

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.
@@ -14,6 +14,7 @@ dist/
14
14
  build/
15
15
  *.egg
16
16
  .venv/
17
+ test/
17
18
  venv/
18
19
  uv.lock
19
20
 
@@ -32,6 +33,7 @@ Thumbs.db
32
33
  push*.sh
33
34
  main*.py
34
35
  test*.py
36
+ run*.py
35
37
  debug*.py
36
38
  check*.py
37
39
 
@@ -669,7 +669,7 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3"
669
669
 
670
670
  [[package]]
671
671
  name = "rsnumpy"
672
- version = "0.1.6"
672
+ version = "0.1.7"
673
673
  dependencies = [
674
674
  "ndarray",
675
675
  "num-traits",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "rsnumpy"
3
- version = "0.1.6"
3
+ version = "0.1.7"
4
4
  edition = "2024"
5
5
  readme = "README.md"
6
6
 
@@ -1,13 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rsnumpy
3
- Version: 0.1.6
3
+ Version: 0.1.7
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: Implementation :: CPython
7
7
  Classifier: Programming Language :: Python :: Implementation :: PyPy
8
- Requires-Dist: maturin>=1.14.0
9
- Requires-Dist: rsplotlib>=0.1.4
10
- Requires-Dist: xlrd>=2.0.2
11
8
  License-File: LICENSE
12
9
  Summary: A Rust-powered NumPy-compatible array library.
13
10
  Author: YJ-Niu
@@ -6,10 +6,16 @@ set -euo pipefail
6
6
 
7
7
  RELEASE=true
8
8
  OUT_DIR="wheelhouse"
9
+ cache_file="/Users/user/Desktop/rust_project/rsplotlib/python/rsplotlib/rsplotlib.cpython-313-darwin.so"
9
10
  # 如果 wheelhouse 目录存在, 则删除
10
11
  if [[ -d "$OUT_DIR" ]]; then
11
12
  rm -rf "$OUT_DIR"
12
13
  fi
14
+ # 如果 cache_file 目录存在, 则删除
15
+ if [[ -f "$cache_file" ]]; then
16
+ rm "$cache_file"
17
+ fi
18
+
13
19
  # Default python executable; may be overridden by --python or positional arg
14
20
  PYTHON_EXEC="python"
15
21
  # Flag set when the user explicitly provided a Python executable
@@ -70,18 +76,6 @@ if [[ -n "$WHEEL" && -f "$WHEEL" ]]; then
70
76
  else
71
77
  echo "Warning: .venv not found; skip install. Wheels available in $OUT_DIR" >&2
72
78
  fi
73
- # 同步 .so 到项目内的 rsnumpy 包目录,避免本地源包遮蔽安装的 wheel
74
- SO_FILE=".venv/lib/python${PYTHON_VERSION:-3.13}/site-packages/rsnumpy/_core.cpython-${PYTHON_VERSION:-313}-darwin.so"
75
- if [[ -f "$SO_FILE" ]]; then
76
- cp -f "$SO_FILE" "rsnumpy/_core.cpython-${PYTHON_VERSION:-313}-darwin.so" 2>/dev/null || true
77
- fi
78
- # 通用回退:找任何 .venv 中刚生成的 _core .so
79
- SO_GLOB=$(ls .venv/lib/python*/site-packages/rsnumpy/_core.cpython-*-darwin.so 2>/dev/null | head -1)
80
- if [[ -n "$SO_GLOB" && -f "$SO_GLOB" ]]; then
81
- DEST="rsnumpy/$(basename "$SO_GLOB")"
82
- cp -f "$SO_GLOB" "$DEST"
83
- echo "Synced $DEST"
84
- fi
85
79
  else
86
80
  echo "Warning: no .whl file found in $OUT_DIR; skip install." >&2
87
81
  fi
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "rsnumpy"
7
- version = "0.1.6"
7
+ version = "0.1.7"
8
8
  requires-python = ">=3.8"
9
9
  description = "A Rust-powered NumPy-compatible array library."
10
10
  readme = "README.md"
@@ -19,12 +19,8 @@ classifiers = [
19
19
  "Programming Language :: Python :: Implementation :: PyPy",
20
20
  ]
21
21
  dynamic = ["version"]
22
- dependencies = [
23
- "maturin>=1.14.0",
24
- "rsplotlib>=0.1.4",
25
- "xlrd>=2.0.2",
26
- ]
27
22
 
28
23
  [tool.maturin]
29
24
  module-name = "rsnumpy._core"
30
- include = ["rsnumpy/__init__.py", "rsnumpy/linalg/__init__.py", "rsnumpy/random/__init__.py"]
25
+ python-source = "python"
26
+ include = ["python/rsnumpy/__init__.py", "python/rsnumpy/linalg/__init__.py", "python/rsnumpy/random/__init__.py"]
@@ -66,6 +66,9 @@ class ndarray:
66
66
  def __repr__(self):
67
67
  return repr(self._array)
68
68
 
69
+ def __str__(self):
70
+ return str(self._array)
71
+
69
72
  def __len__(self):
70
73
  if self.ndim == 0:
71
74
  raise TypeError("len() of unsized object")
@@ -107,13 +107,9 @@ fn format_array_repr(arr: &Array<f64, IxDyn>, _prefix: &str) -> String {
107
107
  let mut s = String::from("[");
108
108
  for (i, val) in arr.iter().enumerate() {
109
109
  if i > 0 {
110
- s.push_str(", ");
111
- }
112
- if *val == val.floor() && val.is_finite() {
113
- s.push_str(&format!("{}.", val));
114
- } else {
115
- s.push_str(&format!("{}", val));
110
+ s.push_str(" ");
116
111
  }
112
+ s.push_str(&format_scalar(*val));
117
113
  }
118
114
  s.push(']');
119
115
  return s;
@@ -122,17 +118,34 @@ fn format_array_repr(arr: &Array<f64, IxDyn>, _prefix: &str) -> String {
122
118
  let n = arr.shape()[0];
123
119
  for i in 0..n {
124
120
  if i > 0 {
125
- s.push_str(",\n");
121
+ s.push_str("\n ");
126
122
  }
127
123
  let sub = arr.index_axis(Axis(0), i).to_owned().into_dyn();
128
124
  let row_str = format_array_repr(&sub, "");
129
- s.push_str(" ");
130
125
  s.push_str(&row_str);
131
126
  }
132
127
  s.push_str("]");
133
128
  s
134
129
  }
135
130
 
131
+ fn format_scalar(val: f64) -> String {
132
+ if val.is_nan() {
133
+ return "nan".to_string();
134
+ }
135
+ if val.is_infinite() {
136
+ return if val > 0.0 { "inf".to_string() } else { "-inf".to_string() };
137
+ }
138
+ if val == val.floor() && val.is_finite() && val.abs() < 1e16 {
139
+ // 整数值不显示小数点,与 numpy print 输出一致
140
+ let v = val as i64;
141
+ if v as f64 == val {
142
+ return format!("{}", v);
143
+ }
144
+ }
145
+ let s = format!("{}", val);
146
+ s
147
+ }
148
+
136
149
  /// NdArray: 类似 NumPy ndarray 的多维数组
137
150
  #[pyclass(name = "ndarray", from_py_object)]
138
151
  #[derive(Clone)]
@@ -161,6 +174,11 @@ impl NdArray {
161
174
  Ok(format!("rsnumpy.ndarray({}) dtype=float64", arr_str))
162
175
  }
163
176
 
177
+ fn __str__(&self) -> PyResult<String> {
178
+ let arr_str = format_array_repr(&self.data, "");
179
+ Ok(arr_str)
180
+ }
181
+
164
182
  fn __len__(&self) -> PyResult<usize> {
165
183
  if self.data.ndim() == 0 {
166
184
  return Err(PyTypeError::new_err("len() of unsized object"));
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes