import mir.ndslice.slice: Slice; auto tensor = slice!int(5, 6, 7); assert(tensor.length == 5); assert(tensor.length!1 == 6); assert(tensor.elementCount == 5 * 6 * 7); static assert(is(typeof(tensor) == Slice!(int*, 3)));
2D DataFrame example
import mir.ndslice.slice; import mir.ndslice.allocation: slice; import mir.date: Date; auto dataframe = slice!(double, Date, string)(4, 3); assert(dataframe.length == 4); assert(dataframe.length!1 == 3); assert(dataframe.elementCount == 4 * 3); static assert(is(typeof(dataframe) == Slice!(double*, 2, Contiguous, Date*, string*))); // Dataframe labels are contiguous 1-dimensional slices. // Fill row labels dataframe.label[] = [ Date(2019, 1, 24), Date(2019, 2, 2), Date(2019, 2, 4), Date(2019, 2, 5), ]; assert(dataframe.label!0[2] == Date(2019, 2, 4)); // Fill column labels dataframe.label!1[] = ["income", "outcome", "balance"]; assert(dataframe.label!1[2] == "balance"); // Change label element dataframe.label!1[2] = "total"; assert(dataframe.label!1[2] == "total"); // Attach a newly allocated label dataframe.label!1 = ["Income", "Outcome", "Balance"].sliced; assert(dataframe.label!1[2] == "Balance");
GC-Allocates an n-dimensional slice.