CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 658
Add support for BigInteger in CPython engine #10830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@mmisol 😢
maybe time to retire this build and use our github action instead? |
Yeah. I saw that appveyor thing probably needs an update, but it's not even ours! Probably it is a good time to retire it. I read we should just remove the web hook and that's it. |
/// </summary> | ||
private static void InitializeEncoders() | ||
{ | ||
var encoders = new IPyObjectEncoder[] { new BigIntegerEncoder() }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aparajit-pratap these are the encoders I mentioned before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmisol was the biginteger encoder/decoder added by you? I may have missed it in your PR's to Python.NET repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BigIntegerEncoder
is part of this submission. The API to add them already existed. One thing I did add in Python.NET is the function PyLong.ToBigInteger
, which is used by the decoder.
|
||
namespace DSCPython.Encoders | ||
{ | ||
internal class BigIntegerEncoder : IPyObjectEncoder, IPyObjectDecoder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for making this internal!
🎉
test/Libraries/DynamoPythonTests/PythonEvalTestsWithLibraries.cs
Outdated
Show resolved
Hide resolved
@@ -117,6 +119,10 @@ | |||
<Name>PythonNodeModels</Name> | |||
<Private>False</Private> | |||
</ProjectReference> | |||
<ProjectReference Include="..\..\..\src\Tools\DynamoShapeManager\DynamoShapeManager.csproj"> | |||
<Project>{263fa9c1-f81e-4a8e-95e0-8cdae20f177b}</Project> | |||
<Name>DynamoShapeManager</Name> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious about the requirement for these dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, when you inherit from DynamoModelTestBase
and want to customize CreateStartConfiguration
you pass some parameters that will complain because you don't have these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh, okay, generally I would say avoid loading libraries that we don't need during the test as these types will be imported into the VM over and over again for each test which can be kind of slow. So if we write 1000 ironPython tests we'll load all the geometry types into the VM foreach test.
Why are we spending a whole bunch of time with BigIntegers. They just happen to be supported by IronPython but not a big use case for zero touch nodes or even python nodes for that matter. |
|
||
using (var pyLong = PyLong.AsLong(pyObj)) | ||
{ | ||
value = (T)(object)pyLong.ToBigInteger(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
staring at this I'm assuming that PythonNet will only ever call this method when T is bigInteger
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I think there is something strange with the definition of the interface because it's not a generic one but one of its methods is generic. I didn't know how to handle that exactly but I took this from an example they have in a test.
Hi @mjkkirschner @aparajit-pratap . If there is nothing else missing here, can I ask for your approval? Thanks |
} | ||
return dict; | ||
} | ||
else if (PyLong.IsLongType(pyObj)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or here.
} | ||
return list; | ||
} | ||
else if (PyDict.IsDictType(pyObj)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for else
here.
{ | ||
return pyLong.ToInt64(); | ||
} | ||
catch (PythonException exc) when (exc.Message.StartsWith("OverflowError")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I haven't seen a when
clause like this before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are called exception filters. They allow to catch an exception type conditionally to the fact they also match the expression given in when
. They were introduced in C# 6 https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-6#exception-filters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments; other than that LGTM.
Purpose
Support is added for encoding decoding BigInteger values from Python
int that have a size that exceeds what can fit in a long.
Also a BigInteger encoder/decoder is added to the custom encoders of
Python.NET in order to support encoding and decoding in the context of
function calls.
Declarations
Check these if you believe they are true
*.resx
filesReviewers
@DynamoDS/dynamo