private void Add_ArrayMethods(CsClass cl) { /* [DirectCall("array")] * public static NdArray2D<int> Array( * IEnumerable<IEnumerable<int>> obj, * bool copy = true, * NumpyArrayOrder order = NumpyArrayOrder.K) * { * return NdArray.Make(obj, copy, order); * }*/ var f = CreateFile(); f.AddImportNamespace("System.Collections.Generic"); f.AddImportNamespace("System.Linq"); for (var dimension = 1; dimension <= MaxDim; dimension++) { NdArrayLevel1Generator.Generate(f, dimension); foreach (var wrappedType in NumpyArrayWrappedTypes) { var classLevel2 = NdArrayLevel2Generator.Generate(f, dimension, wrappedType); var resultType = classLevel2.Name; var m = cl.AddMethod("Array" + dimension, resultType) .WithDirectCall("array") .WithStatic() .WithBodyComment($"Generated by {nameof(NumpyGenerator)}.{nameof(Add_ArrayMethods)}/1") .WithBody($"return new {resultType}(obj, copy, order);"); NdArrayLevel2Generator.WithAddParams(m, wrappedType, dimension); } // other types { const string wrappedType = "T"; // var classLevel2 = NdArrayLevel2Generator.Generate(f, dimension, wrappedType); foreach (var i in new[] { true }) { var resultType = $"NdArray{dimension}D<T>"; var m = cl.AddMethod("Array" + (i ? $"{dimension}" : "") + "<T>", resultType) .WithDirectCall("array") .WithStatic() .WithBodyComment($"Generated by {nameof(NumpyGenerator)}.{nameof(Add_ArrayMethods)}/2") .WithBody($"return new {resultType}(obj, copy, order);"); NdArrayLevel2Generator.WithAddParams(m, wrappedType, dimension); } } } var fileName = Path.Combine(BasePath.FullName, "Lang.Python", "+compatibility", "Numpy", "NdArray.Auto.cs"); f.SaveIfDifferent(fileName); }
private void Add_Constructor() { var co = _class.AddConstructor(); NdArrayLevel2Generator.WithAddParams(co, "T", _dimension); if (_dimension == 1) { co.WithBody("InternalData = obj.ToIListCastOrConvert();"); } // protected co = _class.AddConstructor(); co.Visibility = Visibilities.Internal; co.AddParam("internalData", "IList<T>"); co.AddParam("shapeInfo", "NdArrayShapeInfo"); co.Body = " InternalData = internalData; ShapeInfo = shapeInfo;"; }