 |
Shiokaze Framework
A research-oriented fluid solver for computer graphics
|
|
Go to the documentation of this file.
25 #ifndef SHKZ_RCMATRIX_INTERFACE_H
26 #define SHKZ_RCMATRIX_INTERFACE_H
40 template <
class N,
class T>
using RCMatrix_vector_ptr = std::shared_ptr<RCMatrix_vector_interface<N,T> >;
41 template <
class N,
class T>
using RCFixedMatrix_ptr = std::shared_ptr<RCFixedMatrix_interface<N,T> >;
42 template <
class N,
class T>
using RCMatrix_ptr = std::shared_ptr<RCMatrix_interface<N,T> >;
64 virtual RCMatrix_ptr<N,T>
allocate_matrix( N rows=0, N columns=0 )
const = 0;
96 virtual N
size()
const = 0;
103 virtual void clear( T value=T() ) = 0;
110 virtual T
at( N index )
const = 0;
119 virtual void set( N index, T value ) = 0;
128 virtual void add( N index, T value ) = 0;
155 virtual void subtract( N index, T value ) = 0;
164 virtual void multiply( N index, T value ) = 0;
173 virtual void divide( N index, T value ) = 0;
180 virtual void parallel_for_each( std::function<
void( N row, T& value )> func) = 0;
234 auto result = this->allocate_vector();
244 void for_each( std::function<
void( N row, T& value )> func) {
270 for( N i=0; i<v.size(); ++i )
set(i,v[i]);
278 template<
class Y>
void convert_to( std::vector<Y> &v )
const {
280 for( N i=0; i<v.size(); ++i ) v[i] =
at(i);
304 auto x_save = allocate_vector(x->
size());
316 template<
class Y>
void multiply(
const std::vector<Y> &rhs, std::vector<T> &result )
const {
317 auto _rhs = allocate_vector(rhs.size()); _rhs->convert_from(rhs);
318 auto _result = allocate_vector(rhs.size());
320 _result->convert_to(result);
350 virtual void clear( N row ) = 0;
361 virtual T
get( N row, N column )
const = 0;
372 virtual void add_to_element( N row, N column, T increment_value ) = 0;
406 virtual N
rows()
const = 0;
428 auto result = this->allocate_matrix();
478 void for_each( N row, std::function<
void( N column, T& value )> func) {
492 void const_for_each( N row, std::function<
void( N column, T value )> func)
const {
545 virtual RCFixedMatrix_ptr<N,T>
make_fixed()
const = 0;
554 auto result = this->allocate_vector();
567 auto result = this->allocate_matrix();
580 auto result = this->allocate_matrix();
591 auto result = this->allocate_matrix();
603 template<
class Y>
void multiply(
const std::vector<Y> &rhs, std::vector<Y> &result )
const {
604 assert( rhs.size() ==
columns());
605 auto _rhs = this->allocate_vector(
rows()); _rhs->convert_from(rhs);
606 auto _result = this->allocate_vector(
rows());
608 _result->convert_to(result);
616 template<
class Y> std::vector<Y>
multiply(
const std::vector<Y> &rhs )
const {
617 assert( rhs.size() ==
columns());
618 std::vector<Y> result;
619 multiply<Y>(rhs,result);
Interface to provide vector calculations.
Definition: RCMatrix_interface.h:36
virtual void multiply(const RCMatrix_vector_interface< N, T > *rhs, RCMatrix_vector_interface< N, T > *result) const =0
Apply multiplication to an input vector and substitute to a result vector.
bool empty() const
Get if the matrix is empty.
Definition: RCMatrix_interface.h:456
virtual void interruptible_for_each(std::function< bool(N row, T &value)> func)=0
Manipulate values in serial order.
void apply(RCMatrix_vector_interface< N, T > *x) const
Apply multiplication to an input vector.
Definition: RCMatrix_interface.h:303
virtual void const_interruptible_for_each(N row, std::function< bool(N column, T value)> func) const =0
Read values in serial order.
virtual N columns() const =0
Get the size of columns.
RCMatrix_ptr< N, T > duplicate() const
Duplicate matrix.
Definition: RCMatrix_interface.h:427
void for_each(N row, std::function< void(N column, T &value)> func)
Manipulate elements in serial order.
Definition: RCMatrix_interface.h:478
virtual void add(N index, T value)=0
Add an element value at an input index position.
void const_for_each(N row, std::function< void(N column, T value)> func) const
Read elements in serial order.
Definition: RCMatrix_interface.h:492
virtual void add_to_element(N row, N column, T increment_value)=0
Add a value to an element.
Class that encapsulates recursive_configurable class.
Definition: recursive_configurable_module.h:76
std::vector< Y > multiply(const std::vector< Y > &rhs) const
Apply multiplication to an input vector. Provided to preserve std::vector compatibility.
Definition: RCMatrix_interface.h:616
virtual void multiply(T value)=0
Multiply a value to all the elements.
virtual N size() const =0
Get the size of dimension.
void const_for_each(std::function< void(N row, T value)> func) const
Read values in serial order.
Definition: RCMatrix_interface.h:256
virtual N rows() const =0
Get the size of rows.
virtual RCFixedMatrix_ptr< N, T > make_fixed() const =0
Make a fixed matrix.
virtual T abs_max() const =0
Compute the uniform norm.
virtual void clear(T value=T())=0
Clear out all the value with the input value. Note that the dimension size of vector remain intact.
virtual void set(N index, T value)=0
Set an element value at an input index position.
virtual void const_parallel_for_each(std::function< void(N row, T value)> func) const =0
Read values in parallel.
virtual T get(N row, N column) const =0
Get the element value at the row and the column.
void for_each(std::function< void(N row, T &value)> func)
Manipulate values in serial order.
Definition: RCMatrix_interface.h:244
virtual void copy(const RCMatrix_vector_interface< N, T > *x)
Copy the vector.
Definition: RCMatrix_interface.h:77
virtual T at(N index) const =0
Get an element value at an input index position.
#define DEFINE_MODULE(CLASS_T, LNG_NAME, ARG_NAME, DESCRIPTION)
Definition that simplifies the loading module.
Definition: recursive_configurable_module.h:39
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
RCMatrix_ptr< N, T > multiply(const RCMatrix_interface< N, T > *m) const
Apply multiplication to an input matrix of the form: [result] = [self][m].
Definition: RCMatrix_interface.h:566
void clear()
Reset all the elements with zeros.
Definition: RCMatrix_interface.h:436
Interface for creating Row Compressed Matrix and vector instances. "RCMatrix" is provided as implemen...
Definition: RCMatrix_interface.h:626
virtual T dot(const RCMatrix_vector_interface< N, T > *x) const =0
Compute the dot product.
RCMatrix_vector_ptr< N, T > multiply(const RCMatrix_vector_interface< N, T > *rhs) const
Apply multiplication to an input vector.
Definition: RCMatrix_interface.h:552
void convert_from(const std::vector< Y > &v)
Convert input std::vector to the vector of this type.
Definition: RCMatrix_interface.h:268
virtual RCMatrix_ptr< N, T > allocate_matrix(N rows=0, N columns=0) const =0
Allocate a matrix.
virtual void add_scaled(T alpha, const RCMatrix_vector_interface< N, T > *x)=0
Add alpha * x.
void multiply(const std::vector< Y > &rhs, std::vector< T > &result) const
Apply multiplication to an input vector and substitute to a result vector. Provided to preserve std::...
Definition: RCMatrix_interface.h:316
RCMatrix_vector_ptr< N, T > duplicate() const
Duplicate this vector.
Definition: RCMatrix_interface.h:233
virtual void subtract(const RCMatrix_vector_interface< N, T > *x)
Subtract a vector.
Definition: RCMatrix_interface.h:144
virtual void add(const RCMatrix_interface< N, T > *m, RCMatrix_interface< N, T > *result) const =0
Add a matrix.
virtual RCMatrix_vector_ptr< N, T > allocate_vector(N size=0) const =0
Allocate a vector.
virtual void copy(const RCMatrix_interface< N, T > *m)=0
Copy the input matrix.
virtual void divide(N index, T value)=0
Divide an element value at an input index position.
virtual void multiply(N index, T value)=0
Multiply an element value at an input index position.
virtual void add(const RCMatrix_vector_interface< N, T > *x)
Add a vector.
Definition: RCMatrix_interface.h:135
N non_zeros() const
Get the number of all the non-zero entries.
Definition: RCMatrix_interface.h:445
virtual void parallel_for_each(std::function< void(N row, T &value)> func)=0
Manipulate values in parallel.
Interface for Row Compressed Matrix.
Definition: RCMatrix_interface.h:38
void convert_to(std::vector< Y > &v) const
Convert to std::vector.
Definition: RCMatrix_interface.h:278
RCMatrix_ptr< N, T > transpose() const
Transpose this matrix.
Definition: RCMatrix_interface.h:590
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
bool empty(N row) const
Get if a row in the matrix is empty.
Definition: RCMatrix_interface.h:467
virtual void interruptible_for_each(N row, std::function< bool(N column, T &value)> func)=0
Manipulate values in serial order.
virtual void const_interruptible_for_each(std::function< bool(N row, T value)> func) const =0
Read values in serial order.
virtual void clear_element(N row, N column)=0
Clear out an element with zero.
virtual void resize(N size)=0
Resize the dimension.
recursive_configurable class that also inherits module.
Definition: recursive_configurable_module.h:49
virtual void initialize(N rows, N columns)=0
Initialize matrix with rows and columns.
void multiply(const std::vector< Y > &rhs, std::vector< Y > &result) const
Apply multiplication to an input vector and substitute to a result vector. Provided to preserve std::...
Definition: RCMatrix_interface.h:603
Specialized Row Compressed Matrix that efficiently performs matrix-vector calculations.
Definition: RCMatrix_interface.h:37
Interface to provide allocators for Row Compressed Matrix and vector instances.
Definition: RCMatrix_interface.h:47
RCMatrix_ptr< N, T > add(const RCMatrix_interface< N, T > *m) const
Add to an input matrix.
Definition: RCMatrix_interface.h:579