Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add support for complex type #2136

Open
Labels
@jjwallman

Description

@jjwallman

Environment

  • Pythonnet version: 3.0.1
  • Python version: 3.9.13
  • Operating System: Windows 10
  • .NET Runtime: Microsoft.AspNetCore.App 6.0.15

Details

  • I would like to be able to use complex numbers through pythonnet. To achieve this, encoders/decoders should translate between a PyComplex class based on thehttps://docs.python.org/3/c-api/complex.html#c.PyComplex_Type and the System.Numerics.Complex class.

  • I created a minimal class to create a System.Numerics.Complex from real and imaginary parts and return it to Python and to print a System.Numerics.Complex passed to a function (see attached source code).

  • I compiling the solution and copied the resulting dll into aComplex folder with the__init__.py andclr_runtime.json files in the attached zip file.

  • I ran ipython in the directory containingComplex and ran the following commands:

importComplextest=Complex.ComplexNS().Test()test.makeComplex(1.0,1.0)# test 1test.convertComplex(1j)# test 2-Theresultoftest.makeComplex(1.0,1.0)was<System.Numerics.Complexobjectat0x000001A8F1C03380>,whereasIwasexpecting1+1j-Thetracebackis-In [5]:test.convertComplex(1j)---------------------------------------------------------------------------PythonExceptionTraceback (mostrecentcalllast)PythonException:'complex'valuecannotbeconvertedtoSystem.Numerics.ComplexTheaboveexceptionwasthedirectcauseofthefollowingexception:ArgumentExceptionTraceback (mostrecentcalllast)ArgumentException:'complex'valuecannotbeconvertedtoSystem.Numerics.ComplexinmethodSystem.StringconvertComplex(System.Numerics.Complex)--->Python.Runtime.PythonException:'complex'valuecannotbeconvertedtoSystem.Numerics.Complex---Endofinnerexceptionstacktrace---Theaboveexceptionwasthedirectcauseofthefollowingexception:AggregateExceptionTraceback (mostrecentcalllast)AggregateException:Oneormoreerrorsoccurred. ('complex'valuecannotbeconvertedtoSystem.Numerics.ComplexinmethodSystem.StringconvertComplex(System.Numerics.Complex))--->System.ArgumentException:'complex'valuecannotbeconvertedtoSystem.Numerics.ComplexinmethodSystem.StringconvertComplex(System.Numerics.Complex)--->Python.Runtime.PythonException:'complex'valuecannotbeconvertedtoSystem.Numerics.Complex---Endofinnerexceptionstacktrace------Endofinnerexceptionstacktrace---Theaboveexceptionwasthedirectcauseofthefollowingexception:TypeErrorTraceback (mostrecentcalllast)CellIn [5],line1---->1test.convertComplex(1j)[Complex.zip](https://github.com/pythonnet/pythonnet/files/11063123/Complex.zip)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp