Skip to content

Commit d4e772e

Browse files
committed
fix: align tensor stdlib wrappers and ZRTL plugin signatures
Fix mismatches between tensor.zynml method wrappers and ZRTL C function signatures that caused the remaining 4 CRANELIFT WARN arg-count errors: - shape(self) → shape(self, dim) to match per-dimension ZRTL API - transpose(self) → transpose(self, dim0, dim1), remove phantom transpose_axes - get/set: switch from List-based to flat-index f32 API (tensor_get_f32/set_f32) - slice: switch from List-based to per-dimension API (dim, start, end) - squeeze registration: remove extra u32 param not in C function - slice registration: remove extra i64 param not in C function - plugins/Cargo.toml: fix [lints] → [workspace.lints] for workspace build
1 parent 2354212 commit d4e772e

3 files changed

Lines changed: 20 additions & 18 deletions

File tree

crates/zynml/stdlib/tensor.zynml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ impl Tensor {
136136
// ============================================================================
137137

138138
impl Tensor {
139-
// Shape and dimensions - ZRTL returns different types, use wrappers
140-
def shape(self): List<i64> {
141-
extern tensor_shape(self)
139+
// Shape and dimensions - ZRTL returns size of a single dimension
140+
// Usage: t.shape(0) returns size of dim 0, t.shape(1) returns size of dim 1
141+
def shape(self, dim: i64): i64 {
142+
extern tensor_shape(self, dim)
142143
}
143144
def ndim(self): i64 {
144145
extern tensor_ndim(self)
@@ -185,11 +186,10 @@ impl Tensor {
185186
def reshape(self, shape: List<i64>): Tensor {
186187
extern tensor_reshape(self, shape.data, shape.len)
187188
}
188-
def transpose(self): Tensor {
189-
extern tensor_transpose(self)
190-
}
191-
def transpose_axes(self, dim0: i64, dim1: i64): Tensor {
192-
extern tensor_transpose_axes(self, dim0, dim1)
189+
// Transpose: swap two dimensions
190+
// Usage: t.transpose(0, 1) swaps dim 0 and dim 1
191+
def transpose(self, dim0: i64, dim1: i64): Tensor {
192+
extern tensor_transpose(self, dim0, dim1)
193193
}
194194
def flatten(self): Tensor {
195195
extern tensor_flatten(self)
@@ -233,14 +233,17 @@ impl Tensor {
233233
}
234234

235235
// Indexing and slicing
236-
def get(self, indices: List<i64>): f64 {
237-
extern tensor_get(self, indices)
236+
// ZRTL get/set use flat index (i64), not multi-dim List
237+
def get(self, index: i64): f32 {
238+
extern tensor_get_f32(self, index)
238239
}
239-
def set(self, indices: List<i64>, value: f64) {
240-
extern tensor_set(self, indices, value)
240+
def set(self, index: i64, value: f32) {
241+
extern tensor_set_f32(self, index, value)
241242
}
242-
def slice(self, start: List<i64>, end: List<i64>): Tensor {
243-
extern tensor_slice(self, start, end)
243+
// Slice along a single dimension: t.slice(dim, start, end)
244+
// Usage: t.slice(0, 2, 5) slices dim 0 from index 2 to 5
245+
def slice(self, dim: i64, start: i64, end: i64): Tensor {
246+
extern tensor_slice(self, dim, start, end)
244247
}
245248

246249
// Comparison (returns boolean tensor) - use wrappers

plugins/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,4 @@ zrtl = { path = "../sdk/zrtl" }
4040
thiserror = "2.0"
4141
log = "0.4"
4242

43-
[lints]
44-
workspace = true
43+
[workspace.lints]

plugins/zrtl_tensor/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,9 +1995,9 @@ zrtl_plugin! {
19951995
// Shape operations - return new tensors
19961996
("$Tensor$reshape", tensor_reshape, (i64, i64, u32) -> opaque),
19971997
("$Tensor$transpose", tensor_transpose, (i64, u32, u32) -> opaque),
1998-
("$Tensor$squeeze", tensor_squeeze, (i64, u32) -> opaque),
1998+
("$Tensor$squeeze", tensor_squeeze, (i64) -> opaque),
19991999
("$Tensor$unsqueeze", tensor_unsqueeze, (i64, u32) -> opaque),
2000-
("$Tensor$slice", tensor_slice, (i64, u32, i64, i64, i64) -> opaque),
2000+
("$Tensor$slice", tensor_slice, (i64, u32, i64, i64) -> opaque),
20012001

20022002
// Reductions - return scalars
20032003
("$Tensor$sum_f32", tensor_sum_f32, (i64) -> f32),

0 commit comments

Comments
 (0)