Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yet another vector rewrite #53

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/crates/algebra/src/algebra/adem_algebra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use itertools::Itertools;
use rustc_hash::FxHashMap as HashMap;

use fp::prime::{BinomialIterator, BitflagIterator, ValidPrime};
use fp::vector::{FpVector, SliceMut};
use fp::vector::{prelude::*, FpVector, SliceMut};
use once::OnceVec;

use crate::algebra::combinatorics::{self, MAX_XI_TAU};
Expand Down
2 changes: 1 addition & 1 deletion ext/crates/algebra/src/algebra/algebra_trait.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use fp::prime::ValidPrime;
use fp::vector::{Slice, SliceMut};
use fp::vector::{prelude::*, Slice, SliceMut};

use std::fmt::Write as _; // Needed for write! macro for String

Expand Down
6 changes: 3 additions & 3 deletions ext/crates/algebra/src/algebra/combinatorics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use fp::vector::FpVector;
use fp::vector::{prelude::*, FpVector};
use once::OnceVec;

use fp::prime::{minus_one_to_the_n, Binomial, ValidPrime};
Expand All @@ -9,7 +9,7 @@ pub const MAX_XI_TAU: usize = MAX_MULTINOMIAL_LEN;
/// If p is the nth prime, then `XI_DEGREES[n][i - 1]` is the degree of $ξ_i$ at the prime p divided by
/// q, where q = 2p - 2 if p != 2 and 1 if p = 2.
const XI_DEGREES: [[i32; MAX_XI_TAU]; NUM_PRIMES] = {
let mut res = [[0; 10]; 8];
let mut res = [[0; 10]; NUM_PRIMES];
const_for! { p_idx in 0 .. NUM_PRIMES {
let p = PRIMES[p_idx];
let mut p_to_the_i = p;
Expand All @@ -26,7 +26,7 @@ const XI_DEGREES: [[i32; MAX_XI_TAU]; NUM_PRIMES] = {
/// If p is the nth prime, then `TAU_DEGREES[n][i]` is the degree of $τ_i$ at the prime p. Its value is
/// nonsense at the prime 2
const TAU_DEGREES: [[i32; MAX_XI_TAU]; NUM_PRIMES] = {
let mut res = [[0; 10]; 8];
let mut res = [[0; 10]; NUM_PRIMES];
const_for! { p_idx in 0 .. NUM_PRIMES {
let p = PRIMES[p_idx];
let mut p_to_the_i: u32 = 1;
Expand Down
2 changes: 1 addition & 1 deletion ext/crates/algebra/src/algebra/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::algebra::{Algebra, Bialgebra};
use fp::prime::ValidPrime;
use fp::vector::{Slice, SliceMut};
use fp::vector::{prelude::*, Slice, SliceMut};

/// $\mathbb{F}_p$, viewed as an [`Algebra`] over itself.
///
Expand Down
2 changes: 1 addition & 1 deletion ext/crates/algebra/src/algebra/milnor_algebra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::cell::Cell;
use crate::algebra::combinatorics;
use crate::algebra::{Algebra, Bialgebra, GeneratedAlgebra, UnstableAlgebra};
use fp::prime::{factor_pk, integer_power, Binomial, BitflagIterator, ValidPrime};
use fp::vector::{FpVector, Slice, SliceMut};
use fp::vector::{prelude::*, FpVector, Slice, SliceMut};
use once::OnceVec;

#[cfg(feature = "json")]
Expand Down
2 changes: 1 addition & 1 deletion ext/crates/algebra/src/algebra/pair_algebra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use crate::combinatorics;
use crate::Algebra;
use fp::prime::TWO;
use fp::vector::{FpVector, Slice, SliceMut};
use fp::vector::{prelude::*, FpVector, Slice, SliceMut};
use rustc_hash::FxHasher;

type HashMap<K, V> = hashbrown::HashMap<K, V, std::hash::BuildHasherDefault<FxHasher>>;
Expand Down
2 changes: 1 addition & 1 deletion ext/crates/algebra/src/algebra/polynomial_algebra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc_hash::FxHashMap as HashMap;
use std::fmt;

use fp::prime::ValidPrime;
use fp::vector::{FpVector, SliceMut};
use fp::vector::{prelude::*, FpVector, SliceMut};
use once::OnceVec;

use crate::algebra::combinatorics::TruncatedPolynomialMonomialBasis;
Expand Down
2 changes: 1 addition & 1 deletion ext/crates/algebra/src/module/block_structure.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bivec::BiVec;
use fp::vector::{Slice, SliceMut};
use fp::vector::{prelude::*, Slice, SliceMut};
use std::ops::Range;

#[derive(Debug)]
Expand Down
4 changes: 2 additions & 2 deletions ext/crates/algebra/src/module/finite_dimensional_module.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::algebra::Algebra;
use crate::module::{Module, ZeroModule};
use bivec::BiVec;
use fp::vector::{FpVector, SliceMut};
use fp::vector::{prelude::*, FpVector, SliceMut};

use std::fmt::Write as _;
use std::sync::Arc;
Expand Down Expand Up @@ -178,7 +178,7 @@ impl<A: Algebra> Module for FiniteDimensionalModule<A> {
return;
}
let output = self.action(op_degree, op_index, mod_degree, mod_index);
result.add(output.as_slice(), coeff);
result.add(output, coeff);
}

fn max_degree(&self) -> Option<i32> {
Expand Down
4 changes: 2 additions & 2 deletions ext/crates/algebra/src/module/finitely_presented_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use crate::algebra::Algebra;
use crate::module::homomorphism::{FreeModuleHomomorphism, ModuleHomomorphism};
use crate::module::{FreeModule, Module, ZeroModule};
use fp::vector::{FpVector, SliceMut};
use fp::vector::{prelude::*, FpVector, SliceMut};
use once::OnceBiVec;

#[cfg(feature = "json")]
Expand Down Expand Up @@ -233,7 +233,7 @@ impl<A: Algebra> Module for FinitelyPresentedModule<A> {
);
let image = self.map.image(out_deg).unwrap();
image.reduce(temp_vec.as_slice_mut());
for i in 0..result.as_slice().len() {
for i in 0..result.len() {
let value = temp_vec.entry(self.fp_idx_to_gen_idx(out_deg, i));
result.add_basis_element(i, value);
}
Expand Down
2 changes: 1 addition & 1 deletion ext/crates/algebra/src/module/free_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use crate::algebra::MuAlgebra;
use crate::module::{Module, ZeroModule};
use fp::vector::{Slice, SliceMut};
use fp::vector::{prelude::*, Slice, SliceMut};
use once::{OnceBiVec, OnceVec};

#[derive(Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion ext/crates/algebra/src/module/hom_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bivec::BiVec;
use crate::algebra::Field;
use crate::module::block_structure::BlockStructure;
use crate::module::{FreeModule, Module};
use fp::vector::SliceMut;
use fp::vector::{prelude::*, SliceMut};
use once::OnceBiVec;

/// Given a module N and a free module M, this is the module Hom(M, N) as a module over the ground
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::module::free_module::OperationGeneratorPair;
use crate::module::homomorphism::{ModuleHomomorphism, ZeroHomomorphism};
use crate::module::{Module, MuFreeModule};
use fp::matrix::{MatrixSliceMut, QuasiInverse, Subspace};
use fp::vector::{FpVector, Slice, SliceMut};
use fp::vector::{prelude::*, FpVector, Slice, SliceMut};
use once::OnceBiVec;

pub type FreeModuleHomomorphism<M> = MuFreeModuleHomomorphism<false, M>;
Expand Down Expand Up @@ -55,10 +55,7 @@ where
assert!(input_degree >= self.source.min_degree());
assert!(input_index < self.source.dimension(input_degree));
let output_degree = input_degree - self.degree_shift;
assert_eq!(
self.target.dimension(output_degree),
result.as_slice().len()
);
assert_eq!(self.target.dimension(output_degree), result.len());
let OperationGeneratorPair {
operation_degree,
generator_degree,
Expand Down Expand Up @@ -191,7 +188,6 @@ where
}
for (i, new_output) in new_outputs.iter_mut().enumerate() {
new_output
.as_slice_mut()
.assign(outputs_vectors.slice(target_dimension * i, target_dimension * (i + 1)));
}
self.outputs.push_checked(new_outputs, degree);
Expand All @@ -213,7 +209,7 @@ where
return;
}
for (i, new_output) in new_outputs.iter_mut().enumerate() {
new_output.as_slice_mut().assign(matrix.row(i));
new_output.assign(matrix.row(i));
}
self.outputs.push_checked(new_outputs, degree);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::module::homomorphism::{IdentityHomomorphism, ModuleHomomorphism, Zero
use crate::module::Module;
use bivec::BiVec;
use fp::matrix::{Matrix, QuasiInverse, Subspace};
use fp::vector::SliceMut;
use fp::vector::{prelude::*, SliceMut};
use once::OnceBiVec;

/// A ModuleHomomorphism that simply records the matrix of the homomorphism in every degree.
Expand Down Expand Up @@ -62,7 +62,7 @@ impl<S: Module, T: Module<Algebra = S::Algebra>> ModuleHomomorphism
) {
let output_degree = input_degree - self.degree_shift;
if let Some(matrix) = self.matrices.get(output_degree) {
result.add(matrix[input_idx].as_slice(), coeff);
result.add(&matrix[input_idx], coeff);
}
}

Expand Down
2 changes: 1 addition & 1 deletion ext/crates/algebra/src/module/homomorphism/hom_pullback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::module::homomorphism::{FreeModuleHomomorphism, ModuleHomomorphism};
use crate::module::HomModule;
use crate::module::{FreeModule, Module};
use fp::matrix::{QuasiInverse, Subspace};
use fp::vector::SliceMut;
use fp::vector::{prelude::*, SliceMut};
use once::OnceBiVec;

/// Given a map $\mathtt{map}: A \to B$ and hom modules $\mathtt{source} = \Hom(B, X)$, $\mathtt{target} = \Hom(A, X)$, produce the induced pullback map $\Hom(B, X) \to \Hom(A, X)$.
Expand Down
2 changes: 1 addition & 1 deletion ext/crates/algebra/src/module/homomorphism/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use crate::module::Module;
use fp::matrix::{AugmentedMatrix, Matrix, MatrixSliceMut, QuasiInverse, Subspace};
use fp::prime::ValidPrime;
use fp::vector::{Slice, SliceMut};
use fp::vector::{prelude::*, Slice, SliceMut};

#[cfg(feature = "concurrent")]
use rayon::prelude::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::module::{Module, QuotientModule};
use fp::vector::{FpVector, SliceMut};
use fp::vector::{prelude::*, FpVector, SliceMut};
use std::sync::Arc;

use crate::module::homomorphism::ModuleHomomorphism;
Expand Down
2 changes: 1 addition & 1 deletion ext/crates/algebra/src/module/module_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use itertools::Itertools;
use std::sync::Arc;

use fp::prime::ValidPrime;
use fp::vector::{Slice, SliceMut};
use fp::vector::{prelude::*, Slice, SliceMut};

use crate::algebra::Algebra;

Expand Down
2 changes: 1 addition & 1 deletion ext/crates/algebra/src/module/quotient_module.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::module::{Module, ZeroModule};
use bivec::BiVec;
use fp::matrix::Subspace;
use fp::vector::{FpVector, Slice, SliceMut};
use fp::vector::{prelude::*, FpVector, Slice, SliceMut};
use std::sync::Arc;

/// A quotient of a module truncated below a fix degree.
Expand Down
2 changes: 1 addition & 1 deletion ext/crates/algebra/src/module/rpn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::algebra::{
};
use crate::module::{Module, ZeroModule};
use fp::prime::{Binomial, TWO};
use fp::vector::SliceMut;
use fp::vector::{prelude::*, SliceMut};

use std::sync::Arc;

Expand Down
2 changes: 1 addition & 1 deletion ext/crates/algebra/src/module/tensor_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::algebra::{Algebra, Bialgebra};
use crate::module::block_structure::BlockStructure;
use crate::module::{Module, ZeroModule};
use fp::prime::minus_one_to_the_n;
use fp::vector::{FpVector, Slice, SliceMut};
use fp::vector::{prelude::*, FpVector, Slice, SliceMut};

use std::sync::Arc;

Expand Down
2 changes: 1 addition & 1 deletion ext/crates/algebra/src/steenrod_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::algebra::{AdemAlgebra, Algebra, MilnorAlgebra};
use crate::milnor_algebra::{MilnorBasisElement, PPartEntry};
use crate::steenrod_parser::*;
use fp::prime::ValidPrime;
use fp::vector::FpVector;
use fp::vector::{prelude::*, FpVector};

use anyhow::anyhow;
use std::collections::BTreeMap;
Expand Down
1 change: 1 addition & 0 deletions ext/crates/fp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ expect-test = "1.1.0"

[build-dependencies]
build_const = "0.2.2"
itertools = "0.10"

[features]
default = ["odd-primes"]
Expand Down
18 changes: 13 additions & 5 deletions ext/crates/fp/benches/criterion.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::time::Duration;

use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use fp::{matrix::Matrix, prime::ValidPrime};
use rand::Rng;

#[cfg(feature = "odd-primes")]
static TEST_PRIMES: [u32; 4] = [2, 3, 5, 7];
#[cfg(not(feature = "odd-primes"))]
static TEST_PRIMES: [u32; 1] = [2];

fn random_matrix(p: ValidPrime, dimension: usize) -> Matrix {
Matrix::from_vec(
p,
Expand All @@ -14,10 +17,15 @@ fn random_matrix(p: ValidPrime, dimension: usize) -> Matrix {
}

fn row_reductions(c: &mut Criterion) {
for p in [2, 3, 5, 7].iter() {
for p in TEST_PRIMES.iter() {
let p = ValidPrime::new(*p);
let mut group = c.benchmark_group(&format!("row_reduce_{}", p));
for dimension in [10, 20, 69, 100, 420, 1000] {
let sizes = if *p == 2 {
vec![10, 20, 69, 100, 420, 1000, 2000, 4000]
} else {
vec![10, 20, 69, 100, 420, 1000]
};
for dimension in sizes {
group.bench_function(&format!("row_reduce_{}_{}", p, dimension), move |b| {
b.iter_batched_ref(
|| random_matrix(p, dimension),
Expand All @@ -41,7 +49,7 @@ fn random_vector(p: ValidPrime, dimension: usize) -> Vec<u32> {

criterion_group! {
name = row_reduction;
config = Criterion::default().sample_size(100).measurement_time(Duration::from_secs(100));
config = Criterion::default().sample_size(100).measurement_time(std::time::Duration::from_secs(100));
targets = row_reductions
}

Expand Down
11 changes: 11 additions & 0 deletions ext/crates/fp/benches/iai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ fn row_reduce_7_420() {
row_reduce_p_n(ValidPrime::new(7), 420);
}

#[cfg(feature = "odd-primes")]
iai::main!(
row_reduce_2_10,
row_reduce_2_20,
Expand All @@ -143,3 +144,13 @@ iai::main!(
row_reduce_7_420,
row_reduce_7_1000,
);

#[cfg(not(feature = "odd-primes"))]
iai::main!(
row_reduce_2_10,
row_reduce_2_20,
row_reduce_2_69,
row_reduce_2_100,
row_reduce_2_420,
row_reduce_2_1000,
);
Loading