| 245 | } |
| 246 | |
| 247 | fn array_helper(arg: Vec<f32>, shape: Vec<u64>, conf: PWLConfig) -> Result<Vec<f32>> { |
| 248 | let array_t = array_type(shape, INT64); |
| 249 | let c = simple_context(|g| { |
| 250 | let i = g.input(array_t.clone())?; |
| 251 | create_approximation(i, |x| x * x, -2.0, 2.0, 10, conf) |
| 252 | })?; |
| 253 | let mapped_c = run_instantiation_pass(c)?; |
| 254 | let mut arr = vec![]; |
| 255 | for x in arg { |
| 256 | arr.push((x * ((1 << 10) as f32)) as i64); |
| 257 | } |
| 258 | let result = random_evaluate( |
| 259 | mapped_c.get_context().get_main_graph()?, |
| 260 | vec![Value::from_flattened_array(&arr, INT64)?], |
| 261 | )?; |
| 262 | let output = result.to_flattened_array_i64(array_t)?; |
| 263 | let mut res = vec![]; |
| 264 | for x in output { |
| 265 | res.push((x as f32) / ((1 << 10) as f32)); |
| 266 | } |
| 267 | Ok(res) |
| 268 | } |
| 269 | |
| 270 | #[test] |
| 271 | fn pwl_simple_test() -> Result<()> { |