QuantumDiffusionModel

Struct QuantumDiffusionModel 

Source
pub struct QuantumDiffusionModel { /* private fields */ }
Expand description

Quantum diffusion model

Implementations§

Source§

impl QuantumDiffusionModel

Source

pub fn new( data_dim: usize, num_qubits: usize, num_timesteps: usize, noise_schedule: NoiseSchedule, ) -> Result<Self>

Create a new quantum diffusion model

Examples found in repository?
examples/quantum_diffusion.rs (line 77)
41fn compare_noise_schedules() -> Result<()> {
42    let num_timesteps = 100;
43
44    let schedules = vec![
45        (
46            "Linear",
47            NoiseSchedule::Linear {
48                beta_start: 0.0001,
49                beta_end: 0.02,
50            },
51        ),
52        ("Cosine", NoiseSchedule::Cosine { s: 0.008 }),
53        (
54            "Quadratic",
55            NoiseSchedule::Quadratic {
56                beta_start: 0.0001,
57                beta_end: 0.02,
58            },
59        ),
60        (
61            "Sigmoid",
62            NoiseSchedule::Sigmoid {
63                beta_start: 0.0001,
64                beta_end: 0.02,
65            },
66        ),
67    ];
68
69    println!("   Noise levels at different timesteps:");
70    println!("   Time     Linear   Cosine   Quadratic  Sigmoid");
71
72    for t in (0..=100).step_by(20) {
73        let t_idx = (t * (num_timesteps - 1) / 100).min(num_timesteps - 1);
74        print!("   t={t:3}%: ");
75
76        for (_, schedule) in &schedules {
77            let model = QuantumDiffusionModel::new(2, 4, num_timesteps, *schedule)?;
78            print!("{:8.4} ", model.betas()[t_idx]);
79        }
80        println!();
81    }
82
83    Ok(())
84}
85
86/// Train a quantum diffusion model
87fn train_diffusion_model() -> Result<()> {
88    // Generate synthetic 2D data (two moons)
89    let num_samples = 200;
90    let data = generate_two_moons(num_samples);
91
92    println!("   Generated {num_samples} samples of 2D two-moons data");
93
94    // Create diffusion model
95    let mut model = QuantumDiffusionModel::new(
96        2,  // data dimension
97        4,  // num qubits
98        50, // timesteps
99        NoiseSchedule::Cosine { s: 0.008 },
100    )?;
101
102    println!("   Created quantum diffusion model:");
103    println!("   - Data dimension: 2");
104    println!("   - Qubits: 4");
105    println!("   - Timesteps: 50");
106    println!("   - Schedule: Cosine");
107
108    // Train model
109    let mut optimizer = Adam::new(0.001);
110    let epochs = 100;
111    let batch_size = 32;
112
113    println!("\n   Training for {epochs} epochs...");
114    let losses = model.train(&data, &mut optimizer, epochs, batch_size)?;
115
116    // Print training statistics
117    println!("\n   Training Statistics:");
118    println!("   - Initial loss: {:.4}", losses[0]);
119    println!("   - Final loss: {:.4}", losses.last().unwrap());
120    println!(
121        "   - Improvement: {:.2}%",
122        (1.0 - losses.last().unwrap() / losses[0]) * 100.0
123    );
124
125    Ok(())
126}
127
128/// Generate samples from trained model
129fn generate_samples() -> Result<()> {
130    // Create a simple trained model
131    let model = QuantumDiffusionModel::new(
132        2,  // data dimension
133        4,  // num qubits
134        50, // timesteps
135        NoiseSchedule::Linear {
136            beta_start: 0.0001,
137            beta_end: 0.02,
138        },
139    )?;
140
141    // Generate samples
142    let num_samples = 10;
143    println!("   Generating {num_samples} samples...");
144
145    let samples = model.generate(num_samples)?;
146
147    println!("\n   Generated samples:");
148    for i in 0..num_samples.min(5) {
149        println!(
150            "   Sample {}: [{:.3}, {:.3}]",
151            i + 1,
152            samples[[i, 0]],
153            samples[[i, 1]]
154        );
155    }
156
157    // Compute statistics
158    let mean = samples.mean_axis(scirs2_core::ndarray::Axis(0)).unwrap();
159    let std = samples.std_axis(scirs2_core::ndarray::Axis(0), 0.0);
160
161    println!("\n   Sample statistics:");
162    println!("   - Mean: [{:.3}, {:.3}]", mean[0], mean[1]);
163    println!("   - Std:  [{:.3}, {:.3}]", std[0], std[1]);
164
165    Ok(())
166}
167
168/// Score-based diffusion demonstration
169fn score_diffusion_demo() -> Result<()> {
170    // Create score-based model
171    let model = QuantumScoreDiffusion::new(
172        2,  // data dimension
173        4,  // num qubits
174        10, // noise levels
175    )?;
176
177    println!("   Created quantum score-based diffusion model");
178    println!("   - Noise levels: {:?}", model.noise_levels());
179
180    // Test score estimation
181    let x = Array1::from_vec(vec![0.5, -0.3]);
182    let noise_level = 0.1;
183
184    let score = model.estimate_score(&x, noise_level)?;
185    println!("\n   Score estimation:");
186    println!("   - Input: [{:.3}, {:.3}]", x[0], x[1]);
187    println!("   - Noise level: {noise_level:.3}");
188    println!("   - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
189
190    // Langevin sampling
191    println!("\n   Langevin sampling:");
192    let init = Array1::from_vec(vec![2.0, 2.0]);
193    let num_steps = 100;
194    let step_size = 0.01;
195
196    let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
197
198    println!("   - Initial: [{:.3}, {:.3}]", init[0], init[1]);
199    println!(
200        "   - After {} steps: [{:.3}, {:.3}]",
201        num_steps, sample[0], sample[1]
202    );
203    println!(
204        "   - Distance moved: {:.3}",
205        (sample[0] - init[0]).hypot(sample[1] - init[1])
206    );
207
208    Ok(())
209}
210
211/// Visualize the diffusion process
212fn visualize_diffusion_process() -> Result<()> {
213    let model = QuantumDiffusionModel::new(
214        2,  // data dimension
215        4,  // num qubits
216        20, // fewer timesteps for visualization
217        NoiseSchedule::Linear {
218            beta_start: 0.0001,
219            beta_end: 0.02,
220        },
221    )?;
222
223    // Start with a clear data point
224    let x0 = Array1::from_vec(vec![1.0, 0.5]);
225
226    println!("   Forward diffusion process:");
227    println!("   t=0 (original): [{:.3}, {:.3}]", x0[0], x0[1]);
228
229    // Show forward diffusion at different timesteps
230    for t in [5, 10, 15, 19] {
231        let (xt, _) = model.forward_diffusion(&x0, t)?;
232        let noise_level = (1.0 - model.alphas_cumprod()[t]).sqrt();
233        println!(
234            "   t={:2} (noise={:.3}): [{:.3}, {:.3}]",
235            t, noise_level, xt[0], xt[1]
236        );
237    }
238
239    println!("\n   Reverse diffusion process:");
240
241    // Start from noise
242    let mut xt = Array1::from_vec(vec![
243        2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
244        2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
245    ]);
246
247    println!("   t=19 (pure noise): [{:.3}, {:.3}]", xt[0], xt[1]);
248
249    // Show reverse diffusion
250    for t in [15, 10, 5, 0] {
251        xt = model.reverse_diffusion_step(&xt, t)?;
252        println!("   t={:2} (denoised): [{:.3}, {:.3}]", t, xt[0], xt[1]);
253    }
254
255    println!("\n   This demonstrates how diffusion models:");
256    println!("   1. Gradually add noise to data (forward process)");
257    println!("   2. Learn to reverse this process (backward process)");
258    println!("   3. Generate new samples by denoising random noise");
259
260    Ok(())
261}
262
263/// Generate two-moons dataset
264fn generate_two_moons(n_samples: usize) -> Array2<f64> {
265    let mut data = Array2::zeros((n_samples, 2));
266    let n_samples_per_moon = n_samples / 2;
267
268    // First moon
269    for i in 0..n_samples_per_moon {
270        let angle = std::f64::consts::PI * i as f64 / n_samples_per_moon as f64;
271        data[[i, 0]] = 0.1f64.mul_add(2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0), angle.cos());
272        data[[i, 1]] = 0.1f64.mul_add(2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0), angle.sin());
273    }
274
275    // Second moon (shifted and flipped)
276    for i in 0..n_samples_per_moon {
277        let idx = n_samples_per_moon + i;
278        let angle = std::f64::consts::PI * i as f64 / n_samples_per_moon as f64;
279        data[[idx, 0]] = 0.1f64.mul_add(
280            2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
281            1.0 - angle.cos(),
282        );
283        data[[idx, 1]] = 0.1f64.mul_add(
284            2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
285            0.5 - angle.sin(),
286        );
287    }
288
289    data
290}
291
292/// Advanced diffusion techniques demonstration
293fn advanced_diffusion_demo() -> Result<()> {
294    println!("\n6. Advanced Diffusion Techniques:");
295
296    // Conditional generation
297    println!("\n   a) Conditional Generation:");
298    let model = QuantumDiffusionModel::new(4, 4, 50, NoiseSchedule::Cosine { s: 0.008 })?;
299    let condition = Array1::from_vec(vec![0.5, -0.5]);
300    let conditional_samples = model.conditional_generate(&condition, 5)?;
301
302    println!(
303        "   Generated {} conditional samples",
304        conditional_samples.nrows()
305    );
306    println!("   Condition: [{:.3}, {:.3}]", condition[0], condition[1]);
307
308    // Variational diffusion
309    println!("\n   b) Variational Diffusion Model:");
310    let vdm = QuantumVariationalDiffusion::new(
311        4, // data_dim
312        2, // latent_dim
313        4, // num_qubits
314    )?;
315
316    let x = Array1::from_vec(vec![0.1, 0.2, 0.3, 0.4]);
317    let (mean, log_var) = vdm.encode(&x)?;
318
319    println!("   Encoded data to latent space:");
320    println!("   - Input: {:?}", x.as_slice().unwrap());
321    println!("   - Latent mean: [{:.3}, {:.3}]", mean[0], mean[1]);
322    println!(
323        "   - Latent log_var: [{:.3}, {:.3}]",
324        log_var[0], log_var[1]
325    );
326
327    Ok(())
328}
Source

