From 4404edc383e735060efa8aceb406e4a6353f1e25 Mon Sep 17 00:00:00 2001 From: Clemens Akens Date: Thu, 12 Oct 2023 16:15:31 +0200 Subject: [PATCH] Minor refactoring --- src/tensor.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tensor.zig b/src/tensor.zig index c78b64f..2378dc9 100644 --- a/src/tensor.zig +++ b/src/tensor.zig @@ -8,16 +8,16 @@ pub fn Tensor(comptime n_dims: comptime_int) type { const Self = @This(); allocator: ?std.mem.Allocator, - data: []f32, sub_dims: [n_dims - 1]usize, + data: []f32, pub fn init(allocator: std.mem.Allocator, dims: [n_dims]usize) !Self { const data_size = @reduce(.Mul, @as(@Vector(n_dims, usize), dims)); return .{ .allocator = allocator, - .data = try allocator.alloc(f32, data_size), .sub_dims = dims[1..].*, + .data = try allocator.alloc(f32, data_size), }; } @@ -42,10 +42,10 @@ pub fn Tensor(comptime n_dims: comptime_int) type { const sub_data_size = @reduce(.Mul, @as(@Vector(n_dims - 1, usize), self.sub_dims)); - return Tensor(n_dims - 1){ + return .{ .allocator = null, - .data = self.data[index * sub_data_size ..][0..sub_data_size], .sub_dims = self.sub_dims[1..].*, + .data = self.data[index * sub_data_size ..][0..sub_data_size], }; }