Fix issues with big sizes, really I should be using a different storage mechanism for large sizes I think
This commit is contained in:
parent
0bdca635ff
commit
b94d001ab2
15
libdla.h
15
libdla.h
@ -4,21 +4,8 @@
|
|||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
struct CStorage;
|
|
||||||
|
|
||||||
struct CPosition {
|
|
||||||
int32_t _0;
|
|
||||||
int32_t _1;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
CStorage *storage_new(uint32_t grid_size);
|
bool dla_rust_disabled();
|
||||||
|
|
||||||
bool storage_at(const CStorage *storage, int32_t i, int32_t j);
|
|
||||||
|
|
||||||
void storage_deposit(CStorage *storage, int32_t i, int32_t j, uint8_t val);
|
|
||||||
|
|
||||||
CPosition walk(uint32_t d, int32_t i, int32_t j);
|
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|||||||
@ -39,11 +39,6 @@ fn write_csv_positions<R: Rng, P: Position, S: Storage<P>, W: Walker<P>, Sp: Spa
|
|||||||
fn write_json_full_data<R: Rng, P: Position, S: Storage<P>, W: Walker<P>, Sp: Spawner<P>, St: Sticker<P, S>>(sys: &DLASystem<R, P, S, W, Sp, St>, output_path: &Path) {
|
fn write_json_full_data<R: Rng, P: Position, S: Storage<P>, W: Walker<P>, Sp: Spawner<P>, St: Sticker<P, S>>(sys: &DLASystem<R, P, S, W, Sp, St>, output_path: &Path) {
|
||||||
let file = File::create(output_path).expect("Failed to open file");
|
let file = File::create(output_path).expect("Failed to open file");
|
||||||
|
|
||||||
let vec: Vec<P> = sys.history
|
serde_json::to_writer(file, &sys.history)
|
||||||
.iter()
|
|
||||||
.map(|l| l.position.clone())
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
serde_json::to_writer(file, &vec)
|
|
||||||
.expect("Failed to write json");
|
.expect("Failed to write json");
|
||||||
}
|
}
|
||||||
|
|||||||
150
src/clib.rs
150
src/clib.rs
@ -1,75 +1,81 @@
|
|||||||
#![feature(array_zip)]
|
|
||||||
|
|
||||||
use system::Storage;
|
|
||||||
use crate::system::grid::{Pos2D, VectorStorage};
|
|
||||||
|
|
||||||
mod system;
|
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Debug)]
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct CPosition(i32, i32);
|
|
||||||
|
|
||||||
pub struct CStorage(VectorStorage);
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn storage_new(grid_size: u32) -> &'static mut CStorage {
|
pub extern "C" fn dla_rust_disabled() -> bool {
|
||||||
let mut pntr = Box::new(CStorage(VectorStorage::new(grid_size)));
|
true
|
||||||
Box::leak(pntr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
// #![feature(array_zip)]
|
||||||
pub extern "C" fn storage_at(storage: &CStorage, i: i32, j: i32) -> bool {
|
//
|
||||||
storage.0.at(&Pos2D { x: i, y: j })
|
// use system::Storage;
|
||||||
}
|
// use crate::system::spaces::square_grid::Grid2D;
|
||||||
|
// use crate::system::spaces::VectorStorage;
|
||||||
#[no_mangle]
|
//
|
||||||
pub extern "C" fn storage_deposit(storage: &mut CStorage, i: i32, j: i32, val: u8) {
|
// mod system;
|
||||||
storage.0.write(&Pos2D { x: i, y: j }, val == 1);
|
//
|
||||||
}
|
// #[derive(Eq, PartialEq, Debug)]
|
||||||
|
// #[repr(C)]
|
||||||
#[no_mangle]
|
// pub struct CPosition(i32, i32);
|
||||||
pub extern "C" fn walk(d: u32, i: i32, j: i32) -> CPosition {
|
//
|
||||||
return test::b(d, i, j);
|
// pub struct CStorage(VectorStorage);
|
||||||
}
|
//
|
||||||
|
// #[no_mangle]
|
||||||
mod test {
|
// pub extern "C" fn storage_new(grid_size: u32) -> &'static mut CStorage {
|
||||||
use num_integer::Integer;
|
// let mut pntr = Box::new(CStorage(VectorStorage::new(grid_size)));
|
||||||
use crate::CPosition;
|
// Box::leak(pntr)
|
||||||
use crate::system::grid::Pos2D;
|
// }
|
||||||
|
//
|
||||||
pub(crate) fn a(d: u32, i: i32, j: i32) -> CPosition {
|
// #[no_mangle]
|
||||||
match d {
|
// pub extern "C" fn storage_at(storage: &CStorage, i: i32, j: i32) -> bool {
|
||||||
0 => CPosition(i + 1, j),
|
// storage.0.at(&Grid2D { x: i, y: j })
|
||||||
1 => CPosition(i - 1, j),
|
// }
|
||||||
2 => CPosition(i, j + 1),
|
//
|
||||||
3 => CPosition(i, j - 1),
|
// #[no_mangle]
|
||||||
_ => panic!("Ahh"),
|
// pub extern "C" fn storage_deposit(storage: &mut CStorage, i: i32, j: i32, val: u8) {
|
||||||
}
|
// storage.0.inner.(&Grid2D { x: i, y: j }, val == 1);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
pub(crate) fn b(d: u32, i: i32, j: i32) -> CPosition {
|
// #[no_mangle]
|
||||||
let (dim, sign) = d.div_rem(&2);
|
// pub extern "C" fn walk(d: u32, i: i32, j: i32) -> CPosition {
|
||||||
let sign = if sign == 0 { 1 } else { -1 };
|
// return test::b(d, i, j);
|
||||||
// HACK: Our conventin and the MVA are different, since we are trying to strangle fig this, quick hack.
|
// }
|
||||||
let offset = Pos2D::in_direction(dim, sign);
|
//
|
||||||
let next = Pos2D { x: i, y: j } + offset;
|
// // mod test {
|
||||||
|
// // use num_integer::Integer;
|
||||||
CPosition(next.x, next.y)
|
// // use crate::CPosition;
|
||||||
}
|
// // use crate::system::grid::Grid2D;
|
||||||
|
// //
|
||||||
#[test]
|
// // pub(crate) fn a(d: u32, i: i32, j: i32) -> CPosition {
|
||||||
fn test() {
|
// // match d {
|
||||||
let d = [0, 1, 2, 3];
|
// // 0 => CPosition(i + 1, j),
|
||||||
d.iter()
|
// // 1 => CPosition(i - 1, j),
|
||||||
.map(|d| d.div_rem(&2))
|
// // 2 => CPosition(i, j + 1),
|
||||||
.for_each(|p| println!("{p:?}"));
|
// // 3 => CPosition(i, j - 1),
|
||||||
}
|
// // _ => panic!("Ahh"),
|
||||||
|
// // }
|
||||||
#[test]
|
// // }
|
||||||
fn alignment() {
|
// //
|
||||||
let d = [0, 1, 2, 3];
|
// // pub(crate) fn b(d: u32, i: i32, j: i32) -> CPosition {
|
||||||
d.iter()
|
// // let (dim, sign) = d.div_rem(&2);
|
||||||
.map(|d| (a(*d, 0, 0), b(*d, 0, 0)))
|
// // let sign = if sign == 0 { 1 } else { -1 };
|
||||||
.for_each(|p| assert_eq!(p.0, p.1));
|
// // // HACK: Our conventin and the MVA are different, since we are trying to strangle fig this, quick hack.
|
||||||
}
|
// // let offset = Grid2D::in_direction(dim, sign);
|
||||||
}
|
// // let next = Grid2D { x: i, y: j } + offset;
|
||||||
|
// //
|
||||||
|
// // CPosition(next.x, next.y)
|
||||||
|
// // }
|
||||||
|
// //
|
||||||
|
// // #[test]
|
||||||
|
// // fn test() {
|
||||||
|
// // let d = [0, 1, 2, 3];
|
||||||
|
// // d.iter()
|
||||||
|
// // .map(|d| d.div_rem(&2))
|
||||||
|
// // .for_each(|p| println!("{p:?}"));
|
||||||
|
// // }
|
||||||
|
// //
|
||||||
|
// // #[test]
|
||||||
|
// // fn alignment() {
|
||||||
|
// // let d = [0, 1, 2, 3];
|
||||||
|
// // d.iter()
|
||||||
|
// // .map(|d| (a(*d, 0, 0), b(*d, 0, 0)))
|
||||||
|
// // .for_each(|p| assert_eq!(p.0, p.1));
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
|||||||
@ -140,16 +140,19 @@ impl GriddedPosition for Grid3D {
|
|||||||
assert!(self.y < grid_size && -(grid_size) < self.y);
|
assert!(self.y < grid_size && -(grid_size) < self.y);
|
||||||
assert!(self.z < grid_size && -(grid_size) < self.z);
|
assert!(self.z < grid_size && -(grid_size) < self.z);
|
||||||
|
|
||||||
let x = (self.x + (grid_size) / 2) as usize;
|
let half_grid = (grid_size) / 2;
|
||||||
let y = (self.y + (grid_size) / 2) as usize;
|
let x = (self.x + half_grid) as usize;
|
||||||
let z = (self.z + (grid_size) / 2) as usize;
|
let y = (self.y + half_grid) as usize;
|
||||||
|
let z = (self.z + half_grid) as usize;
|
||||||
|
|
||||||
|
let grid_size_usize = grid_size as usize;
|
||||||
|
|
||||||
let linear_index =
|
let linear_index =
|
||||||
(grid_size as usize * grid_size as usize) * z
|
(grid_size_usize * grid_size_usize) * z
|
||||||
+ (grid_size as usize) * y
|
+ (grid_size_usize) * y
|
||||||
+ x;
|
+ x;
|
||||||
|
|
||||||
if linear_index >= (grid_size * grid_size * grid_size) as usize {
|
if linear_index >= (grid_size_usize * grid_size_usize * grid_size_usize) as usize {
|
||||||
eprintln!("AHHH SOMETHING WENT WRONG {:?} gives {}", self, linear_index);
|
eprintln!("AHHH SOMETHING WENT WRONG {:?} gives {}", self, linear_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ pub struct VectorStorage {
|
|||||||
|
|
||||||
impl VectorStorage {
|
impl VectorStorage {
|
||||||
pub fn new(grid_size: u32, dimension: u32) -> VectorStorage {
|
pub fn new(grid_size: u32, dimension: u32) -> VectorStorage {
|
||||||
VectorStorage { grid_size, dimension, backing: vec![false; grid_size.pow(dimension) as usize] }
|
VectorStorage { grid_size, dimension, backing: vec![false; (grid_size as usize).pow(dimension) as usize] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user