Add support for BigInteger in CPython engine#10830
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.
@aparajit-pratap these are the encoders I mentioned before.
There was a problem hiding this comment.
@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.
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.
thank you for making this internal!
🎉
test/Libraries/DynamoPythonTests/PythonEvalTestsWithLibraries.cs
Outdated
Show resolved
Hide resolved
| </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.
just curious about the requirement for these dependencies.
There was a problem hiding this comment.
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.
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.
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.
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)) |
| } | ||
| return list; | ||
| } | ||
| else if (PyDict.IsDictType(pyObj)) |
There was a problem hiding this comment.
No need for else here.
| { | ||
| return pyLong.ToInt64(); | ||
| } | ||
| catch (PythonException exc) when (exc.Message.StartsWith("OverflowError")) |
There was a problem hiding this comment.
Interesting, I haven't seen a when clause like this before.
There was a problem hiding this comment.
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
aparajit-pratap
left a comment
There was a problem hiding this comment.
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
*.resxfilesReviewers
@DynamoDS/dynamo