Page 1 of 1

Using libraries written for Python and C# in Cobra

PostPosted: Mon Aug 27, 2012 8:32 pm
by Rupert
Hi there,

I have two questions regarding Cobra (these are probably obvious, but please bear with me since I am new to any non-MATLAB programming).

1. Is it possible to use libraries written/wrapped for Python in Cobra !?! (I am planning to use libraries like ITK and VTK that are written in C++, but are fully supported in Python. Also, it would be nice if SciPy and NumPy could be used in Cobra.)
2. The two libraries mentioned above (ITK and VTK) are also wrapped for C#. Would it be straightforward to use them in Cobra !?!

Thanks in advance,
Rupert

Re: Using libraries written for Python and C# in Cobra

PostPosted: Tue Aug 28, 2012 8:34 am
by Charles
Cobra is based on .NET and uses its type system. (On our budding JVM back-end, it uses JVM's type system.) So your best bet is the C#-based wrappers. We have already done this in the past with other libs like the .NET bindings for OpenGL.

Generally, you add a reference to the library either at the command line:
Code: Select all
cobra -ref:Foo.Bar MyProgram.cobra


Or in your source code using the @ref directive:
# MyProgram.cobra
@ref Foo.Bar

use Foo.Bar

class Program

def main
pass

You can see above the "use" statement to give immediate access to the namespace in the library. You will generally use this whether you use -ref or @ref. Unless you want to use fully qualified names over and over.

The lib will need to be in the .NET/Mono GAC, or co-exist in the same directory as your program (which provides some insulation re: various versions of libs).

Regarding using Python libraries, we have not spent much time exploring the use of Python libraries for IronPython from Cobra. Last time I checked, the 3rd-party Python libs that wrap up C or C++ libs were not available from IronPython or Jython. And the std libs for Python are pretty much covered either by .NET, Cobra, or 3rd party libs for .NET.

We recently added a MultiList which you can find discussed here which provides functionality similar to NumPy.Array (and Boost.MultiArray, etc.). If there are features missing, or other things from SciPy that are needed, we would be interested in hearing about it.

Re: Using libraries written for Python and C# in Cobra

PostPosted: Sat Sep 08, 2012 10:04 am
by Rupert
Thank you Charles. I have been getting used to Cobra in the last few days and it's a great language - it's almost easier than MATLAB ! I will use the .NET option since that looks quite doable.
Thanks again.

Re: Using libraries written for Python and C# in Cobra

PostPosted: Sat Sep 08, 2012 6:48 pm
by Charles
You're welcome. Keep the questions coming, particularly anything you can't find on the site.