Skip to content

Commit 7b25f24

Browse files
committed
Add public documentation
1 parent 4c86307 commit 7b25f24

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

ext/crates/fp/src/vector/base_generic.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,70 @@ use super::{
55
use crate::{limb::LimbLength, prime::ValidPrime};
66

77
pub trait BaseVectorP<const P: u32>: InternalBaseVectorP<P> {
8+
/// The characteristic of the underlying field.
89
fn prime(&self) -> ValidPrime;
10+
/// The length of the vector.
911
fn len(&self) -> usize;
12+
/// Whether the vector is empty.
1013
fn is_empty(&self) -> bool;
14+
/// The entry at index `index`.
1115
fn entry(&self, index: usize) -> u32;
16+
/// A slice of the vector starting at entry `start` (inclusive) and ending at entry `end`
17+
/// (exclusive). This means that `v.slice(start, end).len() == end - start`.
1218
fn slice<'a>(&self, start: usize, end: usize) -> SliceP<'a, P>
1319
where
1420
Self: 'a;
21+
/// The vector itself as a slice.
1522
fn as_slice(&self) -> SliceP<P>;
23+
/// Whether the vector is zero.
1624
fn is_zero(&self) -> bool;
25+
/// An iterator over the entries in the vector.
1726
fn iter(&self) -> FpVectorIterator;
27+
/// An iterator over the *nonzero* entries in the vector.
1828
fn iter_nonzero(&self) -> FpVectorNonZeroIteratorP<P>;
29+
/// The position of the first nonzero entry in the vector, together with its value. This returns
30+
/// `None` if and only if the vector is zero.
1931
fn first_nonzero(&self) -> Option<(usize, u32)>;
32+
/// ???
2033
fn sign_rule<T: BaseVectorP<P>>(&self, other: T) -> bool;
34+
/// Copy the contents of the vector into an owned `FpVector`. If the vector is already an
35+
/// `FpVector`, this is a no-op.
2136
fn into_owned(self) -> FpVectorP<P>;
37+
/// The proportion of non-zero entries.
2238
fn density(&self) -> f32;
2339
}
2440

2541
pub trait BaseVectorMutP<const P: u32>: InternalBaseVectorMutP<P> + BaseVectorP<P> {
42+
/// Scale all entries by a factor of `c`. It is assumed that `c < P`.
2643
fn scale(&mut self, c: u32);
44+
/// Set the vector to the zero vector.
2745
fn set_to_zero(&mut self);
46+
/// Set the entry at index `index` to the value `value`. It is assumed that `value < P`.
2847
fn set_entry(&mut self, index: usize, value: u32);
48+
/// Copy the contents of `other` into `self`. Both vectors must have the same length.
2949
fn assign<T: BaseVectorP<P>>(&mut self, other: T);
50+
/// Add `c` times `other` to `self`. Both `other` and `self` must have the same length, and we
51+
/// must have `c < P`.
3052
fn add<T: BaseVectorP<P>>(&mut self, other: T, c: u32);
53+
/// Add `c` times `other` to `self`, assuming that all entries of `self` with index less than
54+
/// `offset` are zero. Violating this assumption does not lead to a panic or UB, but is very
55+
/// likely to produce nonsensical results.
3156
fn add_offset<T: BaseVectorP<P>>(&mut self, other: T, c: u32, offset: usize);
57+
/// A mutable slice of the vector starting at entry `start` (inclusive) and ending at entry
58+
/// `end` (exclusive). This means that `v.slice_mut(start, end).len() == end - start`.
3259
fn slice_mut(&mut self, start: usize, end: usize) -> SliceMutP<P>;
60+
/// The vector itself as a mutable slice.
3361
fn as_slice_mut(&mut self) -> SliceMutP<P>;
62+
/// Add `value` to the entry at index `index`.
3463
fn add_basis_element(&mut self, index: usize, value: u32);
64+
/// Replace the contents of the vector with the contents of the slice. The two must have the
65+
/// same length.
3566
fn copy_from_slice(&mut self, slice: &[u32]);
67+
/// Given a mask v, add the `v[i]`th entry of `other` to the `i`th entry of `self`.
3668
fn add_masked<T: BaseVectorP<P>>(&mut self, other: T, c: u32, mask: &[usize]);
69+
/// Given a mask v, add the `i`th entry of `other` to the `v[i]`th entry of `self`.
3770
fn add_unmasked<T: BaseVectorP<P>>(&mut self, other: T, c: u32, mask: &[usize]);
71+
/// ???
3872
fn add_truncate<T: BaseVectorP<P>>(&mut self, other: T, c: u32) -> Option<()>;
3973
}
4074

ext/crates/fp/src/vector/internal/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,6 @@ pub trait InternalBaseVectorMutP<const P: u32>: InternalBaseVectorP<P> {
669669
self._limbs_mut()[target_range.end - 1] |= result;
670670
}
671671

672-
/// This replaces the contents of the vector with the contents of the slice. The two must have
673-
/// the same length.
674-
///
675672
/// This method is only implemented on `FpVectorP` right now. This is the only use case so far,
676673
/// so I don't feel too bad about marking it as unimplemented in the general case.
677674
fn _copy_from_slice(&mut self, _slice: &[u32]) {

ext/crates/fp/src/vector/specialized.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,37 +123,71 @@ macro_rules! dispatch_basevectormut {
123123

124124
/// Trait for common methods on vector-type structs.
125125
pub trait BaseVector {
126+
/// The characteristic of the underlying field.
126127
fn prime(&self) -> ValidPrime;
128+
/// The length of the vector.
127129
fn len(&self) -> usize;
130+
/// Whether the vector is empty.
128131
fn is_empty(&self) -> bool;
132+
/// The entry at index `index`.
129133
fn entry(&self, index: usize) -> u32;
134+
/// A slice of the vector starting at entry `start` (inclusive) and ending at entry `end`
135+
/// (exclusive). This means that `v.slice(start, end).len() == end - start`.
130136
fn slice<'a>(&self, start: usize, end: usize) -> Slice<'a>
131137
where
132138
Self: 'a;
139+
/// The vector itself as a slice.
133140
fn as_slice(&self) -> Slice;
134-
fn into_owned(self) -> FpVector;
141+
/// Whether the vector is zero.
135142
fn is_zero(&self) -> bool;
143+
/// An iterator over the entries in the vector.
136144
fn iter(&self) -> FpVectorIterator;
145+
/// An iterator over the *nonzero* entries in the vector.
137146
fn iter_nonzero(&self) -> FpVectorNonZeroIterator;
147+
/// The position of the first nonzero entry in the vector, together with its value. This returns
148+
/// `None` if and only if the vector is zero.
138149
fn first_nonzero(&self) -> Option<(usize, u32)>;
150+
/// ???
139151
fn sign_rule(&self, other: &Self) -> bool;
152+
/// Copy the contents of the vector into an owned `FpVector`. If the vector is already an
153+
/// `FpVector`, this is a no-op.
154+
fn into_owned(self) -> FpVector;
155+
/// The proportion of non-zero entries.
140156
fn density(&self) -> f32;
141157
}
142158

143159
/// Trait for common methods on mutable vector-type structs.
144160
pub trait BaseVectorMut: BaseVector {
161+
/// Scale all entries by a factor of `c`. It is assumed that `c < P`.
145162
fn scale(&mut self, c: u32);
163+
/// Set the vector to the zero vector.
146164
fn set_to_zero(&mut self);
165+
/// Set the entry at index `index` to the value `value`. It is assumed that `value < P`.
147166
fn set_entry(&mut self, index: usize, value: u32);
167+
/// Copy the contents of `other` into `self`. Both vectors must have the same length.
148168
fn assign<'a, T: Into<Slice<'a>>>(&mut self, other: T);
169+
/// Add `c` times `other` to `self`. Both `other` and `self` must have the same length, and we
170+
/// must have `c < P`.
149171
fn add<'a, T: Into<Slice<'a>>>(&mut self, other: T, c: u32);
172+
/// Add `c` times `other` to `self`, assuming that all entries of `self` with index less than
173+
/// `offset` are zero. Violating this assumption does not lead to a panic or UB, but is very
174+
/// likely to produce nonsensical results.
150175
fn add_offset<'a, T: Into<Slice<'a>>>(&mut self, other: T, c: u32, offset: usize);
176+
/// A mutable slice of the vector starting at entry `start` (inclusive) and ending at entry
177+
/// `end` (exclusive). This means that `v.slice_mut(start, end).len() == end - start`.
151178
fn slice_mut(&mut self, start: usize, end: usize) -> SliceMut;
179+
/// The vector itself as a mutable slice.
152180
fn as_slice_mut(&mut self) -> SliceMut;
181+
/// Add `value` to the entry at index `index`.
153182
fn add_basis_element(&mut self, index: usize, value: u32);
183+
/// Replace the contents of the vector with the contents of the slice. The two must have the
184+
/// same length.
154185
fn copy_from_slice(&mut self, slice: &[u32]);
186+
/// Given a mask v, add the `v[i]`th entry of `other` to the `i`th entry of `self`.
155187
fn add_masked<'a, T: Into<Slice<'a>>>(&mut self, other: T, c: u32, mask: &[usize]);
188+
/// Given a mask v, add the `i`th entry of `other` to the `v[i]`th entry of `self`.
156189
fn add_unmasked<'a, T: Into<Slice<'a>>>(&mut self, other: T, c: u32, mask: &[usize]);
190+
/// ???
157191
fn add_truncate<'a, T: Into<Slice<'a>>>(&mut self, other: T, c: u32) -> Option<()>;
158192
}
159193

0 commit comments

Comments
 (0)