Skip to content

Commit

Permalink
Add main page README and improve doxygen for Tensor a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanwm committed Jul 6, 2024
1 parent a6ad759 commit 360c1a2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# nuTens

A lightweight library for calculating neutrino oscillation probabilities using tensors typically used in machine learning.
4 changes: 2 additions & 2 deletions doc/doxygen.config
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

INPUT = ../nuTens
INPUT = ../nuTens ../README.md

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down Expand Up @@ -1022,7 +1022,7 @@ FILTER_SOURCE_PATTERNS =
# (index.html). This can be useful if you have a project on for instance GitHub
# and want to reuse the introduction page also for the doxygen output.

USE_MDFILE_AS_MAINPAGE =
USE_MDFILE_AS_MAINPAGE = ../README.md

#---------------------------------------------------------------------------
# Configuration options related to source browsing
Expand Down
45 changes: 45 additions & 0 deletions nuTens/tensors/tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@

class Tensor{

/*!
* @class Tensor
* @brief Basic tensor class
*
* Tensor defines a basic interface for creating and manipulating tensors.
* To create tensors you should use the Initialisers. These can be used on their own or chained together with the Setters to create the desired tensor.
*
* For example
* \code{.cpp}
* Tensor t;
* t.ones({3,3}).dType(NTdtypes::kFloat).device(NTdtypes::kGPU);
* \endcode
* will get you a 3x3 tensor of floats that lives on the GPU.
* This is equivalent to
* \code{.cpp}
* Tensor t;
* t.ones({3,3}, NTdtypes::kFloat, NTdtypes::kGPU);
* \endcode
*/

public:
/// @name Initialisers
/// Use these methods to initialise the tensor
Expand All @@ -20,19 +40,27 @@ class Tensor{
/// @arg length The length of the intitalised tensor
/// @arg type The data type of the initialised tensor
Tensor& ones(int length, NTdtypes::scalarType type, NTdtypes::deviceType device = NTdtypes::kCPU, bool requiresGrad = true);
/// @brief Initialise this tensor with ones
/// @arg shape The desired shape of the intitalised tensor
/// @arg type The data type of the initialised tensor
Tensor& ones(const std::vector<long int> &shape, NTdtypes::scalarType type, NTdtypes::deviceType device = NTdtypes::kCPU, bool requiresGrad = true);

/// @brief Initialise this tensor with zeros
/// @arg length The length of the intitalised tensor
/// @arg type The data type of the initialised tensor
Tensor &zeros(int length, NTdtypes::scalarType type, NTdtypes::deviceType device = NTdtypes::kCPU, bool requiresGrad = true);
/// @brief Initialise this tensor with zeros
/// @arg shape The desired shape of the intitalised tensor
/// @arg type The data type of the initialised tensor
Tensor &zeros(const std::vector<long int> &shape, NTdtypes::scalarType type, NTdtypes::deviceType device = NTdtypes::kCPU, bool requiresGrad = true);

/// @}

/// @name Setters
/// @{
/// @brief Set the underlying data type of this tensor
Tensor& dType(NTdtypes::scalarType type);
/// @brief Set the device that this tensor lives on
Tensor& device(NTdtypes::deviceType device);
/// @}

Expand All @@ -44,11 +72,28 @@ class Tensor{
/// @arg t1 Left hand tensor
/// @arg t2 Right hand tensor
static Tensor matmul(const Tensor &t1, const Tensor &t2);

/// @brief Scale a matrix by some scalar
/// @arg s The scalar
/// @arg t The tensor
static Tensor scale(float s, const Tensor &t);
/// @brief Scale a matrix by some complex scalar
/// @arg s The scalar
/// @arg t The tensor
static Tensor scale(std::complex<float> s, const Tensor &t);

/// @brief Inline matrix multiplication
/// @arg t2 Right hand matrix to multiply with this one
void matmul_(const Tensor &t2);


/// @brief Inline matrix scaling
/// @arg s The scalar
void scale_(float s);
/// @brief Inline complex matrix scaling
/// @arg s The scalar
void scale_(std::complex<float> s);

/// @}

/// @name Mathematical
Expand Down

0 comments on commit 360c1a2

Please sign in to comment.