Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Easy-to-use Scientific Computing library in/for C++ available for Linux and Windows.

License

NotificationsYou must be signed in to change notification settings

mlcpp/Matrix

Join the chat at https://gitter.im/mlcpp/Matrix

Table of Contents

  1. Installation

  2. Development

    2.1.Linux

    2.2.Windows

  3. Benchmarking

  4. Testing

  5. Quick Start Guide

    5.1.Initializers

    5.2.Slicing

    5.3.Printing/Viewing

    5.4.Indexing

    5.5.Operators

    5.6.Broadcasting

    5.7.Minimum, Maximum

    5.8.Mathematical Operations

    5.9.Statistical Operations

    5.10.Matrix Algebra

    5.11.Miscellaneous

Installation

This describes the installation process using cmake. As pre-requisites, you'llneed git and cmake installed.

# Check out the library.$ git clone https://github.com/mlcpp/Matrix.git&&cd Matrix# Make a build directory to place the build output.$ cmake -E make_directory"build"# Generate build system files with cmake.$ cmake -E chdir"build" cmake -DCMAKE_BUILD_TYPE=Release ../# Build the library.$ cmake -DCMAKE_BUILD_TYPE=Release -S. -B"build"

On a unix system, the build directory should now look something like this:

/Matrix  /build    /examples      /abs      /addition      ...

Development

Linux

Prerequisites

  1. C++ compiler (gcc or clang)
  2. git
  3. clang-format
  4. make (for Makefiles)
  5. cmake (version 3.13 or higher)
# Check out the library.$ git clone https://github.com/mlcpp/Matrix.git&&cd Matrix# Create build directory.$ mkdir build# Enter into build directory.$cd build# Run CMake. This step will generate a Makefile in the build/ folder.$ cmake ../# Compile all files and place the binaries inside build/examples/ folder.$ make# Compile single file and place the binary inside build/examples/ folder.$ make<file_name_without_extension>

Windows

Prerequisites

  1. C++ compiler (mingw-gcc)
  2. git (msysgit)
  3. clang-format
  4. mingw-make or mingw32-make (for Makefiles)
  5. cmake (version 3.13 or higher)

Add these tools to PATH.

Note: Run the following commands in msysgit terminal.

# Check out the library.$ git clone https://github.com/mlcpp/Matrix.git&&cd Matrix# Create build directory.$ mkdir build# Enter into build directory.$cd build# Run CMake. This step will generate a Makefile in the build/ folder.$ cmake ../# Compile all files and place the binaries inside build/examples/ folder.$ mingw-make# use mingw32-make if using 32-bit Windows# Compile single file and place the binary inside build/examples/ folder.$ mingw-make<file_name_without_extension># use mingw32-make if using 32-bit Windows

Benchmarking

To compile g_benchmark binaries:

Linux:make benchmarks

Windows:mingw32-make benchmarks

Testing

To compile g_test binaries:

Linux:make tests

Windows:mingw32-make tests

Quick Start Guide

This guide contains detailed explanation of all the methods and functions available and how to use them.

More detailed information about how to use these methods and functions is available in/examples.

Note: Hered-type means any C++ data type.

Initializers

Many initializer functions are provided that returnMatrix object.

FunctionParametersReturn valueDescription
matrix.init()

1 Parameter:
Type:d-type/std::vector<d-type>/std::vector<std::vector<d-type>>/std::vector<std::vector<std::string>>
Job: value(s) of elements in theMatrix object

Matrix objectCreates aMatrix object of same dimensions and values as provided in the parameter.
matrix.eye()

1 Parameter:
Type:int
Job: Size of the identity matrix

Matrix objectCreates an identityMatrix object of the size given as parameters.
matrix.zeros()

2 Parameters:
Type:int;int
Job: Number of rows; Number of columns

Matrix objectCreates aMatrix object of all elements0 of the size given as parameters.
matrix.ones()

2 Parameters:
Type:int;int
Job: Number of rows; Number of columns

Matrix objectCreates aMatrix object of all elements1 of the size given as parameters.
matrix.genfromtxt()

2 Parameters:
Type:std::string;char
Job: Path of the.csv file

Matrix objectCreates aMatrix object with data elements as in the given file.

Slicing

Matrix objects can be sliced likeNumPy arrays.

FunctionParametersReturn valueDescription
Matrix.slice()

4 Parameter:
Type:int;int;int;int
Job: Starting row index; Ending row index; Starting column index; Ending column index

Matrix objectSlices theMatrix object according to the indices provided.
Matrix.slice_select()

4 Parameter:
Type:Matrix<d-type1>;Matrix<d-type2>;d-type2;int
Job:Matrix to select values on;Matrix to select values from; value to select; column index on which to select

Matrix objectSlices theMatrix object to get all rows which have value(3rd parameter) in secondMatrix object and one column(4th parameter)

Printing/Viewing

A number of methods are provided to print/view aMatrix object in different ways.

FunctionParametersReturn valueDescription
Matrix.print()

0 Parameters

voidPrints the wholeMatrix object onto the console.
Matrix.head()

0 Parameters

voidPrints first 5 rows of theMatrix object onto the console.
Matrix.tail()

0 Parameters

voidPrints first 5 rows of theMatrix object onto the console.
Matrix.view()

2 Parameters:
Type:int;int
Job: row index; column index

voidPrints the value on the provided index.
Matrix.view()

4 Parameters:
Type:int;int;int;int
ob: Starting row index; Ending row index; Starting column index; Ending column index

voidPrints theMatrix object according to the indices provided.

Indexing

Indexing can be used to get or assign value to a particular element.

For example, let there is aMatrix object named mat. If we want to get the value at index (5,3) we can do this as follows:

double val = mat(5,3);

Similarly, if we want to assign the value to index (5,3) we can do this by:

mat(5,3) = 10.54;

Operators

Support for almost all standard C++ operators is provided. This includes:

  • Arithmetic operators (+, -, \*, /)
  • Compound assignment operatos (+=, -=, \*=, /=)
  • Increment and decrement operators (++, --)
  • Relational and Comparison operators (==, !=, <, >, <=, >=)
  • Unary Minus (-)

Broadcasting

Broadcasting is in-built in the Basic Mathematical operations i.e., addition, subtraction, multiplication and division.

Following binary operations are possible:

  • Matrix = Matrix @ Matrix
  • Matrix = Matrix @ Vector
  • Matrix = Matrix @ Scalar

where, @ is any operator from (+, -, *, /)

Note: Vector is aMatrix object where row lengthor column length is equal to 1.

Following unary operations are possible:

  • Matrix = @Matrix

where, @ is any operator from (-)

Minimum, Maximum

FunctionParametersReturn valueDescription
matrix.min()

2 Parameters:
Type:Matrix;std::string
Job:Matrix to find minimum; dimension across which to find minimum

Matrix objectMethod to get the minimum value along an axis
matrix.max()

2 Parameters:
Type:Matrix;std::string
Job:Matrix to find maximum; dimension across which to find maximum

Matrix objectMethod to get the maximum value along an axis
matrix.argmin()

2 Parameters:
Type:Matrix;std::string
Job:Matrix to find index of minimum; dimension across which to find index of minimum

Matrix objectMethod to get the index of minimum value along an axis
matrix.argmax()

2 Parameters:
Type:Matrix;std::string
Job:Matrix to find index of maximum; dimension across which to find index of maximum

Matrix objectMethod to get the index of maximum value along an axis

Mathematical Operations

FunctionParametersReturn valueDescription
matrix.sqrt()

1 Parameter:
Type:Matrix
Job:Matrix object to apply method on

Matrix objectMethod to get the sqrt of each element of aMatrix object
matrix.power()

