powerit
C++ implementation for power iterations
Loading...
Searching...
No Matches
Classes | Functions
powerit Namespace Reference

Namespace for power iterations. More...

Classes

struct  Options
 Options for compute(). More...
 
struct  Result
 Result of compute(). More...
 

Functions

template<typename Data_ , class Engine_ >
void fill_starting_vector (size_t order, Data_ *vector, Engine_ &engine)
 
template<class Multiply_ , typename Data_ >
Result< Data_ > compute_core (size_t order, Multiply_ multiply, Data_ *vector, const Options &opt)
 
template<typename Task_ , class Run_ >
void parallelize (int num_workers, Task_ num_tasks, Run_ run_task_range)
 
template<typename Data_ , class Engine_ >
Result< Data_ > compute (size_t order, const Data_ *matrix, bool row_major, Data_ *vector, Engine_ &engine, const Options &opt)
 
template<typename Data_ >
Result< Data_ > compute (size_t order, const Data_ *matrix, bool row_major, Data_ *vector, const Options &opt)
 

Detailed Description

Namespace for power iterations.

Function Documentation

◆ compute() [1/2]

template<typename Data_ >
Result< Data_ > powerit::compute ( size_t  order,
const Data_ *  matrix,
bool  row_major,
Data_ *  vector,
const Options opt 
)

Perform power iterations on an array containing a diagonizable matrix. This overload assumes that a random starting vector has already been generated.

Template Parameters
Data_Floating-point type for the data.
Parameters
orderOrder of the square matrix.
[in]matrixPointer to an array containing an order-by-order diagonalizable matrix.
row_majorWhether matrix is row-major.
[in,out]vectorPointer to an array of length order. On input, this should contain a random starting vector. On output, this contains the estimate of the first eigenvector.
optFurther options.
Returns
Result containing the first eigenvalue and other diagnostics.

◆ compute() [2/2]

template<typename Data_ , class Engine_ >
Result< Data_ > powerit::compute ( size_t  order,
const Data_ *  matrix,
bool  row_major,
Data_ *  vector,
Engine_ &  engine,
const Options opt 
)

Perform power iterations on a diagonizable matrix to find the first eigenvalue/vector. This overload generates a starting vector from an existing (P)RNG.

Template Parameters
Data_Floating-point type for the data.
Engine_Any C++11-compliant random number generator class.
Parameters
orderOrder of the square matrix.
[in]matrixPointer to an array containing an order-by-order diagonalizable matrix.
row_majorWhether matrix is row-major.
[out]vectorPointer to an array of length order. On output, this contains the estimate of the first eigenvector.
engineInstance of the random number generator.
optFurther options.
Returns
Result containing the first eigenvalue and other diagnostics.

◆ compute_core()

template<class Multiply_ , typename Data_ >
Result< Data_ > powerit::compute_core ( size_t  order,
Multiply_  multiply,
Data_ *  vector,
const Options opt 
)

Perform power iterations on some diagonizable matrix to find the first eigenvalue/vector. This overload generates a starting vector from an existing (P)RNG.

Template Parameters
Multiply_Function that performs a matrix dot product. This is used to abstract away the representation of the actual matrix.
Data_Floating-point type for the data.
Engine_Any C++11-compliant random number generator class.
Parameters
orderOrder of the square matrix.
multiplyFunction to perform a matrix dot product with the working eigenvector. This should accept buffer, a std::vector<Data_>& of length order; and vector, a const Data_* as described below. It should fill buffer with the product of the matrix and vector. The return value is ignored.
[out]vectorPointer to an array of length order. On output, this contains the estimate of the first eigenvector.
optFurther options.
Returns
Result containing the first eigenvalue and other diagnostics.

◆ fill_starting_vector()

template<typename Data_ , class Engine_ >
void powerit::fill_starting_vector ( size_t  order,
Data_ *  vector,
Engine_ &  engine 
)
Template Parameters
Data_Floating-point type for the data.
Engine_Any C++11-compliant random number generator class.
Parameters
orderLength of the array in vector.
[out]vectorPointer to an array of length order. On output, this will be filled with draws from a standard normal distribution.
engineInstance of the random number generator.

◆ parallelize()

template<typename Task_ , class Run_ >
void powerit::parallelize ( int  num_workers,
Task_  num_tasks,
Run_  run_task_range 
)
Template Parameters
Task_Integer type for the number of tasks.
Run_Function to execute a range of tasks.
Parameters
num_workersNumber of workers.
num_tasksNumber of tasks.
run_task_rangeFunction to iterate over a range of tasks within a worker.

By default, this is an alias to subpar::parallelize_range(). However, if the POWERIT_CUSTOM_PARALLEL function-like macro is defined, it is called instead. Any user-defined macro should accept the same arguments as subpar::parallelize_range().