// Copyright (c) 2020 by Meinrad Recheis (Member of SciSharp)// Code generated by CodeMinion: https://github.com/SciSharp/CodeMinionusing System;using System.Collections;using System.Collections.Generic;using System.IO;using System.Linq;using System.Runtime.InteropServices;using System.Text;using Python.Runtime;using Numpy.Models;#if PYTHON_INCLUDEDusing Python.Included;#endifnamespace Numpy{public partial class PythonObject{//auto-generatedpublic PyTuple ToTuple(Array input){var array = new PyObject[input.Length];for (int i = 0; i < input.Length; i++){array[i]=ToPython(input.GetValue(i));}return new PyTuple(array);}//auto-generatedpublic PyObject ToPython(object obj){if (obj == null) return Runtime.None;switch (obj){// basic typescase int o: return new PyInt(o);case long o: return new PyLong(o);case float o: return new PyFloat(o);case double o: return new PyFloat(o);case string o: return new PyString(o);case bool o: return ConverterExtension.ToPython(o);case PyObject o: return o;// sequence typescase Array o: return ToTuple(o);// special types from 'ToPythonConversions'case Axis o: return o.Axes==null ? null : ToTuple(o.Axes);case Shape o: return ToTuple(o.Dimensions);case Slice o: return o.ToPython();case PythonObject o: return o.PyObject;case Dictionary<string, NDarray> o: return ToDict(o);default: throw new NotImplementedException($"Type is not yet supported: { obj.GetType().Name}. Add it to 'ToPythonConversions'");}}//auto-generatedpublic T ToCsharp<T>(dynamic pyobj){switch (typeof(T).Name){// types from 'ToCsharpConversions'case "Dtype": return (T)(object)new Dtype(pyobj);case "NDarray": return (T)(object)new NDarray(pyobj);case "NDarray`1":switch (typeof(T).GenericTypeArguments[0].Name){case "Byte": return (T)(object)new NDarray<byte>(pyobj);case "Short": return (T)(object)new NDarray<short>(pyobj);case "Boolean": return (T)(object)new NDarray<bool>(pyobj);case "Int32": return (T)(object)new NDarray<int>(pyobj);case "Int64": return (T)(object)new NDarray<long>(pyobj);case "Single": return (T)(object)new NDarray<float>(pyobj);case "Double": return (T)(object)new NDarray<double>(pyobj);default: throw new NotImplementedException($"Type NDarray<{typeof(T).GenericTypeArguments[0].Name}> missing. Add it to 'ToCsharpConversions'");}break;case "NDarray[]":var po = pyobj as PyObject;var len = po.Length();var rv = new NDarray[len];for (int i = 0; i < len; i++)rv[i] = ToCsharp<NDarray>(po[i]);return (T) (object) rv;case "Matrix": return (T)(object)new Matrix(pyobj);default:try{return pyobj.As<T>();}catch (Exception e){throw new NotImplementedException($"conversion from {typeof(T).Name} to {pyobj.__class__} not implemented", e);return default(T);}}}//auto-generatedpublic T SharpToSharp<T>(object obj){if (obj == null) return default(T);switch (obj){// from 'SharpToSharpConversions':case Array a:if (typeof(T)==typeof(NDarray)) return (T)(object)ConvertArrayToNDarray(a);break;}throw new NotImplementedException($"Type is not yet supported: { obj.GetType().Name}. Add it to 'SharpToSharpConversions'");}//auto-generated: SpecialConversionsprivate static NDarray ConvertArrayToNDarray(Array a){switch(a){case bool[] arr: return np.array(arr);case int[] arr: return np.array(arr);case float[] arr: return np.array(arr);case double[] arr: return np.array(arr);case int[,] arr: return np.array(arr.Cast<int>().ToArray()).reshape(arr.GetLength(0), arr.GetLength(1));case float[,] arr: return np.array(arr.Cast<float>().ToArray()).reshape(arr.GetLength(0), arr.GetLength(1));case double[,] arr: return np.array(arr.Cast<double>().ToArray()).reshape(arr.GetLength(0), arr.GetLength(1));case bool[,] arr: return np.array(arr.Cast<bool>().ToArray()).reshape(arr.GetLength(0), arr.GetLength(1));default: throw new NotImplementedException($"Type {a.GetType()} not supported yet in ConvertArrayToNDarray.");}}//auto-generated: SpecialConversionsprivate static PyDict ToDict(Dictionary<string, NDarray> d){var dict = new PyDict();foreach (var pair in d)dict[new PyString(pair.Key)] = pair.Value.self;return dict;}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。