lib/accy/src/executable/composition/element.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

 1 const std = @import("std");
 2 const choir_abi = @import("choir_abi");
 3 const choir = @import("choir");
 4 const accy_root = @import("../../root.zig");
 5 
 6 pub fn elementType(value: choir_abi.DType) choir.composition.ElementType {
 7     return switch (value) {
 8         .i1 => .i1,
 9         .i8 => .i8,
10         .i16 => .i16,
11         .i32 => .i32,
12         .i64 => .i64,
13         .u8 => .u8,
14         .u16 => .u16,
15         .u32 => .u32,
16         .u64 => .u64,
17         .f16 => .f16,
18         .bf16 => .bf16,
19         .f32 => .f32,
20         .f64 => .f64,
21         .key => .key,
22     };
23 }
24 
25 pub fn dtype(element_type: choir.composition.ElementType) choir_abi.DType {
26     return switch (element_type) {
27         .i1 => .i1,
28         .i8 => .i8,
29         .i16 => .i16,
30         .i32 => .i32,
31         .i64 => .i64,
32         .u8 => .u8,
33         .u16 => .u16,
34         .u32 => .u32,
35         .u64 => .u64,
36         .f16 => .f16,
37         .bf16 => .bf16,
38         .f32 => .f32,
39         .f64 => .f64,
40         .key => .key,
41     };
42 }
43 
44 test "Accy and composition element types round-trip" {
45     inline for (std.meta.tags(choir_abi.DType)) |value| {
46         try std.testing.expectEqual(value, dtype(elementType(value)));
47     }
48 }