diff --git a/include/tensor/vector.hpp b/include/tensor/vector.hpp index e6d45fb..98785c6 100644 --- a/include/tensor/vector.hpp +++ b/include/tensor/vector.hpp @@ -32,79 +32,165 @@ * *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ #pragma once - +//--------------------------------------------------------------------------------------------------------------------------- +// INCLUDE DESCRIPTION +//--------------------------------------------------------------------------------------------------------------------------- #include // panic::uint_t, panic::int_t, and panic::real_t -//--------------------------------------------------------------------------------------------------------------------------- -// Type Name : panic::tensor::vector -// -// Description: -// Dynamic vector storing panic::real_t values. -// The vector owns its memory and releases it in the destructor. -// -// Member Variables: -// length panic::uint_t -// Number of elements in the vector. -// -// data panic::real_t* -// Pointer to the allocated vector data. -// -// Notes: -// This vector uses dynamic allocation with new[] and delete[]. -// Copying performs a deep copy. -//--------------------------------------------------------------------------------------------------------------------------- namespace panic{ namespace tensor{ + +/** + * @brief struct for vector object + * + * The struct is used for all PANIC libraries + * It uses dynamic allocation with new[] nad delete[]. + * Copying performs a deep copy. + */ template struct vector{ + // Variable to store the length of the data array panic::types::uint_t length; + // Pointer to the data array T* data; - // empty contructor + /** + * @brief Empthy constructor + * + */ vector(); - // contructor with size allocation + /** + * @brief Contructor with size allocation. + * + * @param size Number of elemets in the vector + */ vector(panic::types::uint_t size); - // contructor with size allocation and sets it all to a value + /** + * @brief Contructor with size allocation and sets it all to a value. + * + * @param size Number of elemets in the vector + * @param value all the values in the vactor. + */ vector(panic::types::uint_t size, T value); - // copy-contructor - // vector a(3); - // vector b = a; + /** + * @brief Copy-contructor. + * + * Computes: + * @code + * vector a(3); + * vector b = a; + * @endcode + * + */ vector(const vector& other); - // de-contructor, releases memory + /** + * @brief De-contructor, releases memory. + * + * @note Releases memory. + */ ~vector(); - // copy-assignment - //vector a(5); - //vector b(3); - //b = a; + /** + * @brief Copy-assignment. + * + * Computes: + * @code + * vector a(3); + * vector b(5); + * b = a; + * @endcode + * + */ vector& operator=(const vector& other); - // function returns size. - // const tells compiler that the fuction don't edit the objert. + /** + * @brief Returns number of elements/size. + * + * Computes: + * @code + * m = a.size(); + * @endcode + * + * @note The const tells compiler that the fuction don't edit the objert. + */ panic::types::uint_t size() const; - // function to resize data vector (I need a new that don't save the vlaues) + /** + * @brief Function to resize data vactor. + * + * Computes: + * @code + * a.resize(6); + * @endcode + * + * @note It hold all the privious functions if avaliable. + */ bool resize(panic::types::uint_t new_size); - // fill data with value + /** + * @brief Fill data with value. + * + * Computes: + * @code + * a.fill(3.1415); + * @endcode + * + * @note Sets all values in the vactor. + */ bool fill(T value); - // lets you read and write v[index] + /** + * @brief Read and write vactor data using index + * + * Computes: + * @code + * n = a[3]; + * @endcode + * + * @note This is unchecked and fast. + */ T& operator[](panic::types::uint_t index); - // lets you read v[index] from a const vector + /** + * @brief Read from const vector data using index + * + * Computes: + * @code + * n = const a[3]; + * @endcode + * + * @note This is unchecked and fast. + */ const T& operator[](panic::types::uint_t index) const; - // lets you read and write v.at(index) + /** + * @brief Read and write vactor data using index + * + * Computes: + * @code + * n = a.at(3); + * @endcode + * + * @note This is checked and not fast. + */ T& at(panic::types::uint_t index); - // lets you read v.at(index) from a const vector + /** + * @brief Read from const vector data using index + * + * Computes: + * @code + * n = const a.at(3); + * @endcode + * + * @note This is checked and not fast. + */ const T& at(panic::types::uint_t index) const; }; @@ -130,12 +216,6 @@ extern template struct vector; } // namespace tensor } // namespace panic -//--------------------------------------------------------------------------------------------------------------------------- -// VARIABLE DESCRIPTION -//--------------------------------------------------------------------------------------------------------------------------- -//--------------------------------------------------------------------------------------------------------------------------- -// FUNCTION PROTOTYPE -//--------------------------------------------------------------------------------------------------------------------------- diff --git a/src/tensor/matrix.cpp b/src/tensor/matrix.cpp index ef1b214..26cf821 100644 --- a/src/tensor/matrix.cpp +++ b/src/tensor/matrix.cpp @@ -36,7 +36,7 @@ // INCLUDE DESCRIPTION //--------------------------------------------------------------------------------------------------------------------------- #include -#include // panic::uint_t, panic::int_t, and panic::real_t +#include #include //--------------------------------------------------------------------------------------------------------------------------- diff --git a/src/tensor/vector.cpp b/src/tensor/vector.cpp index 4e79961..0c117ed 100644 --- a/src/tensor/vector.cpp +++ b/src/tensor/vector.cpp @@ -36,19 +36,18 @@ // INCLUDE DESCRIPTION //--------------------------------------------------------------------------------------------------------------------------- #include +#include #include //--------------------------------------------------------------------------------------------------------------------------- -// DEFINE DESCRIPTION -//--------------------------------------------------------------------------------------------------------------------------- - -//--------------------------------------------------------------------------------------------------------------------------- -// TYPE DESCRIPTION -//--------------------------------------------------------------------------------------------------------------------------- - -//--------------------------------------------------------------------------------------------------------------------------- -// VARIABLE DESCRIPTION +// PRIVATE CONSTANTS //--------------------------------------------------------------------------------------------------------------------------- +/** + * @brief Minimum number of element operations before using the OpenMP-enabled loop. + * + * Small vectors and matrices are kept serial because the overhead of starting + * worker threads can be larger than the work itself. + */ static const panic::types::uint_t vector_omp_min_size = 10000; //--------------------------------------------------------------------------------------------------------------------------- @@ -160,10 +159,7 @@ vector::~vector(){ // Function Name : panic::tensor::vector::operator= // // Description: -// Copy-assignment. Copies from another vector like this: -// vector a(5); -// vector b(3); -// b = a; +// Copy-assignment. Copies from another vector. //-------------------------------------------------------------------------------------------------------------------------- template vector& vector::operator=(const vector& other){ @@ -315,7 +311,6 @@ const T& vector::at(panic::types::uint_t index) const{ } - //--------------------------------------------------------------------------------------------------------------------------- // EXPLICIT TEMPLATE INSTANTIATION //---------------------------------------------------------------------------------------------------------------------------