Re: [Python.NET] Getting an open Python file handle into CLR

2015-07-21 Thread Jeffrey Bush
As I said in my message, you can using IntPtr.Overloads[Int64](handle). Jeff On Tue, Jul 21, 2015 at 11:12 AM, Dan Lenski wrote: > Ron Harding via PythonDotNet writes: > > > perhaps re-directed command line calls for stdin, stdout, stderr in c# > interacting with python i/o command line calls(

Re: [Python.NET] Getting an open Python file handle into CLR

2015-07-21 Thread Jeffrey Bush
The problem is the conversion from a Python long to a C# number, not anything to do with the file handle itself. This worked for me: (after your "print handle") cs_handle = IntPtr.Overloads[Int64](Int64(handle)) fs = FileStream(cs_handle, True) Jeff On Mon, Jul 20, 2015 at 9:19 PM, Ron Harding

Re: [Python.NET] About use DotNet threading lib

2015-03-04 Thread Jeffrey Bush
You seem to be slightly misinformed about the cPython GIL. While it is true that it prevents two Python statements from being interpreted at the same time, many "long-running" functions automatically release the GIL while they are being executed. For example, when reading and writing a file the GIL

Re: [Python.NET] Efficient copy of .NET Array to ctypes or numpy array

2014-11-20 Thread Jeffrey Bush
; ix = it.multi_index > if len(ix)==1: > netarr[ix[0]] = res[ix[0]] > else: > netarr[ix] = res[ix] > it.iternext() > return netarr > return inner > > Thanks, > > Denis > > > On Wed, No

Re: [Python.NET] Efficient copy of .NET Array to ctypes or numpy array

2014-11-05 Thread Jeffrey Bush
ote: >>> >>>> Thanks Brad and Jeff for the detailed info. For now, fromiter is >>>> serving me well and has reduced my processing time considerably, so I am >>>> just going to stick with it. >>>> >>>> >>>> On 29 Octobe

Re: [Python.NET] Efficient copy of .NET Array to ctypes or numpy array

2014-10-28 Thread Jeffrey Bush
I finally have a chance to chime in, and Bradley is exactly right. Marshall.Copy copies the raw data, and apparently your file library does not store that data in a nice, contiguous, manner. While it is highly likely that copying all the data to an array in C# will be faster than the fromiter in Py

Re: [Python.NET] converting double array to numpy list

2014-08-21 Thread Jeffrey Bush
ut in my case when I call python from c#, I do that using > InvokeMethod that would only allow me to pass an array of PyObjects. So > that's the challenge. > > > > On Wed, Aug 20, 2014 at 12:23 PM, Jeffrey Bush > wrote: > >> Numpy arrays are almost always created

Re: [Python.NET] converting double array to numpy list

2014-08-20 Thread Jeffrey Bush
Numpy arrays are almost always created in Python and there are dozens of methods. That post you link to has the best solution for this case: import numpy as np dest = np.empty(len(src)) That creates a new numpy array of the same length of src with undefined ("empty") values at every index. You co

Re: [Python.NET] Efficient copy of .NET Array to ctypes or numpy array.

2014-05-23 Thread Jeffrey Bush
The problem with your current code is that as soon as you call src_hndl.Free() the pointer is not necessarily valid any more! .NET is allowed to move the memory contents of objects at will unless they are pinned (which is what the first line does). By freeing the GCHandle it is no longer pinned and

Re: [Python.NET] Efficient copy of .NET Array to ctypes or numpy array.

2014-05-21 Thread Jeffrey Bush
n %f sec' % (end-start)) check_arrays(src, dest) print('Copy using Marshal.Copy'), from System.Runtime.InteropServices import Marshal start = time.clock() dest = np.empty(len(src)) Marshal.Copy(src, 0, IntPtr.__overloads__[int](dest.__array_interface__['data'][0]), len(src)) end = time.c

Re: [Python.NET] Efficient copy of .NET Array to ctypes or numpy array.

2014-05-21 Thread Jeffrey Bush
You could write a .NET function to do this with fixed pointers and "memcpy" from the .NET array to the numpy data (the raw data). This would be the absolute fastest way, but does involve a number of assumptions (for example that the data in the two arrays are laid out in the same way). If you want

Re: [Python.NET] Problem with System.ArgumentException in call to method from dll

2013-01-23 Thread Jeffrey Bush
As previously said you have to probably do something like: from System.Windows.Media.Imaging import BitmapSource bitmapsrc = None cam = xiCam() cam.OpenDevice(0) cam.SetParam(PRM.BUFFER_**POLICY, BUFF_POLICY.SAFE) cam.SetParam(PRM.IMAGE_DATA_**FORMAT, IMG_FORMAT.MONO8) cam.StartAcquisition() time

Re: [Python.NET] Memory Type Problems

2013-01-17 Thread Jeffrey Bush
nceEquals(System.Object, System.Object) > | > | __overloads__ > > As for the smarts behind it, it'll be fun to get back into the guts and > see if some improvements can be made. > > Oh boy; I just love those System.NotSupportedException(s)! > Thanks for the feedba

Re: [Python.NET] Memory Type Problems

2013-01-15 Thread Jeffrey Bush
; - I tend to think of this package as a "wrist-friendly" (see > Boo) wrapper over the Mono/.NET components more than a trying to be a type > compatibility layer. > > 3) Slicing seems like something that is worth implementing. That would > take a lot of typing ou

Re: [Python.NET] Memory Type Problems

2013-01-08 Thread Jeffrey Bush
range(10)) > >>> a = Array[Byte](list(i for i in g)) > > >>> a[5] > 0 > > On 01/04/2013 06:33 PM, Jeffrey Bush wrote: > > Hi, > > I have a library in C for compression. I made Python script for testing > it, called using ctypes. > > Now, I a

[Python.NET] Memory Type Problems

2013-01-04 Thread Jeffrey Bush
Hi, I have a library in C for compression. I made Python script for testing it, called using ctypes. Now, I am working on a .NET library for something very similar and would like to test it in the same way. However, I am getting lost in how to do some of the things with your library. The functio