Hi Alessandro, Nice to see how easily you use the C++ library ;-)! Note that the evaluation operator over a sample is not mandatory. It allows you to implement an optimized version of the evaluation over a collection of input points eg using parallelism. The default implementation is a simple loop over the points, ie the method you implemented.
Cheers Régis Le vendredi 27 mars 2020 à 14:21:37 UTC+1, Mori Alessandro <[email protected]> a écrit : Thank Régis, In the meanwhile, I have tried to define a my class, inheriting EvaluationImplementation. It seems to work: ---- class UserFunctionImplementation : public EvaluationImplementation { public: explicit UserFunctionImplementation(rvar (*ineqFcn)(rvar inV)) : EvaluationImplementation() { ineqFcn_ = ineqFcn; if (ineqFcn_ == NULL) throw InvalidDimensionException(HERE) << "Error: cannot build an user function implementation with a NULL pointer"; setInputDescription(Description::BuildDefault(dimension_, "x")); setOutputDescription(Description::BuildDefault(dimension_, "y")); } virtual UserFunctionImplementation * clone() const { return new UserFunctionImplementation(*this); } Bool operator ==(const UserFunctionImplementation & other) const { return ((dimension_ == other.dimension_) && (ineqFcn_ == other.ineqFcn_)); } virtual Point operator() (const Point & inP) const { if (inP.getDimension() != dimension_) throw InvalidArgumentException(HERE) << "Invalid input dimension"; callsNumber_.increment(); rvar out = (*ineqFcn_)(inP[0]); return Point(1, out); } virtual Sample operator() (const Sample & inS) const { UnsignedInteger dim = inS.getDimension(); UnsignedInteger size = inS.getSize(); if (dim != dimension_) throw InvalidArgumentException(HERE) << "Invalid input dimension"; callsNumber_.fetchAndAdd(size); Sample outS(size, dim); for (UnsignedInteger i = 0; i < size; i++) outS[i] = (*this)(inS[i]); return outS; } virtual UnsignedInteger getInputDimension() const { return dimension_; } virtual UnsignedInteger getOutputDimension() const { return dimension_; } private: const UnsignedInteger dimension_ = 1; rvar (*ineqFcn_)(rvar inV); }; ----- Then UserFunctionImplementation inequality_implementation(inequalityFunctionKriging); Where inequalityFunctionKriging is a function (double inequalityFunctionKriging(double)) defined in a c++ source. Thanks again, Alessandro Alessandro Mori Computational ElectroMagnetic Engineering System Analyst IDS Ingegneria Dei Sistemi S.p.A. www.idscorporation.com Pisa Headquarters: Via Enrica Calabresi, 24 - Loc. Montacchiello 56121 Pisa (PI) - Italy Tel: +39 050 3124 289 Fax: +39 050 3124 201 e-mail: [email protected] ****************************************************************************************************************************************************** This email and any attachments are confidential and is intended only for the use of the intended addressee thereof. If you are not the intended addressee, please be aware that any use, disclosure, distribution and/or copying of this communication, either whole or partial, is strictly prohibited. If you receive this communication in error, please notify the sender immediately and delete it from your computer. ******************************************************************************************************************************************************** -----Original Message----- From: regis lebrun <[email protected]> Sent: giovedì 26 marzo 2020 22:10 To: [email protected]; Mori Alessandro <[email protected]> Subject: Re: [ot-users] user c++ function Hi again, Currently we only provide a Python module to the Windows users of OpenTURNS. If you manage to interface your C++ function with Python (see eg https://stackoverflow.com/questions/145270/calling-c-c-from-python), then you should have a look at the PythonFunction class in OpenTURNS, see: http://openturns.github.io/openturns/latest/user_manual/_generated/openturns.PythonFunction.html http://openturns.github.io/openturns/latest/examples/functional_modeling/python_function.html You also have a dedicated section in the Developer's guide: http://openturns.github.io/openturns/latest/developer_guide/wrapper_development.html Don't hesitate to contact me directly if you need further help. Cheers Régis Le jeudi 26 mars 2020 à 21:17:21 UTC+1, Mori Alessandro <[email protected]> a écrit : Hello, I am using OpenTURNS in a C++ code. I have to create a Function defined by a C++ routine (Sample someName(Sample input) or Point someOtherName(Point input)). Is there any example showing how to do this (maybe using a pointer to the C++ routine)? Thank you, Alessandro Alessandro Mori Computational ElectroMagnetic Engineering System Analyst IDS Ingegneria Dei Sistemi S.p.A. www.idscorporation.com Pisa Headquarters: Via Enrica Calabresi, 24 - Loc. Montacchiello 56121 Pisa (PI) - Italy Tel: +39 050 3124 289 Fax: +39 050 3124 201 e-mail: [email protected] Capitale Sociale 13.171.240 Euro i.v. – C.C.I.A.A. Pisa, R.E.A. n° 77042 - C.F. 00672210507 – P. IVA (VAT) IT 00672210507 Share Capital 13.171.240 euro fully paid – registered at the Pisa Chamber of Commerce, R.E.A. n. 77042 – Tax number and VAT code (IT) 00672210507 - e-mail (PEC): [email protected] (for use in Italy only) P Save a tree, please don't print this e-mail unless you really need to. ******************************************************************************************************************************************************** This email and any attachments are confidential and is intended only for the use of the intended addressee thereof. If you are not the intended addressee, please be aware that any use, disclosure, distribution and/or copying of this communication, either whole or partial, is strictly prohibited. If you receive this communication in error, please notify the sender immediately and delete it from your computer. ******************************************************************************************************************************************************** _______________________________________________ OpenTURNS users mailing list [email protected] http://openturns.org/mailman/listinfo/users _______________________________________________ OpenTURNS users mailing list [email protected] http://openturns.org/mailman/listinfo/users _______________________________________________ OpenTURNS users mailing list [email protected] http://openturns.org/mailman/listinfo/users
