Skip to content

Commit a961d9e

Browse files
committed
Fix CodeGenerator
1 parent c9741a1 commit a961d9e

5 files changed

Lines changed: 25 additions & 86 deletions

File tree

src/CodeMinion.Core/CodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ private void GenToPython(CodeWriter s, bool @static=false)
10231023
{
10241024
s.Out("// basic types");
10251025
s.Out("case int o: return new PyInt(o);");
1026-
s.Out("case long o: return new PyLong(o);");
1026+
s.Out("case long o: return new PyInt(o);");
10271027
s.Out("case float o: return new PyFloat(o);");
10281028
s.Out("case double o: return new PyFloat(o);");
10291029
s.Out("case string o: return new PyString(o);");

src/Numpy/Models/NDarray.gen.cs

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6187,80 +6187,6 @@ public NDarray ediff1d(NDarray to_end = null, NDarray to_begin = null)
61876187
return ToCsharp<NDarray>(py);
61886188
}
61896189

6190-
/// <summary>
6191-
/// Return the gradient of an N-dimensional array.<br></br>
6192-
///
6193-
/// The gradient is computed using second order accurate central differences
6194-
/// in the interior points and either first or second order accurate one-sides
6195-
/// (forward or backwards) differences at the boundaries.<br></br>
6196-
///
6197-
/// The returned gradient hence has the same shape as the input array.<br></br>
6198-
///
6199-
/// Notes
6200-
///
6201-
/// Assuming that (i.e., has at least 3 continuous
6202-
/// derivatives) and let be a non-homogeneous stepsize, we
6203-
/// minimize the “consistency error” between the true gradient
6204-
/// and its estimate from a linear combination of the neighboring grid-points:
6205-
///
6206-
/// By substituting and
6207-
/// with their Taylor series expansion, this translates into solving
6208-
/// the following the linear system:
6209-
///
6210-
/// The resulting approximation of is the following:
6211-
///
6212-
/// It is worth noting that if
6213-
/// (i.e., data are evenly spaced)
6214-
/// we find the standard second order approximation:
6215-
///
6216-
/// With a similar procedure the forward/backward approximations used for
6217-
/// boundaries can be derived.<br></br>
6218-
///
6219-
/// References
6220-
/// </summary>
6221-
/// <param name="varargs">
6222-
/// Spacing between f values.<br></br>
6223-
/// Default unitary spacing for all dimensions.<br></br>
6224-
///
6225-
/// Spacing can be specified using:
6226-
///
6227-
/// If axis is given, the number of varargs must equal the number of axes.<br></br>
6228-
///
6229-
/// Default: 1.
6230-
/// </param>
6231-
/// <param name="edge_order">
6232-
/// Gradient is calculated using N-th order accurate differences
6233-
/// at the boundaries.<br></br>
6234-
/// Default: 1.
6235-
/// </param>
6236-
/// <param name="axis">
6237-
/// Gradient is calculated only along the given axis or axes
6238-
/// The default (axis = None) is to calculate the gradient for all the axes
6239-
/// of the input array.<br></br>
6240-
/// axis may be negative, in which case it counts from
6241-
/// the last to the first axis.
6242-
/// </param>
6243-
/// <returns>
6244-
/// A set of ndarrays (or a single ndarray if there is only one dimension)
6245-
/// corresponding to the derivatives of f with respect to each dimension.<br></br>
6246-
///
6247-
/// Each derivative has the same shape as f.
6248-
/// </returns>
6249-
public NDarray gradient(NDarray varargs = null, int? edge_order = null, Axis axis = null)
6250-
{
6251-
//auto-generated code, do not change
6252-
var __self__=self;
6253-
var pyargs=ToTuple(new object[]
6254-
{
6255-
varargs,
6256-
});
6257-
var kwargs=new PyDict();
6258-
if (edge_order!=null) kwargs["edge_order"]=ToPython(edge_order);
6259-
if (axis!=null) kwargs["axis"]=ToPython(axis);
6260-
dynamic py = __self__.InvokeMethod("gradient", pyargs, kwargs);
6261-
return ToCsharp<NDarray>(py);
6262-
}
6263-
62646190
/// <summary>
62656191
/// Return the cross product of two (arrays of) vectors.<br></br>
62666192
///

src/Numpy/Models/PythonObject.gen.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,22 @@ public T ToCsharp<T>(dynamic pyobj)
8787
return (T) (object) rv;
8888
case "Matrix": return (T)(object)new Matrix(pyobj);
8989
default:
90+
var pyClass = $"{pyobj.__class__}";
91+
if (pyClass == "<class 'str'>")
92+
{
93+
return (T)(object)pyobj.ToString();
94+
}
95+
if (pyClass.StartsWith("<class 'numpy"))
96+
{
97+
return (pyobj.item() as PyObject).As<T>();
98+
}
9099
try
91100
{
92101
return pyobj.As<T>();
93102
}
94103
catch (Exception e)
95104
{
96-
throw new NotImplementedException($"conversion from {typeof(T).Name} to {pyobj.__class__} not implemented", e);
105+
throw new NotImplementedException($"conversion from {pyobj.__class__} to {typeof(T).Name} not implemented", e);
97106
return default(T);
98107
}
99108
}

src/Numpy/np.math.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,7 @@ public static NDarray ediff1d(NDarray ary, NDarray to_end = null, NDarray to_beg
19461946
dynamic py = __self__.InvokeMethod("ediff1d", pyargs, kwargs);
19471947
return ToCsharp<NDarray>(py);
19481948
}
1949-
1949+
19501950
/// <summary>
19511951
/// Return the cross product of two (arrays of) vectors.<br></br>
19521952
///

src/Numpy/np.module.gen.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,20 @@ internal static T ToCsharp<T>(dynamic pyobj)
123123
for (int i = 0; i < len; i++)
124124
rv[i] = ToCsharp<NDarray>(po[i]);
125125
return (T) (object) rv;
126-
case "Matrix":
127-
return (T)(object)new Matrix(pyobj);
126+
case "Matrix": return (T)(object)new Matrix(pyobj);
128127
default:
129-
try {
130-
var pyClass = $"{pyobj.__class__}";
131-
if (pyClass == "<class 'str'>")
132-
return (T)(object)pyobj.ToString();
133-
if (pyClass.StartsWith("<class 'numpy"))
134-
return (pyobj.item() as PyObject).As<T>();
135-
return (pyobj as PyObject).As<T>();
128+
var pyClass = $"{pyobj.__class__}";
129+
if (pyClass == "<class 'str'>")
130+
{
131+
return (T)(object)pyobj.ToString();
132+
}
133+
if (pyClass.StartsWith("<class 'numpy"))
134+
{
135+
return (pyobj.item() as PyObject).As<T>();
136+
}
137+
try
138+
{
139+
return pyobj.As<T>();
136140
}
137141
catch (Exception e)
138142
{

0 commit comments

Comments
 (0)