Skip to content

Commit

Permalink
Better elements
Browse files Browse the repository at this point in the history
  • Loading branch information
tbetcke committed Jan 15, 2025
1 parent add4d0c commit 1ce15c0
Show file tree
Hide file tree
Showing 13 changed files with 242 additions and 83 deletions.
4 changes: 3 additions & 1 deletion examples/cg_distributed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use mpi::topology::Communicator;
use rand::Rng;
use rlst::operator::interface::DistributedArrayVectorSpace;
use rlst::operator::Operator;
use rlst::{CgIteration, DistributedCsrMatrix, Element, IndexLayout, LinearSpace, OperatorBase};
use rlst::{
CgIteration, DistributedCsrMatrix, ElementImpl, IndexLayout, LinearSpace, OperatorBase,
};

pub fn main() {
let universe = mpi::initialize().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/operator/abstract_operator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Definition of a general linear operator.
use crate::operator::element::Element;
use crate::operator::element::ElementImpl;
use crate::operator::LinearSpace;
use crate::RlstScalar;
use num::One;
Expand Down
9 changes: 5 additions & 4 deletions src/operator/interface/array_vector_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use crate::dense::{
base_array::BaseArray,
data_container::VectorContainer,
};
use crate::operator::space::{Element, IndexableSpace, InnerProductSpace, LinearSpace};
use crate::operator::space::{ElementImpl, IndexableSpace, InnerProductSpace, LinearSpace};
use crate::operator::{ConcreteElementContainer, Element};
use crate::rlst_dynamic_array1;

/// Array vector space
Expand Down Expand Up @@ -67,8 +68,8 @@ impl<Item: RlstScalar> LinearSpace for ArrayVectorSpace<Item> {

type F = Item;

fn zero(space: Rc<Self>) -> Self::E {
ArrayVectorSpaceElement::new(space)
fn zero(space: Rc<Self>) -> Element<ConcreteElementContainer<Self::E>> {
Element::<ConcreteElementContainer<Self::E>>::new(ArrayVectorSpaceElement::new(space))
}
}

Expand All @@ -78,7 +79,7 @@ impl<Item: RlstScalar> InnerProductSpace for ArrayVectorSpace<Item> {
}
}

impl<Item: RlstScalar> Element for ArrayVectorSpaceElement<Item> {
impl<Item: RlstScalar> ElementImpl for ArrayVectorSpaceElement<Item> {
type F = Item;
type Space = ArrayVectorSpace<Item>;

Expand Down
11 changes: 7 additions & 4 deletions src/operator/interface/distributed_array_vector_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use std::rc::Rc;
use mpi::traits::{Communicator, Equivalence};

use crate::dense::types::RlstScalar;
use crate::operator::space::{Element, IndexableSpace, InnerProductSpace, LinearSpace};
use crate::operator::space::{ElementImpl, IndexableSpace, InnerProductSpace, LinearSpace};
use crate::operator::{ConcreteElementContainer, Element};
use crate::DistributedVector;
use bempp_distributed_tools::IndexLayout;

Expand Down Expand Up @@ -69,8 +70,10 @@ impl<'a, C: Communicator, Item: RlstScalar + Equivalence> LinearSpace

type F = Item;

fn zero(space: Rc<Self>) -> Self::E {
DistributedArrayVectorSpaceElement::new(space.clone())
fn zero(space: Rc<Self>) -> Element<ConcreteElementContainer<Self::E>> {
Element::<ConcreteElementContainer<_>>::new(DistributedArrayVectorSpaceElement::new(
space.clone(),
))
}
}

Expand All @@ -82,7 +85,7 @@ impl<C: Communicator, Item: RlstScalar + Equivalence> InnerProductSpace
}
}

impl<'a, C: Communicator, Item: RlstScalar + Equivalence> Element
impl<'a, C: Communicator, Item: RlstScalar + Equivalence> ElementImpl
for DistributedArrayVectorSpaceElement<'a, C, Item>
{
type F = Item;
Expand Down
2 changes: 1 addition & 1 deletion src/operator/interface/distributed_sparse_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::dense::types::RlstScalar;
use crate::operator::Operator;
use crate::DistributedCsrMatrix;
use crate::{
operator::space::{Element, IndexableSpace, LinearSpace},
operator::space::{ElementImpl, IndexableSpace, LinearSpace},
operator::AsApply,
operator::OperatorBase,
};
Expand Down
2 changes: 1 addition & 1 deletion src/operator/interface/matrix_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::dense::{
};
use crate::operator::Operator;
use crate::{
operator::space::{Element, LinearSpace},
operator::space::{ElementImpl, LinearSpace},
operator::AsApply,
operator::OperatorBase,
};
Expand Down
6 changes: 3 additions & 3 deletions src/operator/operations/conjugate_gradients.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Arnoldi Iteration
use crate::dense::types::RlstScalar;
use crate::operator::{AsApply, Element, InnerProductSpace, LinearSpace};
use crate::operator::{AsApply, ElementImpl, InnerProductSpace, LinearSpace};
use num::One;

/// Iteration for CG
pub struct CgIteration<'a, Space: InnerProductSpace, Op: AsApply<Domain = Space, Range = Space>>
where
<Space::E as Element>::Space: InnerProductSpace,
<Space::E as ElementImpl>::Space: InnerProductSpace,
{
operator: &'a Op,
rhs: &'a Space::E,
Expand All @@ -21,7 +21,7 @@ where
impl<'a, Space: InnerProductSpace, Op: AsApply<Domain = Space, Range = Space>>
CgIteration<'a, Space, Op>
where
<Space::E as Element>::Space: InnerProductSpace,
<Space::E as ElementImpl>::Space: InnerProductSpace,
{
/// Create a new CG iteration
pub fn new(op: &'a Op, rhs: &'a Space::E) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions src/operator/operations/modified_gram_schmidt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::dense::{
array::DynamicArray,
traits::{RandomAccessMut, Shape},
};
use crate::operator::{frame::Frame, Element, InnerProductSpace, NormedSpace};
use crate::operator::{frame::Frame, ElementImpl, InnerProductSpace, NormedSpace};
use num::One;
/// Gram Schmidt orthogonalization
pub struct ModifiedGramSchmidt;
Expand All @@ -14,7 +14,7 @@ impl ModifiedGramSchmidt {
pub fn orthogonalize<
'a,
Item: RlstScalar,
Elem: Element<F = Item>,
Elem: ElementImpl<F = Item>,
Space: InnerProductSpace<E = Elem, F = Item> + 'a,
FrameType: Frame<E = Elem>,
>(
Expand Down
Loading

0 comments on commit 1ce15c0

Please sign in to comment.