Skip to content

Better Floating-Point Hiding #198

@ryanmrichard

Description

@ryanmrichard

I'm spitballing as I think about how to unwrap a BufferBase into a pointer in order to call an external eigen solver. My original thought was, the user writes a templated function:

template<typename FloatingType>
BufferBase& do_stuff(BufferBase& buffer){
    tensorwrappbr::allocator::Contiguous<FloatingType> alloc;
    auto& buffer_downcast = alloc.rebind(buffer);
    auto* pbuffer = buffer_downcast.data();
    // Do stuff, like build Eigen::Map<MatrixXd>...
    return buffer_downcast;
}

Then in the module for the eigen solve, for example:

using no_uq_type = double;
using uq_type = as_uq_type<no_uq_type>; // Trait that knows about ENABLE_SIGMA

BufferBase& buffer;
BufferBase* p
if(uq)
   return do_stuff<uq_type>(buffer);
else
   return do_stuff<no_uq_type>(buffer)

The other option is to do visitor pattern, where the visitor knows about all of the floating point types and the derived class of BufferBase just calls the appropriate overload of the visitor (the visitor could have all members dispatch to a templated method if the code is always the same).

This issue is for me to work through the design, instead of just brute forcing it like I started to do with the fp_helper branch.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions