📄 functions.cpp
字号:
//Copyright (c) 2004-2005, Baris Sumengen
//All rights reserved.
//
// CIMPL Matrix Performance Library
//
//Redistribution and use in source and binary
//forms, with or without modification, are
//permitted provided that the following
//conditions are met:
//
// * No commercial use is allowed.
// This software can only be used
// for non-commercial purposes. This
// distribution is mainly intended for
// academic research and teaching.
// * Redistributions of source code must
// retain the above copyright notice, this
// list of conditions and the following
// disclaimer.
// * Redistributions of binary form must
// mention the above copyright notice, this
// list of conditions and the following
// disclaimer in a clearly visible part
// in associated product manual,
// readme, and web site of the redistributed
// software.
// * Redistributions in binary form must
// reproduce the above copyright notice,
// this list of conditions and the
// following disclaimer in the
// documentation and/or other materials
// provided with the distribution.
// * The name of Baris Sumengen may not be
// used to endorse or promote products
// derived from this software without
// specific prior written permission.
//
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
//HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
//EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
//NOT LIMITED TO, THE IMPLIED WARRANTIES OF
//MERCHANTABILITY AND FITNESS FOR A PARTICULAR
//PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
//CONTRIBUTORS BE LIABLE FOR ANY
//DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
//EXEMPLARY, OR CONSEQUENTIAL DAMAGES
//(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
//OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
//DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
//HOWEVER CAUSED AND ON ANY THEORY OF
//LIABILITY, WHETHER IN CONTRACT, STRICT
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
//OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
//OF THIS SOFTWARE, EVEN IF ADVISED OF THE
//POSSIBILITY OF SUCH DAMAGE.
#include "./Functions.h"
#include "mkl_vml.h"
namespace MathCore
{
// Inverts elements
Vector<float> Inv(Vector<float>& m)
{
Vector<float> temp(m.Length());
vsInv(m.Length(), m.Data(), temp.Data());
return temp;
}
Vector<double> Inv(Vector<double>& m)
{
Vector<double> temp(m.Length());
vdInv(m.Length(), m.Data(), temp.Data());
return temp;
}
Matrix<float> Inv(Matrix<float>& m)
{
Matrix<float> temp(m.Rows(), m.Columns());
vsInv(m.Length(), m.Data(), temp.Data());
return temp;
}
Matrix<double> Inv(Matrix<double>& m)
{
Matrix<double> temp(m.Rows(), m.Columns());
vdInv(m.Length(), m.Data(), temp.Data());
return temp;
}
Vector<float>& InvI(Vector<float>& m)
{
vsInv(m.Length(), m.Data(), m.Data());
return m;
}
Vector<double>& InvI(Vector<double>& m)
{
vdInv(m.Length(), m.Data(), m.Data());
return m;
}
Matrix<float>& InvI(Matrix<float>& m)
{
vsInv(m.Length(), m.Data(), m.Data());
return m;
}
Matrix<double>& InvI(Matrix<double>& m)
{
vdInv(m.Length(), m.Data(), m.Data());
return m;
}
// Division of elements
Vector<float> Div(Vector<float>& m1, Vector<float>& m2)
{
if(m1.Length() != m2.Length())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Vector lengths are not the same!");
}
Vector<float> temp(m1.Length());
vsDiv(m1.Length(), m1.Data(), m2.Data(), temp.Data());
return temp;
}
Vector<double> Div(Vector<double>& m1, Vector<double>& m2)
{
if(m1.Length() != m2.Length())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Vector lengths are not the same!");
}
Vector<double> temp(m1.Length());
vdDiv(m1.Length(), m1.Data(), m2.Data(), temp.Data());
return temp;
}
Matrix<float> Div(Matrix<float>& m1, Matrix<float>& m2)
{
if(m1.Rows() != m2.Rows() || m1.Columns() != m2.Columns())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix dimensions does not match!");
}
Matrix<float> temp(m1.Rows(), m1.Columns());
vsDiv(m1.Length(), m1.Data(), m2.Data(), temp.Data());
return temp;
}
Matrix<double> Div(Matrix<double>& m1, Matrix<double>& m2)
{
if(m1.Rows() != m2.Rows() || m1.Columns() != m2.Columns())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix dimensions does not match!");
}
Matrix<double> temp(m1.Rows(), m1.Columns());
vdDiv(m1.Length(), m1.Data(), m2.Data(), temp.Data());
return temp;
}
Vector<float>& DivI(Vector<float>& m1, Vector<float>& m2)
{
if(m1.Length() != m2.Length())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Vector lengths are not the same!");
}
vsDiv(m1.Length(), m1.Data(), m2.Data(), m1.Data());
return m1;
}
Vector<double>& DivI(Vector<double>& m1, Vector<double>& m2)
{
if(m1.Length() != m2.Length())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Vector lengths are not the same!");
}
vdDiv(m1.Length(), m1.Data(), m2.Data(), m1.Data());
return m1;
}
Matrix<float>& DivI(Matrix<float>& m1, Matrix<float>& m2)
{
if(m1.Rows() != m2.Rows() || m1.Columns() != m2.Columns())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix dimensions does not match!");
}
vsDiv(m1.Length(), m1.Data(), m2.Data(), m1.Data());
return m1;
}
Matrix<double>& DivI(Matrix<double>& m1, Matrix<double>& m2)
{
if(m1.Rows() != m2.Rows() || m1.Columns() != m2.Columns())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix dimensions does not match!");
}
vdDiv(m1.Length(), m1.Data(), m2.Data(), m1.Data());
return m1;
}
// Square root of elements
Vector<float> Sqrt(Vector<float>& m)
{
Vector<float> temp(m.Length());
vsSqrt(m.Length(), m.Data(), temp.Data());
return temp;
}
Vector<double> Sqrt(Vector<double>& m)
{
Vector<double> temp(m.Length());
vdSqrt(m.Length(), m.Data(), temp.Data());
return temp;
}
Matrix<float> Sqrt(Matrix<float>& m)
{
Matrix<float> temp(m.Rows(), m.Columns());
vsSqrt(m.Length(), m.Data(), temp.Data());
return temp;
}
Matrix<double> Sqrt(Matrix<double>& m)
{
Matrix<double> temp(m.Rows(), m.Columns());
vdSqrt(m.Length(), m.Data(), temp.Data());
return temp;
}
Vector<float>& SqrtI(Vector<float>& m)
{
vsSqrt(m.Length(), m.Data(), m.Data());
return m;
}
Vector<double>& SqrtI(Vector<double>& m)
{
vdSqrt(m.Length(), m.Data(), m.Data());
return m;
}
Matrix<float>& SqrtI(Matrix<float>& m)
{
vsSqrt(m.Length(), m.Data(), m.Data());
return m;
}
Matrix<double>& SqrtI(Matrix<double>& m)
{
vdSqrt(m.Length(), m.Data(), m.Data());
return m;
}
// Inverse Square root of elements
Vector<float> InvSqrt(Vector<float>& m)
{
Vector<float> temp(m.Length());
vsInvSqrt(m.Length(), m.Data(), temp.Data());
return temp;
}
Vector<double> InvSqrt(Vector<double>& m)
{
Vector<double> temp(m.Length());
vdInvSqrt(m.Length(), m.Data(), temp.Data());
return temp;
}
Matrix<float> InvSqrt(Matrix<float>& m)
{
Matrix<float> temp(m.Rows(), m.Columns());
vsInvSqrt(m.Length(), m.Data(), temp.Data());
return temp;
}
Matrix<double> InvSqrt(Matrix<double>& m)
{
Matrix<double> temp(m.Rows(), m.Columns());
vdInvSqrt(m.Length(), m.Data(), temp.Data());
return temp;
}
Vector<float>& InvSqrtI(Vector<float>& m)
{
vsInvSqrt(m.Length(), m.Data(), m.Data());
return m;
}
Vector<double>& InvSqrtI(Vector<double>& m)
{
vdInvSqrt(m.Length(), m.Data(), m.Data());
return m;
}
Matrix<float>& InvSqrtI(Matrix<float>& m)
{
vsInvSqrt(m.Length(), m.Data(), m.Data());
return m;
}
Matrix<double>& InvSqrtI(Matrix<double>& m)
{
vdInvSqrt(m.Length(), m.Data(), m.Data());
return m;
}
// Cube root of elements
Vector<float> Cbrt(Vector<float>& m)
{
Vector<float> temp(m.Length());
vsCbrt(m.Length(), m.Data(), temp.Data());
return temp;
}
Vector<double> Cbrt(Vector<double>& m)
{
Vector<double> temp(m.Length());
vdCbrt(m.Length(), m.Data(), temp.Data());
return temp;
}
Matrix<float> Cbrt(Matrix<float>& m)
{
Matrix<float> temp(m.Rows(), m.Columns());
vsCbrt(m.Length(), m.Data(), temp.Data());
return temp;
}
Matrix<double> Cbrt(Matrix<double>& m)
{
Matrix<double> temp(m.Rows(), m.Columns());
vdCbrt(m.Length(), m.Data(), temp.Data());
return temp;
}
Vector<float>& CbrtI(Vector<float>& m)
{
vsCbrt(m.Length(), m.Data(), m.Data());
return m;
}
Vector<double>& CbrtI(Vector<double>& m)
{
vdCbrt(m.Length(), m.Data(), m.Data());
return m;
}
Matrix<float>& CbrtI(Matrix<float>& m)
{
vsCbrt(m.Length(), m.Data(), m.Data());
return m;
}
Matrix<double>& CbrtI(Matrix<double>& m)
{
vdCbrt(m.Length(), m.Data(), m.Data());
return m;
}
// Cube root of elements
Vector<float> InvCbrt(Vector<float>& m)
{
Vector<float> temp(m.Length());
vsInvCbrt(m.Length(), m.Data(), temp.Data());
return temp;
}
Vector<double> InvCbrt(Vector<double>& m)
{
Vector<double> temp(m.Length());
vdInvCbrt(m.Length(), m.Data(), temp.Data());
return temp;
}
Matrix<float> InvCbrt(Matrix<float>& m)
{
Matrix<float> temp(m.Rows(), m.Columns());
vsInvCbrt(m.Length(), m.Data(), temp.Data());
return temp;
}
Matrix<double> InvCbrt(Matrix<double>& m)
{
Matrix<double> temp(m.Rows(), m.Columns());
vdInvCbrt(m.Length(), m.Data(), temp.Data());
return temp;
}
Vector<float>& InvCbrtI(Vector<float>& m)
{
vsInvCbrt(m.Length(), m.Data(), m.Data());
return m;
}
Vector<double>& InvCbrtI(Vector<double>& m)
{
vdInvCbrt(m.Length(), m.Data(), m.Data());
return m;
}
Matrix<float>& InvCbrtI(Matrix<float>& m)
{
vsInvCbrt(m.Length(), m.Data(), m.Data());
return m;
}
Matrix<double>& InvCbrtI(Matrix<double>& m)
{
vdInvCbrt(m.Length(), m.Data(), m.Data());
return m;
}
// Pow of elements
Vector<float> Pow(Vector<float>& m1, Vector<float>& m2)
{
if(m1.Length() != m2.Length())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Vector lengths are not the same!");
}
Vector<float> temp(m1.Length());
vsPow(m1.Length(), m1.Data(), m2.Data(), temp.Data());
return temp;
}
Vector<double> Pow(Vector<double>& m1, Vector<double>& m2)
{
if(m1.Length() != m2.Length())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Vector lengths are not the same!");
}
Vector<double> temp(m1.Length());
vdPow(m1.Length(), m1.Data(), m2.Data(), temp.Data());
return temp;
}
Matrix<float> Pow(Matrix<float>& m1, Matrix<float>& m2)
{
if(m1.Rows() != m2.Rows() || m1.Columns() != m2.Columns())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix dimensions does not match!");
}
Matrix<float> temp(m1.Rows(), m1.Columns());
vsPow(m1.Length(), m1.Data(), m2.Data(), temp.Data());
return temp;
}
Matrix<double> Pow(Matrix<double>& m1, Matrix<double>& m2)
{
if(m1.Rows() != m2.Rows() || m1.Columns() != m2.Columns())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix dimensions does not match!");
}
Matrix<double> temp(m1.Rows(), m1.Columns());
vdPow(m1.Length(), m1.Data(), m2.Data(), temp.Data());
return temp;
}
Vector<float>& PowI(Vector<float>& m1, Vector<float>& m2)
{
if(m1.Length() != m2.Length())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Vector lengths are not the same!");
}
vsPow(m1.Length(), m1.Data(), m2.Data(), m1.Data());
return m1;
}
Vector<double>& PowI(Vector<double>& m1, Vector<double>& m2)
{
if(m1.Length() != m2.Length())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Vector lengths are not the same!");
}
vdPow(m1.Length(), m1.Data(), m2.Data(), m1.Data());
return m1;
}
Matrix<float>& PowI(Matrix<float>& m1, Matrix<float>& m2)
{
if(m1.Rows() != m2.Rows() || m1.Columns() != m2.Columns())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix dimensions does not match!");
}
vsPow(m1.Length(), m1.Data(), m2.Data(), m1.Data());
return m1;
}
Matrix<double>& PowI(Matrix<double>& m1, Matrix<double>& m2)
{
if(m1.Rows() != m2.Rows() || m1.Columns() != m2.Columns())
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("Matrix dimensions does not match!");
}
vdPow(m1.Length(), m1.Data(), m2.Data(), m1.Data());
return m1;
}
// Pow of vector elements to a constant
Vector<float> Powx(Vector<float>& m1, const float m2)
{
Vector<float> temp(m1.Length());
vsPowx(m1.Length(), m1.Data(), m2, temp.Data());
return temp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -