diff --git a/specs/ml/file_io_contract.t27 b/specs/ml/file_io_contract.t27 index 07969972ec..6ea9b36c56 100644 --- a/specs/ml/file_io_contract.t27 +++ b/specs/ml/file_io_contract.t27 @@ -235,7 +235,7 @@ pub fn get_u32(buf: []const u8, off: i32) -> u32 { return x; } -fn byte_sum(buf: []const u8, n: i32) -> u32 { +pub fn byte_sum(buf: []const u8, n: i32) -> u32 { var s : u32 = 0; var i : i32 = 0; while (i < n) { diff --git a/specs/ml/train_slice_model.t27 b/specs/ml/train_slice_model.t27 index 332cce6ded..3698852929 100644 --- a/specs/ml/train_slice_model.t27 +++ b/specs/ml/train_slice_model.t27 @@ -95,17 +95,6 @@ fn get_f32(buf: []const u8, off: i32) -> f64 { return @floatCast(f); } -fn byte_total(buf: []const u8, n: i32) -> u32 { - var s : u32 = 0; - var i : i32 = 0; - while (i < n) { - const b : u32 = @intCast(buf[@intCast(i)]); - s = s + b; - i = i + 1; - } - return s; -} - /// Train the slice for `steps` steps of learning rate `lr` from its fixed initial state. /// losses[0] is the mean loss before any step, losses[1] the mean loss after the last one. pub fn train(steps: u32, lr: f64, losses: []f64) -> void { @@ -148,7 +137,7 @@ pub fn pack(buf: []u8, steps: u32, losses: []const f64) -> void { buf[@intCast(OFF_TRITS + k)] = code; k = k + 1; } - put_u32(buf, OFF_SUM, byte_total(buf, OFF_SUM)); + put_u32(buf, OFF_SUM, byte_sum(buf, OFF_SUM)); } /// Accept a checkpoint image only if its magic, its checksum and the losses it carries are right: @@ -157,7 +146,7 @@ pub fn check_image(buf: []const u8) -> i32 { if (buf[0] != MAGIC0 or buf[1] != MAGIC1 or buf[2] != MAGIC2 or buf[3] != MAGIC3) { return TRAIN_ERR_MAGIC; } - if (get_u32(buf, OFF_SUM) != byte_total(buf, OFF_SUM)) { + if (get_u32(buf, OFF_SUM) != byte_sum(buf, OFF_SUM)) { return TRAIN_ERR_SUM; } const first : f64 = get_f32(buf, OFF_FIRST);