MCPcopy Create free account
hub / github.com/PyO3/rust-numpy / half_f16_works

Function half_f16_works

tests/array.rs:567–601  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

565#[cfg(feature = "half")]
566#[test]
567fn half_f16_works() {
568 Python::attach(|py| {
569 let np = py.eval(c_str!("__import__('numpy')"), None, None).unwrap();
570 let locals = [("np", &np)].into_py_dict(py).unwrap();
571
572 let array = py
573 .eval(
574 c_str!("np.array([[1, 2], [3, 4]], dtype='float16')"),
575 None,
576 Some(&locals),
577 )
578 .unwrap()
579 .cast_into::<PyArray2<f16>>()
580 .unwrap();
581
582 assert_eq!(
583 array.readonly().as_array(),
584 array![
585 [f16::from_f32(1.0), f16::from_f32(2.0)],
586 [f16::from_f32(3.0), f16::from_f32(4.0)]
587 ]
588 );
589
590 array
591 .readwrite()
592 .as_array_mut()
593 .map_inplace(|value| *value *= f16::from_f32(2.0));
594
595 py_run!(
596 py,
597 array np,
598 "assert np.all(array == np.array([[2, 4], [6, 8]], dtype='float16'))"
599 );
600 });
601}
602
603#[cfg(feature = "half")]
604#[test]

Callers

nothing calls this directly

Calls 2

readwriteMethod · 0.80
as_array_mutMethod · 0.45

Tested by

no test coverage detected