pub fn forward_diffusion( &self, x0: &Array1<f64>, t: usize, ) -> Result<(Array1<f64>, Array1<f64>)>

Forward diffusion process: add noise to data

Examples found in repository?
examples/quantum_diffusion.rs (line 231)
212fn visualize_diffusion_process() -> Result<()> {
213    let model = QuantumDiffusionModel::new(
214        2,  // data dimension
215        4,  // num qubits
216        20, // fewer timesteps for visualization
217        NoiseSchedule::Linear {
218            beta_start: 0.0001,
219            beta_end: 0.02,
220        },
221    )?;
222
223    // Start with a clear data point
224    let x0 = Array1::from_vec(vec![1.0, 0.5]);
225
226    println!("   Forward diffusion process:");
227    println!("   t=0 (original): [{:.3}, {:.3}]", x0[0], x0[1]);
228
229    // Show forward diffusion at different timesteps
230    for t in [5, 10, 15, 19] {
231        let (xt, _) = model.forward_diffusion(&x0, t)?;
232        let noise_level = (1.0 - model.alphas_cumprod()[t]).sqrt();
233        println!(
234            "   t={:2} (noise={:.3}): [{:.3}, {:.3}]",
235            t, noise_level, xt[0], xt[1]
236        );
237    }
238
239    println!("\n   Reverse diffusion process:");
240
241    // Start from noise
242    let mut xt = Array1::from_vec(vec![
243        2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
244        2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
245    ]);
246
247    println!("   t=19 (pure noise): [{:.3}, {:.3}]", xt[0], xt[1]);
248
249    // Show reverse diffusion
250    for t in [15, 10, 5, 0] {
251        xt = model.reverse_diffusion_step(&xt, t)?;
252        println!("   t={:2} (denoised): [{:.3}, {:.3}]", t, xt[0], xt[1]);
253    }
254
255    println!("\n   This demonstrates how diffusion models:");
256    println!("   1. Gradually add noise to data (forward process)");
257    println!("   2. Learn to reverse this process (backward process)");
258    println!("   3. Generate new samples by denoising random noise");
259
260    Ok(())
261}
Source

pub fn predict_noise(&self, xt: &Array1<f64>, t: usize) -> Result<Array1<f64>>

Predict noise from noisy data using quantum circuit

Source

pub fn reverse_diffusion_step( &self, xt: &Array1<f64>, t: usize, ) -> Result<Array1<f64>>

Reverse diffusion process: denoise step by step

Examples found in repository?
examples/quantum_diffusion.rs (line 251)
212fn visualize_diffusion_process() -> Result<()> {
213    let model = QuantumDiffusionModel::new(
214        2,  // data dimension
215        4,  // num qubits
216        20, // fewer timesteps for visualization
217        NoiseSchedule::Linear {
218            beta_start: 0.0001,
219            beta_end: 0.02,
220        },
221    )?;
222
223    // Start with a clear data point
224    let x0 = Array1::from_vec(vec![1.0, 0.5]);
225
226    println!("   Forward diffusion process:");
227    println!("   t=0 (original): [{:.3}, {:.3}]", x0[0], x0[1]);
228
229    // Show forward diffusion at different timesteps
230    for t in [5, 10, 15, 19] {
231        let (xt, _) = model.forward_diffusion(&x0, t)?;
232        let noise_level = (1.0 - model.alphas_cumprod()[t]).sqrt();
233        println!(
234            "   t={:2} (noise={:.3}): [{:.3}, {:.3}]",
235            t, noise_level, xt[0], xt[1]
236        );
237    }
238
239    println!("\n   Reverse diffusion process:");
240
241    // Start from noise
242    let mut xt = Array1::from_vec(vec![
243        2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
244        2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
245    ]);
246
247    println!("   t=19 (pure noise): [{:.3}, {:.3}]", xt[0], xt[1]);
248
249    // Show reverse diffusion
250    for t in [15, 10, 5, 0] {
251        xt = model.reverse_diffusion_step(&xt, t)?;
252        println!("   t={:2} (denoised): [{:.3}, {:.3}]", t, xt[0], xt[1]);
253    }
254
255    println!("\n   This demonstrates how diffusion models:");
256    println!("   1. Gradually add noise to data (forward process)");
257    println!("   2. Learn to reverse this process (backward process)");
258    println!("   3. Generate new samples by denoising random noise");
259
260    Ok(())
261}
Source

pub fn generate(&self, num_samples: usize) -> Result<Array2<f64>>

Generate new samples

Examples found in repository?
examples/quantum_diffusion.rs (line 145)
129fn generate_samples() -> Result<()> {
130    // Create a simple trained model
131    let model = QuantumDiffusionModel::new(
132        2,  // data dimension
133        4,  // num qubits
134        50, // timesteps
135        NoiseSchedule::Linear {
136            beta_start: 0.0001,
137            beta_end: 0.02,
138        },
139    )?;
140
141    // Generate samples
142    let num_samples = 10;
143    println!("   Generating {num_samples} samples...");
144
145    let samples = model.generate(num_samples)?;
146
147    println!("\n   Generated samples:");
148    for i in 0..num_samples.min(5) {
149        println!(
150            "   Sample {}: [{:.3}, {:.3}]",
151            i + 1,
152            samples[[i, 0]],
153            samples[[i, 1]]
154        );
155    }
156
157    // Compute statistics
158    let mean = samples.mean_axis(scirs2_core::ndarray::Axis(0)).unwrap();
159    let std = samples.std_axis(scirs2_core::ndarray::Axis(0), 0.0);
160
161    println!("\n   Sample statistics:");
162    println!("   - Mean: [{:.3}, {:.3}]", mean[0], mean[1]);
163    println!("   - Std:  [{:.3}, {:.3}]", std[0], std[1]);
164
165    Ok(())
166}
Source

pub fn train( &mut self, data: &Array2<f64>, optimizer: &mut dyn Optimizer, epochs: usize, batch_size: usize, ) -> Result<Vec<f64>>

Train the diffusion model

Examples found in repository?
examples/quantum_diffusion.rs (line 114)
87fn train_diffusion_model() -> Result<()> {
88    // Generate synthetic 2D data (two moons)
89    let num_samples = 200;
90    let data = generate_two_moons(num_samples);
91
92    println!("   Generated {num_samples} samples of 2D two-moons data");
93
94    // Create diffusion model
95    let mut model = QuantumDiffusionModel::new(
96        2,  // data dimension
97        4,  // num qubits
98        50, // timesteps
99        NoiseSchedule::Cosine { s: 0.008 },
100    )?;
101
102    println!("   Created quantum diffusion model:");
103    println!("   - Data dimension: 2");
104    println!("   - Qubits: 4");
105    println!("   - Timesteps: 50");
106    println!("   - Schedule: Cosine");
107
108    // Train model
109    let mut optimizer = Adam::new(0.001);
110    let epochs = 100;
111    let batch_size = 32;
112
113    println!("\n   Training for {epochs} epochs...");
114    let losses = model.train(&data, &mut optimizer, epochs, batch_size)?;
115
116    // Print training statistics
117    println!("\n   Training Statistics:");
118    println!("   - Initial loss: {:.4}", losses[0]);
119    println!("   - Final loss: {:.4}", losses.last().unwrap());
120    println!(
121        "   - Improvement: {:.2}%",
122        (1.0 - losses.last().unwrap() / losses[0]) * 100.0
123    );
124
125    Ok(())
126}
Source

pub fn conditional_generate( &self, condition: &Array1<f64>, num_samples: usize, ) -> Result<Array2<f64>>

Conditional generation given a condition

Examples found in repository?
examples/quantum_diffusion.rs (line 300)
293fn advanced_diffusion_demo() -> Result<()> {
294    println!("\n6. Advanced Diffusion Techniques:");
295
296    // Conditional generation
297    println!("\n   a) Conditional Generation:");
298    let model = QuantumDiffusionModel::new(4, 4, 50, NoiseSchedule::Cosine { s: 0.008 })?;
299    let condition = Array1::from_vec(vec![0.5, -0.5]);
300    let conditional_samples = model.conditional_generate(&condition, 5)?;
301
302    println!(
303        "   Generated {} conditional samples",
304        conditional_samples.nrows()
305    );
306    println!("   Condition: [{:.3}, {:.3}]", condition[0], condition[1]);
307
308    // Variational diffusion
309    println!("\n   b) Variational Diffusion Model:");
310    let vdm = QuantumVariationalDiffusion::new(
311        4, // data_dim
312        2, // latent_dim
313        4, // num_qubits
314    )?;
315
316    let x = Array1::from_vec(vec![0.1, 0.2, 0.3, 0.4]);
317    let (mean, log_var) = vdm.encode(&x)?;
318
319    println!("   Encoded data to latent space:");
320    println!("   - Input: {:?}", x.as_slice().unwrap());
321    println!("   - Latent mean: [{:.3}, {:.3}]", mean[0], mean[1]);
322    println!(
323        "   - Latent log_var: [{:.3}, {:.3}]",
324        log_var[0], log_var[1]
325    );
326
327    Ok(())
328}
Source

pub fn betas(&self) -> &Array1<f64>

Get beta values

Examples found in repository?
examples/quantum_diffusion.rs (line 78)
41fn compare_noise_schedules() -> Result<()> {
42    let num_timesteps = 100;
43
44    let schedules = vec![
45        (
46            "Linear",
47            NoiseSchedule::Linear {
48                beta_start: 0.0001,
49                beta_end: 0.02,
50            },
51        ),
52        ("Cosine", NoiseSchedule::Cosine { s: 0.008 }),
53        (
54            "Quadratic",
55            NoiseSchedule::Quadratic {
56                beta_start: 0.0001,
57                beta_end: 0.02,
58            },
59        ),
60        (
61            "Sigmoid",
62            NoiseSchedule::Sigmoid {
63                beta_start: 0.0001,
64                beta_end: 0.02,
65            },
66        ),
67    ];
68
69    println!("   Noise levels at different timesteps:");
70    println!("   Time     Linear   Cosine   Quadratic  Sigmoid");
71
72    for t in (0..=100).step_by(20) {
73        let t_idx = (t * (num_timesteps - 1) / 100).min(num_timesteps - 1);
74        print!("   t={t:3}%: ");
75
76        for (_, schedule) in &schedules {
77            let model = QuantumDiffusionModel::new(2, 4, num_timesteps, *schedule)?;
78            print!("{:8.4} ", model.betas()[t_idx]);
79        }
80        println!();
81    }
82
83    Ok(())
84}
Source

pub fn alphas_cumprod(&self) -> &Array1<f64>

Get alpha cumulative product values

Examples found in repository?
examples/quantum_diffusion.rs (line 232)
212fn visualize_diffusion_process() -> Result<()> {
213    let model = QuantumDiffusionModel::new(
214        2,  // data dimension
215        4,  // num qubits
216        20, // fewer timesteps for visualization
217        NoiseSchedule::Linear {
218            beta_start: 0.0001,
219            beta_end: 0.02,
220        },
221    )?;
222
223    // Start with a clear data point
224    let x0 = Array1::from_vec(vec![1.0, 0.5]);
225
226    println!("   Forward diffusion process:");
227    println!("   t=0 (original): [{:.3}, {:.3}]", x0[0], x0[1]);
228
229    // Show forward diffusion at different timesteps
230    for t in [5, 10, 15, 19] {
231        let (xt, _) = model.forward_diffusion(&x0, t)?;
232        let noise_level = (1.0 - model.alphas_cumprod()[t]).sqrt();
233        println!(
234            "   t={:2} (noise={:.3}): [{:.3}, {:.3}]",
235            t, noise_level, xt[0], xt[1]
236        );
237    }
238
239    println!("\n   Reverse diffusion process:");
240
241    // Start from noise
242    let mut xt = Array1::from_vec(vec![
243        2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
244        2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
245    ]);
246
247    println!("   t=19 (pure noise): [{:.3}, {:.3}]", xt[0], xt[1]);
248
249    // Show reverse diffusion
250    for t in [15, 10, 5, 0] {
251        xt = model.reverse_diffusion_step(&xt, t)?;
252        println!("   t={:2} (denoised): [{:.3}, {:.3}]", t, xt[0], xt[1]);
253    }
254
255    println!("\n   This demonstrates how diffusion models:");
256    println!("   1. Gradually add noise to data (forward process)");
257    println!("   2. Learn to reverse this process (backward process)");
258    println!("   3. Generate new samples by denoising random noise");
259
260    Ok(())
261}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V