mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-29 12:37:08 -06:00
G2: improve editing reliability and Windows rendering fidelity
This commit is contained in:
@@ -196,9 +196,9 @@ pub mod sha256 {
|
||||
tail.push(0);
|
||||
}
|
||||
tail.extend_from_slice(&bits.to_be_bytes());
|
||||
for block in data[..data.len() - data.len() % 64].chunks_exact(64).chain(tail.chunks_exact(64)) {
|
||||
for block in data[..data.len() - data.len() % 64].as_chunks::<64>().0.iter().chain(tail.as_chunks::<64>().0.iter()) {
|
||||
let mut w = [0u32; 64];
|
||||
for (i, c) in block.chunks_exact(4).enumerate() {
|
||||
for (i, c) in block.as_chunks::<4>().0.iter().enumerate() {
|
||||
w[i] = u32::from_be_bytes([c[0], c[1], c[2], c[3]]);
|
||||
}
|
||||
for i in 16..64 {
|
||||
|
||||
@@ -193,7 +193,7 @@ impl FaceLandmarker {
|
||||
let out = self.mesh.run(&[&x])?;
|
||||
let (Some(pts), Some(flag)) = (out.first(), out.get(1).and_then(|f| f.first())) else { return Err("face mesh: missing outputs".into()) };
|
||||
let s = MESH_SIZE as f32;
|
||||
let points = pts.chunks_exact(3).take(MESH_POINTS).map(|p| roi.to_frame(p[0] / s, p[1] / s)).collect();
|
||||
let points = pts.as_chunks::<3>().0.iter().take(MESH_POINTS).map(|p| roi.to_frame(p[0] / s, p[1] / s)).collect();
|
||||
Ok(Face { points, score: sigmoid(*flag) })
|
||||
}
|
||||
|
||||
|
||||
@@ -340,9 +340,9 @@ fn unpickle(p: &[u8]) -> Result<Obj> {
|
||||
/// Element bytes and conversion of a storage dtype.
|
||||
fn to_f32(dtype: &str, bytes: &[u8]) -> Option<Vec<f32>> {
|
||||
match dtype {
|
||||
"FloatStorage" => Some(bytes.chunks_exact(4).map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])).collect()),
|
||||
"HalfStorage" => Some(bytes.chunks_exact(2).map(|c| half_to_f32(u16::from_le_bytes([c[0], c[1]]))).collect()),
|
||||
"BFloat16Storage" => Some(bytes.chunks_exact(2).map(|c| f32::from_bits((u16::from_le_bytes([c[0], c[1]]) as u32) << 16)).collect()),
|
||||
"FloatStorage" => Some(bytes.as_chunks::<4>().0.iter().map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])).collect()),
|
||||
"HalfStorage" => Some(bytes.as_chunks::<2>().0.iter().map(|c| half_to_f32(u16::from_le_bytes([c[0], c[1]]))).collect()),
|
||||
"BFloat16Storage" => Some(bytes.as_chunks::<2>().0.iter().map(|c| f32::from_bits((u16::from_le_bytes([c[0], c[1]]) as u32) << 16)).collect()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,13 +263,13 @@ impl Model {
|
||||
let data = bytes.get(at..at.checked_add(len).ok_or("bad buffer")?).ok_or("truncated model")?;
|
||||
match ty {
|
||||
FLOAT32 if data.len() == 4 * count => {
|
||||
floats[i] = Some(data.chunks_exact(4).map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])).collect())
|
||||
floats[i] = Some(data.as_chunks::<4>().0.iter().map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])).collect())
|
||||
}
|
||||
FLOAT16 if data.len() == 2 * count => {
|
||||
floats[i] = Some(data.chunks_exact(2).map(|c| half_to_f32(u16::from_le_bytes([c[0], c[1]]))).collect())
|
||||
floats[i] = Some(data.as_chunks::<2>().0.iter().map(|c| half_to_f32(u16::from_le_bytes([c[0], c[1]]))).collect())
|
||||
}
|
||||
INT32 if data.len() == 4 * count => {
|
||||
ints[i] = Some(data.chunks_exact(4).map(|c| i32::from_le_bytes([c[0], c[1], c[2], c[3]])).collect())
|
||||
ints[i] = Some(data.as_chunks::<4>().0.iter().map(|c| i32::from_le_bytes([c[0], c[1], c[2], c[3]])).collect())
|
||||
}
|
||||
_ => return Err(format!("{}: unsupported tensor data", names[i])),
|
||||
}
|
||||
@@ -389,7 +389,9 @@ impl Model {
|
||||
op::PAD => {
|
||||
let p = ints[input(1)?].clone().ok_or("PAD: paddings must be constant")?;
|
||||
let pads = p
|
||||
.chunks_exact(2)
|
||||
.as_chunks::<2>()
|
||||
.0
|
||||
.iter()
|
||||
.map(|c| Ok([usize::try_from(c[0]).map_err(|_| "bad pad")?, usize::try_from(c[1]).map_err(|_| "bad pad")?]))
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
Op::Pad(pads)
|
||||
|
||||
Reference in New Issue
Block a user