-
Notifications
You must be signed in to change notification settings - Fork 971
[QDP] fix test bug #734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QDP] fix test bug #734
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ | |
|
|
||
| // Memory safety tests: DLPack lifecycle, RAII, Arc reference counting | ||
|
|
||
| use qdp_core::QdpEngine; | ||
| use qdp_core::{Precision, QdpEngine}; | ||
|
|
||
| mod common; | ||
|
|
||
|
|
@@ -37,12 +37,16 @@ fn test_memory_pressure() { | |
| let data = common::create_test_data(1024); | ||
|
|
||
| for i in 0..100 { | ||
| let ptr = engine.encode(&data, 10, "amplitude") | ||
| let ptr = engine | ||
| .encode(&data, 10, "amplitude") | ||
| .expect("Encoding should succeed"); | ||
|
|
||
| unsafe { | ||
| let managed = &mut *ptr; | ||
| let deleter = managed.deleter.take().expect("Deleter missing in pressure test!"); | ||
| let deleter = managed | ||
| .deleter | ||
| .take() | ||
| .expect("Deleter missing in pressure test!"); | ||
| deleter(ptr); | ||
| } | ||
|
|
||
|
|
@@ -87,7 +91,7 @@ fn test_multiple_concurrent_states() { | |
|
|
||
| #[test] | ||
| #[cfg(target_os = "linux")] | ||
| fn test_dlpack_tensor_metadata() { | ||
| fn test_dlpack_tensor_metadata_default() { | ||
| println!("Testing DLPack tensor metadata..."); | ||
|
|
||
| let engine = match QdpEngine::new(0) { | ||
|
|
@@ -114,15 +118,72 @@ fn test_dlpack_tensor_metadata() { | |
| assert_eq!(stride, 1, "Stride for 1D contiguous array should be 1"); | ||
|
|
||
| assert_eq!(tensor.dtype.code, 5, "Should be complex type (code=5)"); | ||
| assert_eq!(tensor.dtype.bits, 128, "Should be 128 bits (2x64-bit floats)"); | ||
| assert_eq!(tensor.dtype.bits, 64, "Should be 64 bits (2x32-bit floats)"); | ||
|
|
||
| println!("PASS: DLPack metadata verified"); | ||
| println!(" ndim: {}", tensor.ndim); | ||
| println!(" shape: {}", shape); | ||
| println!(" stride: {}", stride); | ||
| println!(" dtype: code={}, bits={}", tensor.dtype.code, tensor.dtype.bits); | ||
| println!( | ||
| " dtype: code={}, bits={}", | ||
| tensor.dtype.code, tensor.dtype.bits | ||
| ); | ||
|
|
||
| let deleter = managed | ||
| .deleter | ||
| .take() | ||
| .expect("Deleter missing in metadata test!"); | ||
| deleter(ptr); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(target_os = "linux")] | ||
| fn test_dlpack_tensor_metadata_f64() { | ||
| println!("Testing DLPack tensor metadata..."); | ||
|
|
||
| let engine = match QdpEngine::new_with_precision(0, Precision::Float64) { | ||
| Ok(e) => e, | ||
| Err(_) => return, | ||
| }; | ||
|
|
||
| let data = common::create_test_data(1024); | ||
| let ptr = engine.encode(&data, 10, "amplitude").unwrap(); | ||
|
|
||
| unsafe { | ||
| let managed = &mut *ptr; | ||
| let tensor = &managed.dl_tensor; | ||
|
|
||
| let deleter = managed.deleter.take().expect("Deleter missing in metadata test!"); | ||
| assert_eq!(tensor.ndim, 1, "Should be 1D tensor"); | ||
| assert!(!tensor.data.is_null(), "Data pointer should be valid"); | ||
| assert!(!tensor.shape.is_null(), "Shape pointer should be valid"); | ||
| assert!(!tensor.strides.is_null(), "Strides pointer should be valid"); | ||
|
|
||
| let shape = *tensor.shape; | ||
| assert_eq!(shape, 1024, "Shape should be 1024 (2^10)"); | ||
|
|
||
| let stride = *tensor.strides; | ||
| assert_eq!(stride, 1, "Stride for 1D contiguous array should be 1"); | ||
|
|
||
| assert_eq!(tensor.dtype.code, 5, "Should be complex type (code=5)"); | ||
| assert_eq!( | ||
| tensor.dtype.bits, 128, | ||
| "Should be 128 bits (2x64-bit floats)" | ||
| ); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the failed test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am thinking as we change the precision to float32 by default, should we set the expected value to 2x32 rather than change the precision back to float64? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see this, working on float32 right now. |
||
|
|
||
| println!("PASS: DLPack metadata verified"); | ||
| println!(" ndim: {}", tensor.ndim); | ||
| println!(" shape: {}", shape); | ||
| println!(" stride: {}", stride); | ||
| println!( | ||
| " dtype: code={}, bits={}", | ||
| tensor.dtype.code, tensor.dtype.bits | ||
| ); | ||
|
|
||
| let deleter = managed | ||
| .deleter | ||
| .take() | ||
| .expect("Deleter missing in metadata test!"); | ||
| deleter(ptr); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I changed