This is an automated email from the ASF dual-hosted git repository.
richhuang pushed a commit to branch dev-qdp
in repository https://gitbox.apache.org/repos/asf/mahout.git
The following commit(s) were added to refs/heads/dev-qdp by this push:
new 828d379dc [QDP] fix test bug (#734)
828d379dc is described below
commit 828d379dcad4de74539a9b8fc4af6ff3cb726c77
Author: Ryan Huang <[email protected]>
AuthorDate: Sat Dec 20 11:50:13 2025 +0800
[QDP] fix test bug (#734)
* fix test bug
Signed-off-by: Hsien-Cheng Huang <[email protected]>
* add test coverage for f32, for coverage
---------
Signed-off-by: Hsien-Cheng Huang <[email protected]>
---
qdp/qdp-core/tests/memory_safety.rs | 75 +++++++++++++++++++++++++++++++++----
1 file changed, 68 insertions(+), 7 deletions(-)
diff --git a/qdp/qdp-core/tests/memory_safety.rs
b/qdp/qdp-core/tests/memory_safety.rs
index 833190c48..2b5fdd6e8 100644
--- a/qdp/qdp-core/tests/memory_safety.rs
+++ b/qdp/qdp-core/tests/memory_safety.rs
@@ -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)"
+ );
+
+ 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);
}
}