summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Groth <christoph.groth@cea.fr>2025-04-30 13:10:14 +0200
committerChristoph Groth <christoph.groth@cea.fr>2025-04-30 13:10:14 +0200
commit4613cb09543f053a44b0c0afb711e50b16f3cf07 (patch)
tree8eb3aecaed117dd8edc4f9006719d4a1986d1b21
parent58916e3e1b9e668838e1cf8947ead046b47fd0e2 (diff)
Demonstrate working with uninitialized memory
-rw-r--r--src/main.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index ccf5705..655c906 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,5 @@
+use std::mem::MaybeUninit;
+
use mdarray::{view, tensor, Slice, Dim, Const, expr::Expression};
use mdarray as md;
@@ -45,6 +47,13 @@ fn main() {
let d = d.reshape(&[2; 7]);
let d = d.permute(&[6, 5, 4, 3, 2, 1, 0]);
+ // Working with uninitialized memory.
+ let mut e = tensor![[MaybeUninit::<f64>::uninit(); 3]; 3];
+ for (i, val) in e.iter_mut().enumerate() {
+ val.write(i as f64);
+ }
+ let _ = unsafe { e.assume_init() };
+
// Indexing
for i in 0..2 {
let index = [0, i, 0, 0, i, 0, 0];