Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion specs/ml/file_io_contract.t27
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 2 additions & 13 deletions specs/ml/train_slice_model.t27
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand All @@ -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);
Expand Down
Loading