MCPcopy Create free account
hub / github.com/ciphermodelabs/ciphercore / array_helper

Function array_helper

ciphercore-base/src/ops/pwl/approx_pointwise.rs:247–268  ·  view source on GitHub ↗
(arg: Vec<f32>, shape: Vec<u64>, conf: PWLConfig)

Source from the content-addressed store, hash-verified

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<()> {

Callers 2

pwl_array_testFunction · 0.70
pwl_array2d_testFunction · 0.70

Calls 11

simple_contextFunction · 0.85
create_approximationFunction · 0.85
run_instantiation_passFunction · 0.85
random_evaluateFunction · 0.85
cloneMethod · 0.80
array_typeFunction · 0.50
inputMethod · 0.45
pushMethod · 0.45
get_main_graphMethod · 0.45
get_contextMethod · 0.45

Tested by 2

pwl_array_testFunction · 0.56
pwl_array2d_testFunction · 0.56