Suppose I have something like this:
// initFromSlice2d is declared like:
// pub fn initFromSlice2d(alloc: std.mem.Allocator, initial: []const []const f32) @This()
const mat3x3 = [_][3]f32{
[_]f32{ 1, 2, 3 },
[_]f32{ 4, 5, 6 },
[_]f32{ 7, 8, 9 },
};
var tens2d = Ndarray(f32).initFromSlice2d(arena.allocator(), &mat3x3);
Leads to the following error:
src\ndarray.zig:530:66: error: expected type '[]const []const f32', found '*const [3][3]f32'
var tens2d = Ndarray(f32).initFromSlice2d(arena.allocator(), &mat3x3);
^~~~~~~
src\ndarray.zig:530:66: note: pointer type child '[3]f32' cannot cast into pointer type child '[]const f32'
src\ndarray.zig:147:67: note: parameter type declared here
pub fn initFromSlice2d(alloc: std.mem.Allocator, initial: []const []const f32) @This() {
^~~~~~~~~~~~~~~~~~~
without the address-of operator I get this:
src\ndarray.zig:530:66: error: array literal requires address-of operator (&) to coerce to slice type '[]const []const f32'
var tens2d = Ndarray(f32).initFromSlice2d(arena.allocator(), mat3x3);
^~~~~~
How do I pass this into a function that takes a slice of slices as input? (Not a fixed size array like above).
I think I get why I can’t pass the “just 9 floats” to a function that takes a slice of slices… but is there a convenient way to convert from the former format to the latter? I think I’m pretty ok with Zig in general, but keep butting my head against array literals.