Util

namespace calculation

Functions

inline void matrix_mult(double *mat_a, double *mat_b, int rows_a, int cols_a, int rows_b, int cols_b, double *rslt_mat)

Multiplies two matrices of arbitrary sizes and stores the result.

Performs classic matrix multiplication using pointer arithmetic.

Parameters:
  • mat_a – First matrix (row-major).

  • mat_b – Second matrix (row-major).

  • rows_a – Number of rows in first matrix.

  • cols_a – Number of columns in first matrix.

  • rows_b – Number of rows in second matrix.

  • cols_b – Number of columns in second matrix.

  • rslt_mat – Result matrix to store the output.

inline void scalar_vector_mult(double *vector, double scalar, int size, double *rslt_vec)

Multiplies each element of a vector with a scalar value.

Parameters:
  • vector – Input vector.

  • scalar – Scalar multiplier.

  • size – Number of elements.

  • rslt_vec – Output vector to store the result.

inline double dot_product_parray(const double *a, const double *b, int size)

Calculates the dot product of two arrays of equal size.

Parameters:
  • a – First array.

  • b – Second array.

  • size – Number of elements in both arrays.

Returns:

Scalar dot product.

inline vector<double> cross_product(const vector<double> &a, const vector<double> &b)

Computes the cross product of two 3D vectors.

Parameters:
  • a – First 3D vector.

  • b – Second 3D vector.

Throws:

std::out_of_range – if vector dimensions are not 3.

Returns:

Resultant 3D vector orthogonal to both inputs.

inline double vector_magnitude(const vector<double> &vec)

Computes the magnitude (Euclidean norm) of a 3D vector.

Parameters:

vec – A 3D vector.

Throws:

std::out_of_range – if input vector is not 3D.

Returns:

Magnitude of the vector.

inline vector<double> convolve(vector<double> a, vector<double> v)

Performs discrete convolution between two input vectors.

If the inputs differ in length, the longer one is convolved with the shorter.

Parameters:
  • a – First input vector.

  • v – Second input vector.

Throws:

std::out_of_range – if either vector is empty.

Returns:

Convolved vector.

inline vector<double> arange(double start, double stop, double step)

Generates a vector of evenly spaced values over a specified interval.

Mimics the behavior of Python’s numpy.arange.

Parameters:
  • start – Starting value (inclusive).

  • stop – Stopping value (exclusive).

  • step – Step size.

Returns:

Vector of evenly spaced values.

inline double uniform_real_distribution(double min = 0.0, double max = 1.0)

Generates a random real number within a uniform distribution.

Parameters:
  • min – Minimum bound (inclusive).

  • max – Maximum bound (exclusive).

Returns:

Random real number in the range [min, max).

inline double normal_distribution(double mean, double stddev)

Generates a normally distributed random value.

Parameters:
  • mean – Mean of the distribution.

  • stddev – Standard deviation of the distribution.

Returns:

Random value drawn from the distribution.

inline vector<double> normal_distribution(double mean, double stddev, int size)

Generates a vector of random values from a normal distribution.

Parameters:
  • mean – Mean of the distribution.

  • stddev – Standard deviation.

  • size – Length of the output vector.

Returns:

Vector of normally distributed values.

inline vector<double> random_vector(int size, double factor)

Generates a vector of uniformly distributed random values scaled by a factor.

Parameters:
  • size – Number of elements.

  • factor – Scaling factor applied to each random value.

Returns:

Vector of scaled random values.

inline void normalize_vector(double *vector)

Normalizes a 3D vector in-place to have unit magnitude.

Parameters:

vector – Pointer to an array representing a 3D vector.

inline VectorXd interp_func(const VectorXd &x, const VectorXd &xp, const VectorXd &fp, double left = NAN, double right = NAN)
inline VectorXd interp(const VectorXd &x, const VectorXd &xp, const VectorXd &fp, double left = NAN, double period = NAN, double right = NAN)
inline std::vector<std::vector<double>> transpose(const std::vector<std::vector<double>> &matrix)

Computes the transpose of a 2D matrix.

Parameters:

matrix – Input matrix as a vector of vectors.

Returns:

Transposed matrix.

namespace std
class quaternion
#include <quaternion.hpp>

A utility class for handling 3D rotations using quaternions.

This class encapsulates a quaternion object from the Eigen library, and provides methods to initialize a quaternion from an axis-angle representation, rotate 3D vectors, and retrieve the internal quaternion or its vector part.

Public Functions

inline quaternion(std::vector<double> axis, double angle)

Constructor that initializes the quaternion from an axis-angle representation.

Parameters:
  • axis – A 3-element vector representing the rotation axis.

  • angle – Rotation angle in radians.

inline std::vector<double> rotate(std::vector<double> vector)

Rotates a 3D vector using the stored quaternion.

Applies the rotation to the input vector by quaternion multiplication.

Parameters:

vector – A 3-element vector to be rotated.

Returns:

Rotated vector as a std::vector<double>.

