Subscribe to this thread
Home - General / All posts - Using System.Numerics[.Vector] namespace in Manifold 9 scripting
tjhb

8,578 post(s)
online
#30-Dec-18 22:24

Is it possible to access System.Numerics[.Vector] classes and methods through the Manifold 9 .NET API?

I am having no luck. Some version of both System.Numerics.dll and System.Numerics.Vector.dll is present on the system, but I don't know if they are visible generally, nor if from Manifold.Context.

Does Manifold 9 target a .NET Framework version prior to the addition of Numerics?

Anyway I don't think System.Numeric.Vector<T> (which is what's really valuable) is available from the Framework, only from Core.

The short answer might be, don't use System.Numerics at least for now. Instead, use Manifold native vector types, that is what they are there for. To enjoy SIMD benefits from a .NET script, write an SQL Command or Expression, which will use native Manifold C++ code and therefore Intel MKL, which uses full-width SIMD whenever possible. (I really don't know.)

tjhb

8,578 post(s)
online
#30-Dec-18 23:06

Correction:

Anyway I don't think System.Numeric.Vector<T> (which is what's really valuable) is not available from the Framework, only from Core.

P.s. I would like to be able to use Numerics from C#, and from IronPython (but I can work out IronPython from C#).

I know I'm all over the place here, not enough of a programmer. Any pointers welcome.

tjhb

8,578 post(s)
online
#31-Dec-18 02:14

Not not, oops.

I am really perplexed why Microsoft are making this so hard. Why is C# not treated as, you know, a product.

As for .NET Core, Standard, and Framework(s), didn't we leave DLL hell behind some time ago?

Not a Manifold problem.

tjhb

8,578 post(s)
online
#01-Jan-19 11:49

Well, publicly airing my ignorance and exasperation seems to have helped. I made progress today and learned a lot (which I should have known before).

My original question was framed wrongly:

Is it possible to access System.Numerics[.Vector] classes and methods through the Manifold 9 .NET API from Manifold 9 .NET scripts?

The answer is: yes and no.

The updated System.Numerics class, provided by System.Numerics.Vectors.dll, is not part of the .NET Framework, but it is not limited to .NET Core, since it can be fetched into a Visual Studio project using NuGet, and if necessary copied from the NuGet cache and reused.

This gives access to the generic vectors and their new methods, and to useful SIMD execution via the Roslyn IL compiler and the RjuJIT native compiler...

Provided that those compilers are in fact being used?

Manifold C# scripts cannot use the new version of Numerics, perhaps because Manifold uses C# 5.0, or because it is using a pre-Roslyn compiler, or for a related reason. If a Manifold C# script includes a reference to the new System.Numerics.Vectors.dll, the compiler seems to become confused, and can't find anything in the System.Numerics namespace. However, it can use the old version (referencing System.Numerics.dll, without generics) just fine.

On the other hand, Manifold IronPython scripts can use the new version. Perhaps because IronPython uses the Dynamic runtime, which in turn uses an up-to-date compiler toolchain? I don't know.

The current version of C# supplied with Visual Studio 2017 can also use the new version. So far I have only tested using the C# REPL, with no problems at all. So an external application using the Manifold 9 API will also be able to use the new Numerics if it wants to.

I'll post a simple project tomorrow. No speed comparisons yet, let alone anything useful, just getting the wiring to work (and not).

tjhb

8,578 post(s)
online
#12-Jan-19 22:10

A quick update on this--mainly to save anyone interested from wasting time on it.

Manifold C# scripts cannot use the new version of Numerics, perhaps because Manifold uses C# 5.0, or because it is using a pre-Roslyn compiler, or for a related reason. If a Manifold C# script includes a reference to the new System.Numerics.Vectors.dll, the compiler seems to become confused, and can't find anything in the System.Numerics namespace. ...

The short answer to this issue is to add System.Numerics.Vectors.dll to the GAC. System.Numerics.dll is already there (various versions).

System.Numerics.Vectors.dll only contains the new System.Numerics.Vector<T> and its methods, and relies on a reference to System.Numerics.dll for the rest of the functions in their shared namespace.

For some reason the C# compiler seems to need them to be in the same place--and it seems that the place must be the GAC. When that requirement is met, then Manifold C# scripts can use the new version of Numerics.

I don't know why IronPython does not mind if the two assemblies are in different places.

By the way JetBrains dotPeek was invaluable for a beginner sorting this out. What a great tool (and free).

adamw


