NumSharp icon indicating copy to clipboard operation
NumSharp copied to clipboard

Unable to use np.dot due to "Specified method unsupported" error

Open moonlitlyra opened this issue 5 years ago • 4 comments

I have recently been working on a unity project involving the genetic algorithm, but have run into an error while trying to use the function np.dot(). NumSharp has been installed using the NuGet client NuGetForUnity

The error message is as follows:

NotSupportedException: Specified method is not supported. NumSharp.NPTypeCodeExtensions.GetAccumulatingType (NumSharp.NPTypeCode typeCode) (at <7807b007e09c46aca587061f8867e538>:0) NumSharp.Backends.DefaultEngine.ReduceAdd (NumSharp.NDArray& arr, System.Nullable1[T] axis_, System.Boolean keepdims, System.Nullable1[T] typeCode, NumSharp.NDArray out) (at <7807b007e09c46aca587061f8867e538>:0) NumSharp.Backends.DefaultEngine.Sum (NumSharp.NDArray& nd, System.Nullable1[T] axis, System.Nullable1[T] typeCode, System.Boolean keepdims) (at <7807b007e09c46aca587061f8867e538>:0) NumSharp.np.sum (NumSharp.NDArray& a, System.Int32 axis) (at <7807b007e09c46aca587061f8867e538>:0) NumSharp.Backends.DefaultEngine.Dot (NumSharp.NDArray& left, NumSharp.NDArray& right) (at <7807b007e09c46aca587061f8867e538>:0) NumSharp.np.dot (NumSharp.NDArray& a, NumSharp.NDArray& b) (at <7807b007e09c46aca587061f8867e538>:0) NN.FeedForward () (at Assets/scripts/NeuralNetwork.cs:73) Bot.FixedUpdate () (at Assets/scripts/Bot.cs:70)

Line 73 of the FeedForward script:

  1. NDArray activations = np.dot(layers[i].weights, layers[i].activations);

Other sections of relevant code:

  1. layer.weights = np.random.rand(3, 2);
  2. layer.activations = np.zeros(2);

moonlitlyra avatar Mar 27 '21 17:03 moonlitlyra

Related to #447

Nucs avatar Apr 14 '21 11:04 Nucs

I seem to have this same issue, in a similar context attempting to use np.dot to do a dot-product for two 1-D numpy arrays containing double values. Assuming we're not both doing something wrong, any workarounds beside calculating the dot product manually?

System.NotSupportedException HResult=0x80131515 Message=Specified method is not supported. Source=NumSharp StackTrace: at NumSharp.NPTypeCodeExtensions.GetAccumulatingType(NPTypeCode typeCode) at NumSharp.Backends.DefaultEngine.sum_elementwise(NDArray arr, Nullable1 typeCode) at NumSharp.Backends.DefaultEngine.ReduceAdd(NDArray& arr, Nullable1 axis_, Boolean keepdims, Nullable`1 typeCode, NDArray out) at NumSharp.Backends.DefaultEngine.Dot(NDArray& left, NDArray& right)

BlackholeGH avatar Jun 27 '21 10:06 BlackholeGH

I seem to have this same issue, in a similar context attempting to use np.dot to do a dot-product for two 1-D numpy arrays containing double values. Assuming we're not both doing something wrong, any workarounds beside calculating the dot product manually?

System.NotSupportedException HResult=0x80131515 Message=Specified method is not supported. Source=NumSharp StackTrace: at NumSharp.NPTypeCodeExtensions.GetAccumulatingType(NPTypeCode typeCode) at NumSharp.Backends.DefaultEngine.sum_elementwise(NDArray arr, Nullable1 typeCode) at NumSharp.Backends.DefaultEngine.ReduceAdd(NDArray& arr, Nullable1 axis_, Boolean keepdims, Nullable`1 typeCode, NDArray out) at NumSharp.Backends.DefaultEngine.Dot(NDArray& left, NDArray& right)

Hello, thankyou for commenting on this issue. No workarounds as far as I am aware, I ended up having to scrap part of my project sadly. Thanks anyway.

moonlitlyra avatar Jun 30 '21 18:06 moonlitlyra

This has been fixed. np.dot now works for 2D matrix multiplication:

var a = np.array(new double[,] { { 1, 2 }, { 3, 4 } });
var b = np.array(new double[,] { { 5, 6 }, { 7, 8 } });
var result = np.dot(a, b);  // Works - shape (2,2)

Resolved via #600, #602, #603, #596.

Nucs avatar Apr 12 '26 05:04 Nucs