inline Eigen::Vector3d get_vector()

Returns the vector part (imaginary components) of the quaternion.

Returns:

Eigen::Vector3d containing the x, y, z components of the quaternion.

inline Eigen::Quaterniond get_q()

Returns the full Eigen quaternion object.

Returns:

Eigen::Quaterniond object representing the quaternion.

Private Members

Eigen::Quaterniond q
namespace reference_frame_operation

Contains utilities for performing reference frame transformations, especially related to celestial coordinate systems.

Functions

inline std::vector<double> transform2spherical(const std::vector<double> &cartesian_coor)

Converts Cartesian coordinates to spherical coordinates.

Parameters:

cartesian_coor – A 3-element vector [x, y, z].

Returns:

A 3-element vector [radius, declination, azimuth] in degrees.

inline std::vector<double> transform2cartesian(const std::vector<double> &spherical_coor)

Converts spherical coordinates to Cartesian coordinates.

Parameters:

spherical_coor – A 3-element vector [radius, declination, azimuth] in degrees.

Returns:

A 3-element vector [x, y, z] in Cartesian coordinates.

inline Eigen::Vector3d polar2cart(double r, double theta, double phi)

Converts polar coordinates to a 3D Cartesian vector using radians.

Parameters:
  • r – Radius.

  • theta – Polar angle (inclination) in radians.

  • phi – Azimuthal angle in radians.

Returns:

An Eigen::Vector3d representing the Cartesian coordinates.

inline std::vector<Eigen::Vector3d> rotate_reference_frame(const std::vector<Eigen::Vector3d> &frame_0_basis, const Eigen::Vector3d &axis_of_rotation, double rotation_angle)

Rotates a reference frame using a quaternion defined by an axis-angle pair.

Parameters:
  • frame_0_basis – A vector of Eigen::Vector3d representing the initial frame’s basis vectors.

  • axis_of_rotation – The axis around which to rotate the frame.

  • rotation_angle – The rotation angle in radians.

Returns:

A vector of Eigen::Vector3d representing the rotated frame’s basis vectors.

struct rot_frame_basis_vectors
#include <reference_frame_operation.hpp>

Represents basis vectors of a rotated frame and the quaternion used for the transformation.

Public Members

std::vector<std::vector<double>> new_rot_frame_basis = {{}}
std::vector<std::vector<double>> rot_frame_basis = {{}}
quaternion rot_frame_quaternion
struct mag_pole_rot_frame
#include <reference_frame_operation.hpp>

Holds the magnetic pole position in both celestial and rotating frames, in both Cartesian and spherical coordinates.

Public Members

std::vector<double> mag_pol_position_rot_frame_cartesian
std::vector<double> mag_pol_position_celestial_frame_cartesian
std::vector<double> mag_pol_position_rot_frame_spherical
std::vector<double> mag_pol_position_celestial_frame_spherical
std::vector<std::vector<double>> mag_frame_basis_vectors
struct earth_pos_in_pulsar_frame
#include <reference_frame_operation.hpp>

Represents Earth’s position with respect to the pulsar’s rotating reference frame.

Public Members

std::vector<double> earth_rot_frame
std::vector<double> vector_to_earth_dir
std::vector<double> earth_rot_frame_spherical
std::vector<double> vector_to_earth_dir_spherical
struct tuple_vec
#include <structures.hpp>

Holds a pair of 1D vectors for grouped processing or comparison.

Public Functions

inline tuple_vec(std::vector<double> v1, std::vector<double> v2)

Constructs a tuple of two vectors.

Parameters:
  • v1 – First vector (moved).

  • v2 – Second vector (moved).

Public Members

std::vector<double> a
std::vector<double> b
struct params
#include <structures.hpp>

Contains parameters for pulsar signal modeling and simulation, including geometry, emission characteristics, and RFI (Radio Frequency Interference) properties.

Public Members

std::vector<double> rot_phases
std::vector<double> pulsar_celestial_coors = {1, 45, 0}
std::vector<double> pulsar_rotation_axis = {0, 0, 1}
double mag_axis_tilt = 45.0
std::vector<double> conal_azimuths = {0, 90, 180, 270}
std::vector<double> conal_declinations = {25, 25, 25, 25}
std::vector<double> rad_conal = {5, 5, 5, 5}
double rad_core = 5.0
float scintillation_index_homo = .5
std::vector<double> freq_list = {1}
double dm_homogeneous = 1.0
float pulsar_period = 1.0
double T_S = 1.0
float bandwidth = 1.0
float acquisition_time = 1.0
double time_of_occurrence_BBRFI = .5
std::vector<int> channels_effected_rangeBBRFI = {1, 100}
float spread_in_phaseBBRFI = .01
double amplitudeBBRFI = 1.0
float probability_of_occurrence_BBRFI = 0.8
double center_channel_indexNBRFI = 100.0
float spread_in_channelsNBRFI = 10.0
double amplitudeNBRFI = 1.0
float probability_of_occurrence_NBRFI = 0.8