diff --git a/demo/temp.py b/demo/temp.py new file mode 100644 index 0000000..84c029d --- /dev/null +++ b/demo/temp.py @@ -0,0 +1,22 @@ +import startinpy +import numpy as np +import laspy +import math +import sys +import json + + +dt = startinpy.DT() +dt.add_attribute_map([("intensity", "f64"), ("visited", "i64")]) + +dt.insert_one_pt([20.0, 30.0, 1.1], intensity=111.2, visited=4); +dt.insert_one_pt([120.0, 33.0, 12.5], intensity=111.2, visited=5); +dt.insert_one_pt([124.0, 222.0, 7.65], intensity=111.2, visited=6); +dt.insert_one_pt([20.0, 133.0, 21.0], intensity=111.2, visited=7); +dt.insert_one_pt([23.0, 13.0, 11.0], intensity=111.2, visited=8); +dt.insert_one_pt([60.0, 60.0, 33.0], intensity=111.2, visited=9); + + +print(dt) + +print(dt.all_attributes()[1:]) diff --git a/src/lib.rs b/src/lib.rs index a27132e..97542fb 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -443,16 +443,26 @@ impl DT { // #[pyo3(text_signature = "($self, dtype)")] #[args()] - pub fn all_attributes<'py>(&self, py: Python<'py>) -> PyResult<()> { - // let am = self.t.list_all_attributes(); - // Get the numpy module + pub fn all_attributes<'py>(&self, py: Python<'py>) -> PyResult { let np = py.import("numpy")?; - // Define the dtype for the structured array - let dtype = np.call_method1("dtype", (vec![("intensity", "f8"), ("visited", "i8")],))?; + // let dmap = self.t.list_all_attributes(); + let mut vmap: Vec<(String, String)> = Vec::new(); + for (key, dtype) in &self.t.list_all_attributes() { + match dtype.as_ref() { + "f64" => vmap.push((String::from(key), "f8".to_string())), + "i64" => vmap.push((String::from(key), "i8".to_string())), + "u64" => vmap.push((String::from(key), "u8".to_string())), + "bool" => vmap.push((String::from(key), "b1".to_string())), + "String" => vmap.push((String::from(key), "U10".to_string())), + &_ => continue, + } + } + println!("{:?}", vmap); + let dtype = np.call_method1("dtype", (vmap,))?; + // let dtype = np.call_method1("dtype", (vec![("intensity", "f8"), ("visited", "i8")],))?; + let allt = self.t.all_attributes().unwrap(); - // Create an empty array with the defined dtype let arraydtype = np.call_method1("empty", (allt.len(), dtype))?; - for (i, each) in allt.iter().enumerate() { let item = arraydtype.get_item(i)?; let o = each.as_object().unwrap(); @@ -462,22 +472,13 @@ impl DT { } match o.get("visited") { Some(x) => item.set_item("visited", x.as_i64())?, - None => item.set_item("visited", std::f64::NAN)?, + None => item.set_item("visited", std::i64::MIN)?, } } + // println!("{:?}", arraydtype); - // // Fill the structured array with data - // for (i, name) in names.iter().enumerate() { - // let item = arraydtype.get_item(i)?; - // item.set_item("name", name)?; - // item.set_item("age", ages[i])?; - // item.set_item("height", heights[i])?; - // } - - println!("{:?}", arraydtype); - - Ok(()) - // Ok(arraydtype.into()) + // Ok(()) + Ok(arraydtype.into()) } /// Get all the values for a given extra attribute stored for the vertices.