Parser auf Boost.Multiprecision umstellen



  • Hi,

    ich bastle mal wieder am Parser von Th69.

    Diesen wollte ich von double auf boost::multiprecision::double_50 umstellen.

    Dazu habe ich einfach die biserhige definition von FctValue

    typedef double FctValue;
    

    in

    typedef boost::multiprecision::cpp_dec_float_50 FctValue;
    

    geändert.

    Jetzt tritt aber bei der Initialisierung von aFct[] der Fehler

    Fehler	C2440	"Initialisierung": "overloaded-function" kann nicht in "FunctionParser::Fct" konvertiert werden
    

    auf.

    aFct[] ist wie Folgt definiert

    FunctionParser::fct FunctionParser::aFct[] =
    {
    	{ "abs", fabs },
    	{ "acos", acos },
    	{ "asin", asin },
    	{ "atan", atan },
    	{ "ceil", ceil },
    	{ "cos", cos },
    	{ "cosh", cosh },
    	{ "exp", exp },
    	{ "floor", floor },
    	{ "ln", log },
    	{ "log", log10 },
    	{ "sgn", sgn },
    	{ "sin", sin },
    	{ "sinh", sinh },
    	{ "sqrt", sqrt },
    	{ "tan", tan },
    	{ "tanh", tanh },
    	{ NULL }
    };
    

    und so deklariert.

    typedef FctValue (*Fct)(FctValue a);	// Funktionen f(x)
    
    struct fct
    {
    const char *cFct;
    Fct _abc;
    };
    
    static fct aFct[];
    

    Weiß jemand wie ich dies konstelation funktionsfähig bekomme?



  • Hallo axels,

    die einzelnen Funktionen z.B. fabs, acos, asin, ... benötigen dann natürlich auch eine entsprechende Überladung für den Datentyp boost::multiprecision::cpp_dec_float_50.

    Du hast ja nichts gewonnen, wenn du dann die double oder float-Varianten dieser Funktionen benutzen würdest.

    In der Doku von boost::multiprecision gibt es unter Polynomial Evaluation ein Beispiel für die Berechnung von sin.

    Im Codeproject-Artikel Boost-Multiprecision-Library steht außerdem:

    Common trigonometry functions such as sin, cos, tan, asin, acos and atan are supported for multiprecision float. User can also compute logarithm and square root. For more info, please take a look at the default_ops.hpp.

    Du müßtest also diesen Header einbinden (falls er nicht schon standardmäßig eingebunden wird) - und am besten cmath (bzw. math.h) rausschmeißen.

    Und dann das Funktionsarray durchgehen und schauen, welche Funktionen es noch nicht gibt.
    Am besten einfach ersteinmal alle Funktionen auskommentieren und dann nach und nach einkommentieren - dann siehst du ja, welche Funktionen fehlerhaft sind (dein Compiler müßte eigentlich in der Fehlerbeschreibung auch die passende Zeile ausgeben).

    Edit:
    Wenn ich die Funktionen aus default_ops.h vergleiche (am Ende der Datei, z.B. "UNARY_OP_FUNCTOR(fabs, number_kind_floating_point)"), dann sind wohl alle Funktionen definiert.

    Wenn du nicht weiterkommst, dann poste mal die gesamte Fehlermeldung (und welchen Compiler du nutzt).



  • Hi TH69,

    es ändert sich nichts. Exemplarisch an den ersten drei Funktionen getestet.
    <cmath> ist auskommtentiert und <default_ops.hpp> inkludiert.

    Der Compiler (VS2015) wirft immernoch die gleiche Fehlermeldung

    Fehler	C2440	"Initialisierung": "overloaded-function" kann nicht in "FunctionParser::Fct" konvertiert werden	fctparser.cpp	41
    

    Zeile 41 ist das Ende des arrays

    In der Buildausgabe stehen folgene zwei Meldungen

    fctparser.cpp(41): error C2440: "Initialisierung": "overloaded-function" kann nicht in "FunctionParser::Fct" konvertiert werden
    
    fctparser.cpp(41): note: Keine Funktion mit diesem Namen im Gültigkeitsbereich stimmt mit dem Zieltyp überein
    
    FunctionParser::fct FunctionParser::aFct[] =
    {
    	{ "abs", boost::multiprecision::fabs},
    	{ "acos", boost::multiprecision::acos},
    	{ "asin", boost::multiprecision::asin}
    	/*{ "atan", atan },
    	{ "ceil", ceil },
    	{ "cos", cos },
    	{ "cosh", cosh },
    	{ "exp", exp },
    	{ "floor", floor },
    	{ "ln", log },
    	{ "log", log10 },
    	{ "sgn", sgn },
    	{ "sin", sin },
    	{ "sinh", sinh },
    	{ "sqrt", sqrt },
    	{ "tan", tan },
    	{ "tanh", tanh },
    	{ NULL }*/
    }; <-- Zeile 41
    

    Ich glaube der Fehlerteufel liegt in dem

    typedef FctValue (*Fct)(FctValue a);	// Funktionen f(x)
    

    kann mir aber nicht vorstellen warum.



  • Puh, ist ein bißchen schwierig den Code von default_ops zu verstehen, aber probiere mal

    typedef FctValue (*Fct)(const FctValue &a);
    

    oder sogar

    typedef const FctValue& (*Fct)(const FctValue &a);
    


  • Beides hat keine Änderung gebracht.
    Immernoch die selbe Fehlermeldung.



  • Gibt der Compiler denn nicht mehr bei der Fehlermeldung aus, so etwas wie "candidates are..."?
    Mittels Changing Build Verbosity in Visual Studio kannst du mal versuchen dies zu ändern.

    Ansonsten mal mit dem gcc compilieren.

    PS: Ich kriege jetzt gleich Besuch - ich schau dann morgen früh hier noch mal rein.



  • Bei Detailierter Buildausgabe gibt er mir die selben zwei Fehlermeldungen wie vorher aus

    fctparser.cpp(41): error C2440: "Initialisierung": "overloaded-function" kann nicht in "FunctionParser::Fct" konvertiert werden
    
    fctparser.cpp(41): note: Keine Funktion mit diesem Namen im Gültigkeitsbereich stimmt mit dem Zieltyp überein
    

    und noch mehr was mir direkt aber nichts sagt.

    1>Ziel "ClCompile" in Datei "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets" aus Projekt "D:\Entwicklung\Math++\Math++\Math++_lib\Math++_lib.vcxproj" (Einstiegspunkt):
    1>       Festgelegte Eigenschaft: CLToolArchitecture=Native32Bit
    1>       Festgelegte Eigenschaft: CLDeleteOutputOnExecute=true
    1>       Die Delete-Aufgabe wurde übersprungen, da die Bedingung "false" war . ('%(ClCompile.DebugInformationFormat)' != '' and '%(ClCompile.DebugInformationFormat)' != 'None' and '%(ClCompile.DebugInformationFormat)' != 'OldStyle' and '%(ClCompile.ProgramDataBaseFileName)' != '' and !Exists(%(ClCompile.ProgramDataBaseFileName))) wurde als ('EditAndContinue' != '' and 'EditAndContinue' != 'None' and 'EditAndContinue' != 'OldStyle' and 'Debug\Math++_lib.pdb' != '' and !Exists(Debug\Math++_lib.pdb)) ausgewertet.
    1>       Die CL-Aufgabe wurde übersprungen, da die Bedingung "false" war . ('%(ClCompile.PrecompiledHeader)' == 'Create' and '%(ClCompile.ExcludedFromBuild)'!='true' and '%(ClCompile.CompilerIteration)' == '') wurde als ('NotUsing' == 'Create' and ''!='true' and '' == '') ausgewertet.
    1>       Die CL-Aufgabe aus der C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Build.CppTasks.Common.dll-Assembly wird verwendet.
    1>       CL-Aufgabe
    1>         Aufgabenparameter:BuildingInIde=True
    1>         Aufgabenparameter:
    1>             Sources=
    1>                 code\funktionsparaser\FctParser.cpp
    1>                         AcceptableNonZeroExitCodes=
    1>                         AdditionalIncludeDirectories=D:\Entwicklung\Math++\Math++\packages\boost.1.63.0.0\build\native\..\..\lib\native\include\;
    1>                         AssemblerListingLocation=
    1>                         AssemblerOutput=NoListing
    1>                         BasicRuntimeChecks=EnableFastChecks
    1>                         BrowseInformation=false
    1>                         BrowseInformationFile=Debug\
    1>                         BufferSecurityCheck=true
    1>                         CallingConvention=Cdecl
    1>                         CompileAs=CompileAsCpp
    1>                         DebugInformationFormat=EditAndContinue
    1>                         DisableLanguageExtensions=false
    1>                         EnableEnhancedInstructionSet=NotSet
    1>                         EnableFiberSafeOptimizations=false
    1>                         EnablePREfast=false
    1>                         ErrorReporting=Prompt
    1>                         ExceptionHandling=Sync
    1>                         ExpandAttributedSource=false
    1>                         FavorSizeOrSpeed=Neither
    1>                         FloatingPointModel=Precise
    1>                         ForceConformanceInForLoopScope=true
    1>                         ForcedIncludeFiles=
    1>                         ForcedUsingFiles=
    1>                         GenerateXMLDocumentationFiles=false
    1>                         IgnoreStandardIncludePath=false
    1>                         ImpLibCompiled=
    1>                         InlineFunctionExpansion=Default
    1>                         IntrinsicFunctions=false
    1>                         LibCompiled=true
    1>                         LinkCompiled=
    1>                         MinimalRebuild=true
    1>                         MinimalRebuildFromTracking=false
    1>                         ObjectFileName=Debug\
    1>                         OmitDefaultLibName=false
    1>                         OmitFramePointers=false
    1>                         Optimization=Disabled
    1>                         PrecompiledHeader=NotUsing
    1>                         PrecompiledHeaderFile=
    1>                         PrecompiledHeaderOutputFile=
    1>                         PreprocessKeepComments=false
    1>                         PreprocessorDefinitions=;_MBCS;
    1>                         PreprocessSuppressLineNumbers=false
    1>                         PreprocessToFile=false
    1>                         ProgramDataBaseFileName=Debug\Math++_lib.pdb
    1>                         RemoveUnreferencedCodeData=true
    1>                         RuntimeLibrary=MultiThreadedDebugDll
    1>                         SDLCheck=true
    1>                         ShowIncludes=false
    1>                         SmallerTypeCheck=false
    1>                         StructMemberAlignment=Default
    1>                         SuppressStartupBanner=true
    1>                         TrackerLogDirectory=Debug\Math++_lib.tlog\
    1>                         TreatWarningAsError=false
    1>                         TreatWChar_tAsBuiltInType=true
    1>                         UndefineAllPreprocessorDefinitions=false
    1>                         UseFullPaths=false
    1>                         UseUnicodeForAssemblerListing=
    1>                         WarningLevel=Level3
    1>                         WholeProgramOptimization=false
    1>                         WinRTNoStdLib=false
    1>                         XMLDocumentationFileName=Debug\
    1>         Aufgabenparameter:AdditionalIncludeDirectories=D:\Entwicklung\Math++\Math++\packages\boost.1.63.0.0\build\native\..\..\lib\native\include\
    1>         Aufgabenparameter:AssemblerOutput=NoListing
    1>         Aufgabenparameter:BasicRuntimeChecks=EnableFastChecks
    1>         Aufgabenparameter:BrowseInformation=False
    1>         Aufgabenparameter:BrowseInformationFile=Debug\
    1>         Aufgabenparameter:BufferSecurityCheck=true
    1>         Aufgabenparameter:CallingConvention=Cdecl
    1>         Aufgabenparameter:CompileAs=CompileAsCpp
    1>         Aufgabenparameter:DebugInformationFormat=EditAndContinue
    1>         Aufgabenparameter:DisableLanguageExtensions=False
    1>         Aufgabenparameter:EnableEnhancedInstructionSet=NotSet
    1>         Aufgabenparameter:EnableFiberSafeOptimizations=False
    1>         Aufgabenparameter:EnablePREfast=False
    1>         Aufgabenparameter:ErrorReporting=Prompt
    1>         Aufgabenparameter:ExceptionHandling=Sync
    1>         Aufgabenparameter:
    1>             ExcludedInputPaths=
    1>                 D:\Programme\Visual Studio 14.0\VC\include
    1>                 D:\Programme\Visual Studio 14.0\VC\atlmfc\include
    1>                 C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt
    1>                 C:\Program Files (x86)\Windows Kits\8.1\Include\um
    1>                 C:\Program Files (x86)\Windows Kits\8.1\Include\shared
    1>                 C:\Program Files (x86)\Windows Kits\8.1\Include\winrt
    1>                 C:\Program Files (x86)\MSBuild\14.0\bin\
    1>                 C:\Windows\Microsoft.NET\Framework\v4.0.30319\
    1>                 D:\Programme\Visual Studio 14.0\VC\lib
    1>                 D:\Programme\Visual Studio 14.0\VC\atlmfc\lib
    1>                 C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x86
    1>         Aufgabenparameter:ExpandAttributedSource=False
    1>         Aufgabenparameter:FavorSizeOrSpeed=Neither
    1>         Aufgabenparameter:FloatingPointModel=Precise
    1>         Aufgabenparameter:ForceConformanceInForLoopScope=True
    1>         Aufgabenparameter:GenerateXMLDocumentationFiles=False
    1>         Aufgabenparameter:IgnoreStandardIncludePath=False
    1>         Aufgabenparameter:InlineFunctionExpansion=Default
    1>         Aufgabenparameter:IntrinsicFunctions=False
    1>         Aufgabenparameter:MinimalRebuild=True
    1>         Aufgabenparameter:ObjectFileName=Debug\
    1>         Aufgabenparameter:OmitDefaultLibName=False
    1>         Aufgabenparameter:OmitFramePointers=False
    1>         Aufgabenparameter:Optimization=Disabled
    1>         Aufgabenparameter:PrecompiledHeader=NotUsing
    1>         Aufgabenparameter:PreprocessKeepComments=False
    1>         Aufgabenparameter:PreprocessorDefinitions=_MBCS
    1>         Aufgabenparameter:PreprocessSuppressLineNumbers=False
    1>         Aufgabenparameter:PreprocessToFile=False
    1>         Aufgabenparameter:ProgramDataBaseFileName=Debug\Math++_lib.pdb
    1>         Aufgabenparameter:RemoveUnreferencedCodeData=True
    1>         Aufgabenparameter:RuntimeLibrary=MultiThreadedDebugDll
    1>         Aufgabenparameter:SDLCheck=True
    1>         Aufgabenparameter:ShowIncludes=False
    1>         Aufgabenparameter:SmallerTypeCheck=False
    1>         Aufgabenparameter:StructMemberAlignment=Default
    1>         Aufgabenparameter:SuppressStartupBanner=True
    1>         Aufgabenparameter:TreatWarningAsError=False
    1>         Aufgabenparameter:TreatWChar_tAsBuiltInType=True
    1>         Aufgabenparameter:UndefineAllPreprocessorDefinitions=False
    1>         Aufgabenparameter:UseFullPaths=False
    1>         Aufgabenparameter:WarningLevel=Level3
    1>         Aufgabenparameter:WholeProgramOptimization=False
    1>         Aufgabenparameter:WinRTNoStdLib=False
    1>         Aufgabenparameter:XMLDocumentationFileName=Debug\
    1>         Aufgabenparameter:TrackerLogDirectory=Debug\Math++_lib.tlog\
    1>         Aufgabenparameter:TrackFileAccess=True
    1>         Aufgabenparameter:MinimalRebuildFromTracking=False
    1>         Aufgabenparameter:ToolArchitecture=Native32Bit
    1>         Aufgabenparameter:DeleteOutputOnExecute=True
    1>         Aufgabenparameter:YieldDuringToolExecution=True
    1>         An das Tool übergebene Umgebungsvariablen:
    1>           VS_UNICODE_OUTPUT=1724
    1>         D:\Programme\Visual Studio 14.0\VC\bin\CL.exe /c /ID:\Entwicklung\Math++\Math++\packages\boost.1.63.0.0\build\native\..\..\lib\native\include\ /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D _MBCS /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\\" /Fd"Debug\Math++_lib.pdb" /Gd /TP /analyze- /errorReport:prompt code\funktionsparaser\FctParser.cpp
    1>         Tracking command:
    1>         C:\Program Files (x86)\MSBuild\14.0\bin\Tracker.exe /d "C:\Program Files (x86)\MSBuild\14.0\bin\FileTracker32.dll" /i D:\Entwicklung\Math++\Math++\Math++_lib\Debug\Math++_lib.tlog /r D:\ENTWICKLUNG\MATH++\MATH++\MATH++_LIB\CODE\FUNKTIONSPARASER\FCTPARSER.CPP /b MSBuildConsole_CancelEvent28263472e93d497db181d3561ca4e9bc  /c "D:\Programme\Visual Studio 14.0\VC\bin\CL.exe"  /c /ID:\Entwicklung\Math++\Math++\packages\boost.1.63.0.0\build\native\..\..\lib\native\include\ /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D _MBCS /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\\" /Fd"Debug\Math++_lib.pdb" /Gd /TP /analyze- /errorReport:prompt code\funktionsparaser\FctParser.cpp
    1>         FctParser.cpp
    1>    
    1>         Der Befehl wurde mit dem Code 2 beendet.
    1>       Die Ausführung der CL-Aufgabe ist abgeschlossen -- FEHLER.
    1>     1>
    


  • Liegt vermutlich daran dass du überladene Funktionen hast, die du entsprechend in den konkreten Typen umkasten müsstest.



  • Also,

    ich bin zu einer Lösung gekommen.

    Ich habe jetzt sämtliche Funktionen des Arrays nochmals überladen um dann die boost::multiprecision Methode aufzurufen.

    Sieht dann so aus:

    FctValue sgn(FctValue x)
    {
    	return (x>0)? 1 :
    			(x<0)? -1 : 0;
    };
    
    FctValue fabs(FctValue x)
    {
    	return boost::multiprecision::fabs(x);
    }
    
    FctValue acos(FctValue x)
    {
    	return boost::multiprecision::acos(x);
    }
    
    FctValue asin(FctValue x) 
    {
    	return boost::multiprecision::asin(x);
    }
    
    FctValue atan(FctValue x)
    {
    	return boost::multiprecision::atan(x);
    }
    
    FctValue ceil(FctValue x)
    {
    	return boost::multiprecision::ceil(x);
    }
    
    FctValue cos(FctValue x)
    {
    	return boost::multiprecision::cos(x);
    }
    
    FctValue cosh(FctValue x)
    {
    	return boost::multiprecision::cosh(x);
    }
    
    FctValue exp(FctValue x)
    {
    	return boost::multiprecision::exp(x);
    }
    
    FctValue floor(FctValue x)
    {
    	return boost::multiprecision::floor(x);
    }
    
    FctValue log(FctValue x) 
    {
    	return boost::multiprecision::log(x);
    }
    
    FctValue log10(FctValue x) 
    {
    	return boost::multiprecision::log10(x);
    }
    
    FctValue sin(FctValue x)
    {
    	return boost::multiprecision::sin(x);
    }
    
    FctValue sinh(FctValue x)
    {
    	return boost::multiprecision::sinh(x);
    }
    
    FctValue sqrt(FctValue x) 
    {
    	return boost::multiprecision::sqrt(x);
    }
    
    FctValue tan(FctValue x)
    {
    	return boost::multiprecision::tan(x);
    }
    
    FctValue tanh(FctValue x)
    {
    	return boost::multiprecision::tanh(x);
    }
    
    FunctionParser::fct FunctionParser::aFct[] =
    {
    	{ "abs", fabs},
    	{ "acos", acos},
    	{ "asin", asin},
    	{ "atan", atan },
    	{ "ceil", ceil },
    	{ "cos", cos },
    	{ "cosh", cosh },
    	{ "exp", exp },
    	{ "floor", floor },
    	{ "ln", log },
    	{ "log", log10 },
    	{ "sgn", sgn },
    	{ "sin", sin },
    	{ "sinh", sinh },
    	{ "sqrt", sqrt },
    	{ "tan", tan },
    	{ "tanh", tanh },
    	{ NULL }
    };
    

    Performace der gesamten Anwendung ist durch die verwendung von boost::multiprecision sehr eingebrochen.

    Bsp:
    Eine Berechnung die mit double etwa 80ms gebraucht hat, dauert jetzt knapp 3,5 Sekunden. Unter Release Einstellungen, sprich mit maximaler Compileroptimierung.

    Selbe Berechung im Debug-mode 30 Sekunden.

    Ob die gesteigerte Präzision diesen Performanceverlust wert ist, gilt es abzuwägen.

    @TH69 Vielen Dank für die Hilfe!



  • Schön, daß du jetzt eine Lösung gefunden hast.

    Ich habe mal mit dem gcc einen Testcode geschrieben, der den Fehler aufzeigt: ideone
    Dort sieht man schön die verschiedenen Funktionsprototypen aufgelistet.
    Ich bin mir immer noch sicher, daß man es auch ohne Neudefinition der Funktionen hinkriegen müßte (wenn man die genauen Prototypen der Boost.Multiprecision-Funktionen kennt).

    Und klar, daß die Performance in den Keller geht - denn die gesamten Berechnungen laufen jetzt ja nicht mehr auf den nativen Fließkomma-Prozessordatentypen.
    Du könntest auch mal zum Vergleich die anderen Datentypen (s. boost.multiprecision: floating-point Numbers) benutzen.


Anmelden zum Antworten