binius_compute/
ops.rs

1// Copyright 2025 Irreducible Inc.
2
3use binius_field::TowerField;
4
5use super::{
6	ComputeLayerExecutor, ComputeMemory,
7	alloc::ComputeAllocator,
8	layer::{ComputeLayer, Error, FSliceMut},
9};
10
11/// Computes the partial evaluation of the equality indicator polynomial.
12///
13/// Given an $n$-coordinate point $r_0, ..., r_n$, this computes the partial evaluation of the
14/// equality indicator polynomial $\widetilde{eq}(X_0, ..., X_{n-1}, r_0, ..., r_{n-1})$ and
15/// returns its values over the $n$-dimensional hypercube.
16///
17/// The returned values are equal to the tensor product
18///
19/// $$
20/// (1 - r_0, r_0) \otimes ... \otimes (1 - r_{n-1}, r_{n-1}).
21/// $$
22///
23/// See [DP23], Section 2.1 for more information about the equality indicator polynomial.
24///
25/// [DP23]: <https://eprint.iacr.org/2023/1784>
26pub fn eq_ind_partial_eval<'a, F, Hal, DeviceAllocatorType>(
27	hal: &Hal,
28	dev_alloc: &'a DeviceAllocatorType,
29	point: &[F],
30) -> Result<FSliceMut<'a, F, Hal>, Error>
31where
32	F: TowerField,
33	Hal: ComputeLayer<F>,
34	DeviceAllocatorType: ComputeAllocator<F, Hal::DevMem>,
35{
36	let n_vars = point.len();
37	let mut out = dev_alloc.alloc(1 << n_vars)?;
38
39	{
40		let mut dev_val = Hal::DevMem::slice_power_of_two_mut(&mut out, 1);
41		hal.fill(&mut dev_val, F::ONE)?;
42	}
43
44	hal.execute(|exec| {
45		exec.tensor_expand(0, point, &mut out)?;
46		Ok(vec![])
47	})?;
48
49	Ok(out)
50}