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
4 changes: 2 additions & 2 deletions crates/ladybug-contract/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ impl Container {
/// Construct from byte slice (little-endian).
pub fn from_bytes(bytes: &[u8; CONTAINER_BYTES]) -> Self {
let mut words = [0u64; CONTAINER_WORDS];
for (i, chunk) in bytes.chunks_exact(8).enumerate() {
words[i] = u64::from_le_bytes(chunk.try_into().unwrap());
for (i, chunk) in bytes.as_chunks::<8>().0.iter().enumerate() {
words[i] = u64::from_le_bytes(*chunk);
}
Self { words }
}
Expand Down
4 changes: 2 additions & 2 deletions crates/ladybug-contract/src/wide_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ impl WideContainer {
/// Construct from byte slice (little-endian).
pub fn from_bytes(bytes: &[u8; WIDE_BYTES]) -> Self {
let mut words = [0u64; WIDE_WORDS];
for (i, chunk) in bytes.chunks_exact(8).enumerate() {
words[i] = u64::from_le_bytes(chunk.try_into().unwrap());
for (i, chunk) in bytes.as_chunks::<8>().0.iter().enumerate() {
words[i] = u64::from_le_bytes(*chunk);
}
Self { words }
}
Expand Down
35 changes: 12 additions & 23 deletions crates/ladybug-contract/src/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
//! ```

use crate::codebook::OpCategory;
use crate::container::{Container, CONTAINER_BYTES, CONTAINER_WORDS};
use crate::container::{CONTAINER_BYTES, CONTAINER_WORDS, Container};
use crate::nars::TruthValue;

/// Magic bytes identifying a CogPacket.
Expand Down Expand Up @@ -129,12 +129,7 @@ impl CogPacket {
// =========================================================================

/// Create a request packet with a single container payload.
pub fn request(
opcode: u16,
source_addr: u16,
target_addr: u16,
payload: Container,
) -> Self {
pub fn request(opcode: u16, source_addr: u16, target_addr: u16, payload: Container) -> Self {
let mut pkt = Self {
header: [0u64; HEADER_WORDS],
payload: vec![payload],
Expand All @@ -149,12 +144,7 @@ impl CogPacket {
}

/// Create a response packet.
pub fn response(
opcode: u16,
source_addr: u16,
target_addr: u16,
payload: Container,
) -> Self {
pub fn response(opcode: u16, source_addr: u16, target_addr: u16, payload: Container) -> Self {
let mut pkt = Self::request(opcode, source_addr, target_addr, payload);
pkt.set_flags(pkt.flags() | FLAG_RESPONSE);
pkt.update_checksum();
Expand Down Expand Up @@ -273,8 +263,7 @@ impl CogPacket {
}

pub fn set_target_addr(&mut self, addr: u16) {
self.header[1] = (self.header[1] & 0xFFFF_0000_FFFF_FFFF)
| ((addr as u64) << 32);
self.header[1] = (self.header[1] & 0xFFFF_0000_FFFF_FFFF) | ((addr as u64) << 32);
}

/// Target prefix.
Expand Down Expand Up @@ -330,8 +319,7 @@ impl CogPacket {
}

pub fn set_truth_value(&mut self, tv: &TruthValue) {
self.header[3] = ((tv.frequency.to_bits() as u64) << 32)
| (tv.confidence.to_bits() as u64);
self.header[3] = ((tv.frequency.to_bits() as u64) << 32) | (tv.confidence.to_bits() as u64);
}

// =========================================================================
Expand Down Expand Up @@ -381,8 +369,7 @@ impl CogPacket {

pub fn set_resonance_threshold(&mut self, threshold: f32) {
let quantized = ((threshold.clamp(0.0, 1.0) * 65535.0) as u64) & 0xFFFF;
self.header[5] = (self.header[5] & 0x0000_FFFF_FFFF_FFFF)
| (quantized << 48);
self.header[5] = (self.header[5] & 0x0000_FFFF_FFFF_FFFF) | (quantized << 48);
}

/// Fan-out degree (0-255).
Expand Down Expand Up @@ -557,8 +544,8 @@ impl CogPacket {

// Decode header
let mut header = [0u64; HEADER_WORDS];
for (i, chunk) in data[..HEADER_BYTES].chunks_exact(8).enumerate() {
header[i] = u64::from_le_bytes(chunk.try_into().unwrap());
for (i, chunk) in data[..HEADER_BYTES].as_chunks::<8>().0.iter().enumerate() {
header[i] = u64::from_le_bytes(*chunk);
}

// Verify magic
Expand Down Expand Up @@ -594,10 +581,12 @@ impl CogPacket {
let offset = HEADER_BYTES + c_idx * CONTAINER_BYTES;
let mut words = [0u64; CONTAINER_WORDS];
for (i, chunk) in data[offset..offset + CONTAINER_BYTES]
.chunks_exact(8)
.as_chunks::<8>()
.0
.iter()
.enumerate()
{
words[i] = u64::from_le_bytes(chunk.try_into().unwrap());
words[i] = u64::from_le_bytes(*chunk);
}
payload.push(Container { words });
}
Expand Down
2 changes: 1 addition & 1 deletion examples/heartbeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::time::Instant;

use ladybug::cognitive::{GateState, get_gate_state};
use ladybug::core::Fingerprint;
use ladybug::core::simd::hamming_distance;
use ladybug::core::hamming_distance;
use ladybug::nars::TruthValue;
use ladybug::storage::{Addr, BindSpace, FINGERPRINT_WORDS};

Expand Down
2 changes: 1 addition & 1 deletion src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1848,7 +1848,7 @@ fn addr_label(bs: &BindSpace, addr: Addr) -> Option<String> {
/// Body: {"source": "0x8000", "max_hops": 3, "verb": "0x0700", "limit": 100}
fn handle_graph_traverse(body: &str, state: &SharedState, format: ResponseFormat) -> Vec<u8> {
let source_raw = extract_json_hex_u16(body, "source").unwrap_or(0x8000);
let max_hops = extract_json_usize(body, "max_hops").unwrap_or(3) as usize;
let max_hops = extract_json_usize(body, "max_hops").unwrap_or(3);
let verb_raw = extract_json_hex_u16(body, "verb");
let limit = extract_json_usize(body, "limit").unwrap_or(1000);

Expand Down
2 changes: 1 addition & 1 deletion src/cognitive/sieve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ mod tests {
#[test]
fn test_nars_revision_single() {
let tv = TruthValue::new(0.8, 0.7);
let merged = SocraticSieve::nars_revision(&[tv.clone()]);
let merged = SocraticSieve::nars_revision(&[tv]);
assert!((merged.frequency - tv.frequency).abs() < 0.01);
}

Expand Down
4 changes: 2 additions & 2 deletions src/cognitive/step_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ fn extract_fingerprint(input: &Value) -> Result<Fingerprint, StepError> {
}

let mut data = [0u64; crate::FINGERPRINT_U64];
for (i, chunk) in bytes.chunks_exact(8).take(crate::FINGERPRINT_U64).enumerate() {
data[i] = u64::from_le_bytes(chunk.try_into().unwrap());
for (i, chunk) in bytes.as_chunks::<8>().0.iter().take(crate::FINGERPRINT_U64).enumerate() {
data[i] = u64::from_le_bytes(*chunk);
}
return Ok(Fingerprint::from_raw(data));
}
Expand Down
4 changes: 1 addition & 3 deletions src/container/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ impl ContainerCache {

/// Clear all dirty bits.
pub fn clear_all_dirty(&mut self) {
for w in &mut self.dirty {
*w = 0;
}
self.dirty.fill(0);
}

/// Append a new container, growing the cache by one slot.
Expand Down
10 changes: 5 additions & 5 deletions src/container/dn_redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ pub fn cog_record_from_bytes(data: &[u8]) -> Option<CogRecord> {
let meta = parse_container(&data[..super::CONTAINER_BYTES])?;

// Parse content
let content = parse_container(
&data[super::CONTAINER_BYTES..2 * super::CONTAINER_BYTES],
)?;
let content = parse_container(&data[super::CONTAINER_BYTES..2 * super::CONTAINER_BYTES])?;

Some(CogRecord { meta, content })
}
Expand Down Expand Up @@ -221,11 +219,13 @@ fn parse_container(data: &[u8]) -> Option<Container> {
}
let mut words = [0u64; super::CONTAINER_WORDS];
for (i, chunk) in data
.chunks_exact(8)
.as_chunks::<8>()
.0
.iter()
.enumerate()
.take(super::CONTAINER_WORDS)
{
words[i] = u64::from_le_bytes(chunk.try_into().ok()?);
words[i] = u64::from_le_bytes(*chunk);
}
Some(Container { words })
}
Expand Down
10 changes: 8 additions & 2 deletions src/contract/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ pub fn deserialize_fingerprint(bytes: &[u8]) -> Option<[u64; FINGERPRINT_WORDS]>
return None;
}
let mut fp = [0u64; FINGERPRINT_WORDS];
for (i, chunk) in bytes.chunks_exact(8).take(FINGERPRINT_WORDS).enumerate() {
fp[i] = u64::from_le_bytes(chunk.try_into().ok()?);
for (i, chunk) in bytes
.as_chunks::<8>()
.0
.iter()
.take(FINGERPRINT_WORDS)
.enumerate()
{
fp[i] = u64::from_le_bytes(*chunk);
}
Some(fp)
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ impl Fingerprint {
}

let mut data = [0u64; FINGERPRINT_U64];
for (i, chunk) in bytes.chunks_exact(8).enumerate() {
data[i] = u64::from_le_bytes(chunk.try_into().unwrap());
for (i, chunk) in bytes.as_chunks::<8>().0.iter().enumerate() {
data[i] = u64::from_le_bytes(*chunk);
}
Ok(Self { data })
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/rustynum_accel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ pub fn container_bundle(items: &[&Container]) -> Container {
debug_assert_eq!(result_bytes.len(), CONTAINER_WORDS * 8);

// Write bytes back into container words
for (i, chunk) in result_bytes.chunks_exact(8).enumerate() {
container.words[i] = u64::from_ne_bytes(chunk.try_into().unwrap());
for (i, chunk) in result_bytes.as_chunks::<8>().0.iter().enumerate() {
container.words[i] = u64::from_ne_bytes(*chunk);
}

container
Expand Down
2 changes: 1 addition & 1 deletion src/cypher_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ mod tests {
fn test_parse_cypher_literal() {
assert_eq!(parse_cypher_literal("'hello'"), CypherValue::String("hello".to_string()));
assert_eq!(parse_cypher_literal("42"), CypherValue::Int(42));
assert_eq!(parse_cypher_literal("3.14"), CypherValue::Float(3.14));
assert_eq!(parse_cypher_literal("2.5"), CypherValue::Float(2.5));
assert_eq!(parse_cypher_literal("true"), CypherValue::Bool(true));
assert_eq!(parse_cypher_literal("null"), CypherValue::Null);
}
Expand Down
2 changes: 1 addition & 1 deletion src/fabric/udp_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl FramePacket {
// Convert bytes to u64 words for frame decode
let frame_bytes = &data[8..8 + FRAME_BYTES];
let mut words = [0u64; FRAME_WORDS];
for (i, chunk) in frame_bytes.chunks_exact(8).enumerate() {
for (i, chunk) in frame_bytes.as_chunks::<8>().0.iter().enumerate() {
if i < FRAME_WORDS {
words[i] = u64::from_le_bytes([
chunk[0], chunk[1], chunk[2], chunk[3], chunk[4], chunk[5], chunk[6], chunk[7],
Expand Down
6 changes: 2 additions & 4 deletions src/graph/avx_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,9 @@ pub fn batched_query(
let mut matches = Vec::new();

// Process 8 edges at a time
let chunks = graph.edges.chunks_exact(8);
let remainder = chunks.remainder();
let (chunks, remainder) = graph.edges.as_chunks::<8>();

for (chunk_idx, chunk) in chunks.enumerate() {
let edges: &[[u64; WORDS]; 8] = chunk.try_into().unwrap();
for (chunk_idx, edges) in chunks.iter().enumerate() {
let distances = batch_hamming_8(&pattern_words, edges);

for (i, &dist) in distances.iter().enumerate() {
Expand Down
3 changes: 1 addition & 2 deletions src/graph/spo/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ impl SpoBuilder {

// W1: type info with geometry=Spo(6)
meta.words[W_TYPE] = (GEOMETRY_SPO as u64) << 16
| 1u64 << 8 // container count = 1 content
| 0u64; // node_kind = 0 (generic)
| 1u64 << 8; // container count = 1 content; node_kind = 0 (generic)

// W4-W7: NARS truth
meta.words[W_NARS_BASE] = nars.frequency.to_bits() as u64;
Expand Down
1 change: 1 addition & 0 deletions src/qualia/agent_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ fn rung_description(rung: RungLevel) -> &'static str {
// ─────────────────────────────────────────────────────────────

#[cfg(test)]
#[allow(clippy::field_reassign_with_default)]
mod tests {
use super::*;
use crate::container::Container;
Expand Down
12 changes: 0 additions & 12 deletions src/query/cognitive_udfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ impl Default for HammingUdf {
}

impl ScalarUDFImpl for HammingUdf {

fn name(&self) -> &str {
"hamming"
}
Expand Down Expand Up @@ -306,7 +305,6 @@ impl Default for SimilarityUdf {
}

impl ScalarUDFImpl for SimilarityUdf {

fn name(&self) -> &str {
"similarity"
}
Expand Down Expand Up @@ -418,7 +416,6 @@ impl Default for PopcountUdf {
}

impl ScalarUDFImpl for PopcountUdf {

fn name(&self) -> &str {
"popcount"
}
Expand Down Expand Up @@ -532,7 +529,6 @@ impl Default for XorBindUdf {
}

impl ScalarUDFImpl for XorBindUdf {

fn name(&self) -> &str {
"xor_bind"
}
Expand Down Expand Up @@ -600,7 +596,6 @@ impl Default for ExtractScentUdf {
}

impl ScalarUDFImpl for ExtractScentUdf {

fn name(&self) -> &str {
"extract_scent"
}
Expand Down Expand Up @@ -689,7 +684,6 @@ impl Default for ScentDistanceUdf {
}

impl ScalarUDFImpl for ScentDistanceUdf {

fn name(&self) -> &str {
"scent_distance"
}
Expand Down Expand Up @@ -790,7 +784,6 @@ impl Default for NarsDeductionUdf {
}

impl ScalarUDFImpl for NarsDeductionUdf {

fn name(&self) -> &str {
"nars_deduction"
}
Expand Down Expand Up @@ -854,7 +847,6 @@ impl Default for NarsInductionUdf {
}

impl ScalarUDFImpl for NarsInductionUdf {

fn name(&self) -> &str {
"nars_induction"
}
Expand Down Expand Up @@ -918,7 +910,6 @@ impl Default for NarsAbductionUdf {
}

impl ScalarUDFImpl for NarsAbductionUdf {

fn name(&self) -> &str {
"nars_abduction"
}
Expand Down Expand Up @@ -988,7 +979,6 @@ impl Default for NarsRevisionUdf {
}

impl ScalarUDFImpl for NarsRevisionUdf {

fn name(&self) -> &str {
"nars_revision"
}
Expand Down Expand Up @@ -1107,7 +1097,6 @@ impl Default for MembraneEncodeUdf {
}

impl ScalarUDFImpl for MembraneEncodeUdf {

fn name(&self) -> &str {
"membrane_encode"
}
Expand Down Expand Up @@ -1191,7 +1180,6 @@ impl Default for MembraneDecodeUdf {
}

impl ScalarUDFImpl for MembraneDecodeUdf {

fn name(&self) -> &str {
"membrane_decode"
}
Expand Down
1 change: 0 additions & 1 deletion src/query/dn_tree_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ impl DnTreeTableProvider {

#[async_trait]
impl TableProvider for DnTreeTableProvider {

fn schema(&self) -> SchemaRef {
self.schema.clone()
}
Expand Down
1 change: 0 additions & 1 deletion src/query/fingerprint_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ impl std::fmt::Debug for FingerprintTableProvider {

#[async_trait]
impl TableProvider for FingerprintTableProvider {

fn schema(&self) -> SchemaRef {
self.schema.clone()
}
Expand Down
1 change: 0 additions & 1 deletion src/query/graph_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ impl fmt::Debug for EdgeTableProvider {

#[async_trait]
impl TableProvider for EdgeTableProvider {

fn schema(&self) -> SchemaRef {
self.schema.clone()
}
Expand Down
Loading
Loading