Forums

Using libraries written for Python and C# in Cobra

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Using libraries written for Python and C# in Cobra

Postby Rupert » Mon Aug 27, 2012 8:32 pm

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
Rupert
 
Posts: 2

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

Postby Charles » Tue Aug 28, 2012 8:34 am

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

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

Postby Rupert » Sat Sep 08, 2012 10:04 am

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.
Rupert
 
Posts: 2

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

Postby Charles » Sat Sep 08, 2012 6:48 pm

You're welcome. Keep the questions coming, particularly anything you can't find on the site.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 81 guests