2 Parameters:
Type:Matrix;double
Job:Matrix object to apply method on; power ofMatrix elements

Matrix objectMethod to calculate power of each element of aMatrix object
matrix.power()

2 Parameters:
Type:Matrix;Matrix
Job:Matrix object to apply method on; power ofMatrix elements

Matrix objectMethod to calculate power of each element of aMatrix object
matrix.exp()

1 Parameter:
Type:Matrix
Job:Matrix object to apply method on

Matrix objectMethod to calculate exponential of all elements in theMatrix object
matrix.log()

1 Parameter:
Type:Matrix
Job:Matrix object to apply method on

Matrix objectMethod to calculate natural logarithm of all elements in the in theMatrix object
matrix.abs()

1 Parameter:
Type:Matrix
Job:Matrix object to apply method on

Matrix objectMethod to get absolute value of all elements in the in theMatrix object

Note: Broadcasting in power() methods works in the same way as in Basic Mathematical operations.

Statistical Operations

FunctionParametersReturn valueDescription
matrix.sum()

2 Parameters:
Type:Matrix;std::string
Job:Matrix object to apply method on; Dimension on which to calculate sum

Matrix objectMethod to calculate the sum over an axis of aMatrix object
matrix.mean()

2 Parameters:
Type:Matrix;std::string
Job:Matrix object to apply method on; Dimension on which to calculate mean

Matrix objectMethod to calculate the mean over an axis of aMatrix object
matrix.std()

2 Parameters:
Type:Matrix;std::string
Job:Matrix object to apply method on; Dimension on which to calculate standard deviation

Matrix objectMethod to calculate the standard deviation over an axis of aMatrix object

Matrix Algebra

FunctionParametersReturn valueDescription
Matrix.transpose()

0 Parameters

Matrix objectMethod to return the Tranpose of aMatrix object
matrix.matmul()

2 Parameters:
Type:Matrix;Matrix
Job: FirstMatrix for matrix multiplication; SecondMatrix for matrix multiplication

Matrix objectMethod to calculate matrix multiplication
matrix.determinant()

2 Parameters:
Type:Matrix;int
Job:Matrix object to calculate determinant of; Size of theMatrix object

doubleMethod to calculate the Determinant of aMatrix object
matrix.inverse()

1 Parameter:
Type:Matrix
Job:Matrix object to calculate inverse of

Matrix objectMethod to calculate the Inverse of aMatrix object

Miscellaneous

FunctionParametersReturn valueDescription
matrix.concatenate()

3 Parameters:
Type:Matrix;Matrix;std::string
Job:Matrix to concatenate on;Matrix which is to be concatenated; Dimension on which to concatenate

Matrix objectMethod to concatenate/join twoMatrix objects
Matrix.get()

0 Parameters

std::vector<std::vector<d-type>>Method to get theMatrix object as a 2D vector
Matrix.get_row()

1 Parameter:
Type:int
Job: row index

std::vector<d-type>Method to get a row of aMatrix object in the form of a vector
Matrix.get_col()

1 Parameter:
Type:int
Job: column index

std::vector<d-type>Method to get a column of aMatrix object in the form of a vector
matrix.delete_()

3 Parameters:
Type:Matrix;int;std::string
Job:Matrix to delete row/column of; index to be deleted; Dimension on which to delete

Matrix objectMethod to delete a row or column of aMatrix object
matrix.reciprocal()

1 Parameter:
Type:Matrix
Job:Matrix object to apply method on

Matrix objectMethod to calculate reciprocal of all elements in theMatrix object
Matrix.row_length()

0 Parameters

intMethod to get the number of rows in aMatrix object
Matrix.col_length()

0 Parameters

intMethod to get the number of columns in aMatrix object

About

Easy-to-use Scientific Computing library in/for C++ available for Linux and Windows.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

    Contributors7


    [8]ページ先頭

    ©2009-2025 Movatter.jp