8,401 post(s)
#20-Feb-19 08:13

Late to the thread, sorry.

We are using .NET 4, that's the least advanced / default / base version of .NET guaranteed to be everywhere (well, .NET 2 is even less advanced, but we had .NET 4 a long time ago, it comes by default with all modern versions of Windows so it's safe to rely on it being installed), and that's pre-Roslyn.

We are considering adding $... directives to the script to request a later / side version. However we don't want to be relying on anything above the base version of .NET for our own features, including features in the object model. You can see how messy the picture is currently with eleventy different subdivisions of .NET interacting with each other, it is really frustrating (this also has been going on for years and things are not really improving).

Sum total, you can safely use Vector2 and other things from System.Numerics without any extra hoops right now (they come with system updates, IIRC):

// C#

//

// $reference: system.numerics.dll

// $reference: system.numerics.vectors.dll

 

using N = System.Numerics;

 

class Script

{

 

static Manifold.Context Manifold;

static void Main()

{

  N.Vector2 v2 = new N.Vector2(1f, 3.14f);

  Manifold.Application.Log(v2.ToString());

  Manifold.Application.OpenLog();

}

 

}

But you cannot use the generic versions by default.

We'll see if we can make things better using $... directives.

lionel

560 post(s)
#13-Jan-19 08:19

so manifold implement in SQL /cuda (doc type) what microsoft System.Numerics (doc type ) do for matrix vector !!!

I don't find a lot documentation about howto use vector matrix in manifold but after test ...all is very clear and very easy to combine SQL function / transform template ! But don't find doc howto write transform template but the new way to call sql script variable i think ll be helpfull ..i guess / feel !!

Intel /AMD in every new cpu add more and more register ( storage index) operand ( function) instruction on SIMD architecture ( see flynn taxonomy) to compute here many value at once ( parallel) in different domain ( mainly audio video instruction ). Following intel( not AMD) history we have in intel platform MME , SSE and now AVX ( for vector) .

The question is : Does compiler , sdk , framework ( system.Numerics.Vector ) support hardware AVX instruction !!

A old article here help us understand better the context and this post ( that deal with performance / speed) and understand the valuable information post here !! thank's a lot tjhb for this post ( and many others i like to study/ understand ) !!


join image

"Because my dad promised me" ( interstellar ) but blackhole don't exist

best hardware with no ads focus on quality features price like manifold see xiaomi

lionel

560 post(s)
#13-Jan-19 08:46

microsoft OS ll change a lot when understand that microsoft want dev tool that target both android and apple OS ( winphone is dead) . I am very happy to see more and more microsoft application for android or Apple OS . For example a Microsoft app let us change android desktop layout to have microsoft look and feel . In the same time google add new tools in microsoft OS to avoid to use ( buy) microsoft RDP or teamviewer by using chrome browser !! apple fight against some application like google map but Apple have to be more ll be more open to not death ( airplay 2 is available in TV 2019 and wireless audio device !! ..)

here infography about the future of microsoft .. even not really show cpu instruction but let us undertand some words like ryuJIT , nuget and that "core" word has differents meanings ...

Attachments:
microsoft_infrastructure.png


join image

"Because my dad promised me" ( interstellar ) but blackhole don't exist

best hardware with no ads focus on quality features price like manifold see xiaomi

lionel

560 post(s)
#13-Jan-19 10:35

about array vector vectorization

An Arraycan store only homogeneous values.

A Vector is an instruction operand containing a set of data elements packed into a one-dimensional array. Vectors can store any type of objects,

Vectorization is the process of converting an algorithm from operating on a single value at a time to operating on a set of values (vector) at one time

about matrix data frame

in a matrix, all columns must have the same data type (numeric, character, etc.) and the same length.

in data framecolumns can have differents modes (numeric, character, factor, etc.). Just like a table in a database or excel sheet or in R.

mathematic library


join image

"Because my dad promised me" ( interstellar ) but blackhole don't exist

best hardware with no ads focus on quality features price like manifold see xiaomi

lionel

560 post(s)
#13-Jan-19 10:57

there is really a lot to know about SIMD and System.Numerics[.Vector] and what i write is really a little part of the subject ( old point of view of a developper here here performance test here another library toon )


join image

"Because my dad promised me" ( interstellar ) but blackhole don't exist

best hardware with no ads focus on quality features price like manifold see xiaomi

Manifold User Community Use Agreement Copyright (C) 2007-2017 Manifold Software Limited. All rights reserved.