System.Collections.Generic.List.Add(ndarray)

Here are the examples of the csharp api System.Collections.Generic.List.Add(ndarray) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 View Source File : Operator.cs
License : Apache License 2.0
Project Creator : deepakkumar1984

public void Invoke(List<ndarray> outputs)
        {
            var paramKeys = new List<string>();
            var paramValues = new List<string>();

            foreach (var data in _KwParams)
            {
                paramKeys.Add(data.Key);
                paramValues.Add(data.Value);
            }

            var numInputs = _InputNdarrays.Count;
            var numOutputs = outputs.Count;

            var outputHandles = outputs.Select(s => s.GetHandle()).ToArray();
            var outputsReceiver = IntPtr.Zero;
            GCHandle? gcHandle = null;
            try
            {
                if (outputs.Count > 0)
                {
                    gcHandle = GCHandle.Alloc(outputHandles, GCHandleType.Pinned);
                    outputsReceiver = gcHandle.Value.AddrOfPinnedObject();
                }

                NDArrayHandle[] outputsReceivers = { outputsReceiver };

                Logging.CHECK_EQ(NativeMethods.MXImperativeInvoke(_Handle, numInputs, _InputNdarrays.ToArray(), ref numOutputs,
                    ref outputsReceiver,
                    paramKeys.Count, paramKeys.ToArray(), paramValues.ToArray()), NativeMethods.OK);

                if (outputs.Count > 0)
                {
                    gcHandle?.Free();
                    return;
                }

                outputHandles = new NDArrayHandle[numOutputs];

                Marshal.Copy(outputsReceiver, outputHandles, 0, numOutputs);

                foreach (var outputHandle in outputHandles) outputs.Add(new ndarray(outputHandle));

                gcHandle?.Free();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                gcHandle?.Free();
            }
        }