Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34aaf11
commit c19c9bd
Showing
11 changed files
with
278 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//============================================================================= | ||
// Copyright (c) 2016-present Allan CORNET (Nelson) | ||
//============================================================================= | ||
// This file is part of the Nelson. | ||
//============================================================================= | ||
// LICENCE_BLOCK_BEGIN | ||
// This program is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// | ||
// Alternatively, you can redistribute it and/or | ||
// modify it under the terms of the GNU General Public License as | ||
// published by the Free Software Foundation; either version 2 of | ||
// the License, or (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public | ||
// License along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// LICENCE_BLOCK_END | ||
//============================================================================= | ||
#include "betaincBuiltin.hpp" | ||
#include "Error.hpp" | ||
#include "BetaIncomplete.hpp" | ||
#include "OverloadFunction.hpp" | ||
#include "ClassName.hpp" | ||
//============================================================================= | ||
using namespace Nelson; | ||
//============================================================================= | ||
ArrayOfVector | ||
Nelson::SpecialFunctionsGateway::betaincBuiltin(Evaluator* eval, int nLhs, const ArrayOfVector& argIn) | ||
{ | ||
ArrayOfVector retval; | ||
if (argIn.size() != 3) { | ||
Error(ERROR_WRONG_NUMBERS_INPUT_ARGS); | ||
} | ||
if (nLhs > 1) { | ||
Error(ERROR_WRONG_NUMBERS_OUTPUT_ARGS); | ||
} | ||
bool bSuccess = false; | ||
if (eval->mustOverloadBasicTypes()) { | ||
retval = OverloadFunction(eval, nLhs, argIn, "betainc", bSuccess); | ||
} | ||
if (!bSuccess) { | ||
bool needToOverload = false; | ||
retval.push_back(BetaIncomplete(argIn[0], argIn[1], argIn[2], needToOverload)); | ||
if (needToOverload) { | ||
retval = OverloadFunction(eval, nLhs, argIn, "betainc"); | ||
} | ||
} | ||
return retval; | ||
} | ||
//============================================================================= |
38 changes: 38 additions & 0 deletions
38
modules/special_functions/builtin/include/betaincBuiltin.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//============================================================================= | ||
// Copyright (c) 2016-present Allan CORNET (Nelson) | ||
//============================================================================= | ||
// This file is part of the Nelson. | ||
//============================================================================= | ||
// LICENCE_BLOCK_BEGIN | ||
// This program is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// | ||
// Alternatively, you can redistribute it and/or | ||
// modify it under the terms of the GNU General Public License as | ||
// published by the Free Software Foundation; either version 2 of | ||
// the License, or (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public | ||
// License along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// LICENCE_BLOCK_END | ||
//============================================================================= | ||
#pragma once | ||
//============================================================================= | ||
#include "ArrayOf.hpp" | ||
#include "Evaluator.hpp" | ||
//============================================================================= | ||
namespace Nelson { | ||
namespace SpecialFunctionsGateway { | ||
ArrayOfVector | ||
betaincBuiltin(Evaluator* eval, int nLhs, const ArrayOfVector& argIn); | ||
} | ||
//============================================================================= | ||
} // namespace Nelson | ||
//============================================================================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
//============================================================================= | ||
// Copyright (c) 2016-present Allan CORNET (Nelson) | ||
//============================================================================= | ||
// This file is part of the Nelson. | ||
//============================================================================= | ||
// LICENCE_BLOCK_BEGIN | ||
// This program is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// | ||
// Alternatively, you can redistribute it and/or | ||
// modify it under the terms of the GNU General Public License as | ||
// published by the Free Software Foundation; either version 2 of | ||
// the License, or (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public | ||
// License along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// LICENCE_BLOCK_END | ||
//============================================================================= | ||
#include <boost/math/special_functions/beta.hpp> | ||
#include "nlsConfig.h" | ||
#include "BetaIncomplete.hpp" | ||
#include "Error.hpp" | ||
//============================================================================= | ||
namespace Nelson { | ||
//============================================================================= | ||
inline Dimensions | ||
maxDimensions(Dimensions& a, Dimensions& b) | ||
{ | ||
Dimensions ret; | ||
for (unsigned int i = 0; i < std::min(a.getLength(), b.getLength()); i++) { | ||
ret[i] = (a.getAt(i, false) > b.getAt(i, false)) ? a.getAt(i, false) : b.getAt(i, false); | ||
} | ||
return ret; | ||
} | ||
//============================================================================= | ||
template <class T> | ||
ArrayOf | ||
BetaIncomplete(const Dimensions& retDims, Class destinationType, indexType maxLen, | ||
const ArrayOf& X, const ArrayOf& Y, | ||
const ArrayOf& Z) | ||
{ | ||
T* result = (T*)ArrayOf::allocateArrayOf( | ||
destinationType, retDims.getElementCount(), stringVector(), false); | ||
ArrayOf res = ArrayOf(destinationType, retDims, result); | ||
auto* ptrX = (T*)X.getDataPointer(); | ||
auto* ptrY = (T*)Y.getDataPointer(); | ||
auto* ptrZ = (T*)Z.getDataPointer(); | ||
bool fails = false; | ||
#if defined(_NLS_WITH_OPENMP) | ||
#pragma omp parallel for | ||
#endif | ||
for (ompIndexType i = 0; i < (ompIndexType)maxLen; ++i) { | ||
T x = (X.isScalar()) ? ptrX[0] : ptrX[i]; | ||
T y = (Y.isScalar()) ? ptrY[0] : ptrY[i]; | ||
T z = (Z.isScalar()) ? ptrZ[0] : ptrZ[i]; | ||
try { | ||
result[i] = boost::math::ibeta(y, z, x); | ||
} catch (...) { | ||
fails = true; | ||
} | ||
} | ||
if (fails) { | ||
Error(_("Error evaluating betainc.")); | ||
} | ||
return res; | ||
} | ||
//============================================================================= | ||
ArrayOf | ||
BetaIncomplete(const ArrayOf& X, const ArrayOf& Y, const ArrayOf& Z, bool& needOverload) | ||
{ | ||
ArrayOf res; | ||
if (X.getDataClass() == NLS_DOUBLE || X.getDataClass() == NLS_SINGLE && !X.isSparse()) { | ||
needOverload = false; | ||
} else { | ||
needOverload = true; | ||
return res; | ||
} | ||
if (Y.getDataClass() == NLS_DOUBLE || Y.getDataClass() == NLS_SINGLE && !Y.isSparse()) { | ||
needOverload = false; | ||
} else { | ||
needOverload = true; | ||
return res; | ||
} | ||
if (Z.getDataClass() == NLS_DOUBLE || Z.getDataClass() == NLS_SINGLE && !Z.isSparse()) { | ||
needOverload = false; | ||
} else { | ||
needOverload = true; | ||
return res; | ||
} | ||
indexType maxLen = std::max(X.getLength(), std::max(Y.getLength(), Z.getLength())); | ||
Dimensions retDims | ||
= maxDimensions(X.getDimensions(), maxDimensions(Y.getDimensions(), Z.getDimensions())); | ||
if (!(X.isScalar()) && !retDims.equals(X.getDimensions())) { | ||
Error(_("Wrong size of the first argument.")); | ||
} | ||
if (!(Y.isScalar()) && !retDims.equals(Y.getDimensions())) { | ||
Error(_("Wrong size of the second argument.")); | ||
} | ||
if (!(Z.isScalar()) && !retDims.equals(Z.getDimensions())) { | ||
Error(_("Wrong size of the third argument.")); | ||
} | ||
if (X.getDataClass() == NLS_DOUBLE) { | ||
res = BetaIncomplete<double>(retDims, NLS_DOUBLE, maxLen, X, Y, Z); | ||
} else if (X.getDataClass() == NLS_SINGLE) { | ||
res = BetaIncomplete<single>(retDims, NLS_SINGLE, maxLen, X, Y, Z); | ||
} else { | ||
needOverload = true; | ||
} | ||
return res; | ||
} | ||
//============================================================================= | ||
} // namespace Nelson | ||
//============================================================================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//============================================================================= | ||
// Copyright (c) 2016-present Allan CORNET (Nelson) | ||
//============================================================================= | ||
// This file is part of the Nelson. | ||
//============================================================================= | ||
// LICENCE_BLOCK_BEGIN | ||
// This program is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// | ||
// Alternatively, you can redistribute it and/or | ||
// modify it under the terms of the GNU General Public License as | ||
// published by the Free Software Foundation; either version 2 of | ||
// the License, or (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public | ||
// License along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// LICENCE_BLOCK_END | ||
//============================================================================= | ||
#pragma once | ||
//============================================================================= | ||
#include "ArrayOf.hpp" | ||
#include "nlsSpecial_functions_exports.h" | ||
//============================================================================= | ||
namespace Nelson { | ||
NLSSPECIAL_FUNCTIONS_IMPEXP ArrayOf | ||
BetaIncomplete(const ArrayOf& X, const ArrayOf& Y, const ArrayOf& Z, bool& needOverload); | ||
} | ||
//============================================================================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters