public static CsClass Generate(CsFile f, int dimension)
        {
            var a = new NdArrayLevel1Generator(f, dimension);

            a.Add_Constructor();
            a.Add_Map();
            return(a._class);
        }
Beispiel #2
0
        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);
        }