mirror of
https://github.com/hanzoai/jube-fork.git
synced 2026-10-30 18:33:33 +00:00
Included open-source Accord.net library code natively to the solution given the deprecated state of that project. Accord.net will be supported inside Jube for own needs (such as upgrading to .Net 7+). Accord.net libraries modified to compile to .Net 6. Modified Accord.net libraries to better support Newtonsoft Json.net serialisation. Included annotations in the Accord.net libraries to house important dependency statistics. Serialised json can be used independently of Jube to recall a Neural Network. Removal of Binary Serializer totally as a precursor to the projects support of .Net 7+. Extensive bug fixing in crucial functions of Neural Network training and recall. While this part of the system remains in Alpha, it is substantially more fit for purpose.
390 lines
12 KiB
Plaintext
390 lines
12 KiB
Plaintext
<#@ template debug="false" hostspecific="true" language="C#" #>
|
|
<#@ output extension="Generated.cs" #>
|
|
<#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
|
|
<#@ include file="T4Toolbox.tt" #>
|
|
// Accord Math Library
|
|
// The Accord.NET Framework
|
|
// http://accord-framework.net
|
|
//
|
|
// Copyright © César Souza, 2009-2017
|
|
// cesarsouza at gmail.com
|
|
//
|
|
// This library is free software; you can redistribute it and/or
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
// License as published by the Free Software Foundation; either
|
|
// version 2.1 of the License, or (at your option) any later version.
|
|
//
|
|
// This library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
// Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
// License along with this library; if not, write to the Free Software
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
//
|
|
|
|
// ======================================================================
|
|
// This code has been generated by a tool; do not edit manually. Instead,
|
|
// edit the T4 template Vector.Range.tt so this file can be regenerated.
|
|
// ======================================================================
|
|
|
|
|
|
namespace Accord.Math
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Accord.Math;
|
|
|
|
public static partial class Vector
|
|
{
|
|
<#
|
|
string[] types = { "int", "float", "double", "short", "byte", "sbyte", "long", "decimal", "ulong", "ushort" };
|
|
|
|
Func<string, bool> isWhole = (s) =>
|
|
{
|
|
switch (s)
|
|
{
|
|
case "int":
|
|
case "short":
|
|
case "byte":
|
|
case "sbyte":
|
|
case "long":
|
|
case "ulong":
|
|
case "ushort":
|
|
return true;
|
|
case "float":
|
|
case "double":
|
|
case "decimal":
|
|
return false;
|
|
}
|
|
|
|
throw new Exception("Unexpected type.");
|
|
};
|
|
|
|
string remarks = @" ///
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The Range methods should be equivalent to NumPy's np.arange method, with one
|
|
/// single difference: when the intervals are inverted (i.e. a > b) and the step
|
|
/// size is negative, the framework still iterates over the range backwards, as
|
|
/// if the step was negative.</para>
|
|
/// <para>
|
|
/// This function never includes the upper bound of the range. For methods
|
|
/// that include it, please see the <see cref=""Interval(int, int)""/> methods.</para>
|
|
/// </remarks>
|
|
///
|
|
/// <seealso cref=""Interval(int, int)""/>
|
|
///";
|
|
|
|
foreach (string i in types)
|
|
{
|
|
#>
|
|
|
|
/// <summary>
|
|
/// Creates a range vector (like NumPy's arange function).
|
|
/// </summary>
|
|
///
|
|
/// <param name="n">The exclusive upper bound of the range.</param>
|
|
<#=remarks#>
|
|
public static <#=i#>[] Range(<#=i#> n)
|
|
{
|
|
<#=i#>[] r = new <#=i#>[(int)n];
|
|
for (int i = 0; i < r.Length; i++)
|
|
r[i] = (<#=i#>)i;
|
|
return r;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a range vector (like NumPy's arange function).
|
|
/// </summary>
|
|
///
|
|
/// <param name="a">The inclusive lower bound of the range.</param>
|
|
/// <param name="b">The exclusive upper bound of the range.</param>
|
|
<#=remarks#>
|
|
public static <#=i#>[] Range(<#=i#> a, <#=i#> b)
|
|
{
|
|
if (a == b)
|
|
return new <#=i#>[] { };
|
|
|
|
<#=i#>[] r;
|
|
|
|
if (b > a)
|
|
{
|
|
r = new <#=i#>[(int)(b - a)];
|
|
for (int i = 0; i < r.Length; i++)
|
|
r[i] = (<#=i#>)(a++);
|
|
}
|
|
else
|
|
{
|
|
r = new <#=i#>[(int)(a - b)];
|
|
for (int i = 0; i < r.Length; i++)
|
|
r[i] = (<#=i#>)(a--);
|
|
}
|
|
|
|
return r;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Enumerates through a range (like Python's xrange function).
|
|
/// </summary>
|
|
///
|
|
/// <param name="n">The exclusive upper bound of the range.</param>
|
|
<#=remarks#>
|
|
public static IEnumerable<<#=i#>> EnumerableRange(<#=i#> n)
|
|
{
|
|
for (<#=i#> i = 0; i < n; i++)
|
|
yield return (<#=i#>)i;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Enumerates through a range (like Python's xrange).
|
|
/// </summary>
|
|
///
|
|
/// <param name="a">The inclusive lower bound of the range.</param>
|
|
/// <param name="b">The exclusive upper bound of the range.</param>
|
|
<#=remarks#>
|
|
public static IEnumerable<<#=i#>> EnumerableRange(<#=i#> a, <#=i#> b)
|
|
{
|
|
if (a == b)
|
|
yield break;
|
|
|
|
if (b > a)
|
|
{
|
|
int n = (int)(b - a);
|
|
for (int i = 0; i < n; i++)
|
|
yield return (<#=i#>)(a++);
|
|
}
|
|
else
|
|
{
|
|
int n = (int)(a - b);
|
|
for (int i = 0; i < n; i++)
|
|
yield return (<#=i#>)(a--);
|
|
}
|
|
}
|
|
|
|
<#
|
|
foreach (string s in types)
|
|
{
|
|
string r = i;
|
|
if (isWhole(i) || !isWhole(s))
|
|
r = s;
|
|
else if (!isWhole(i) || isWhole(s))
|
|
r = i;
|
|
else if (i != s)
|
|
continue;
|
|
|
|
if (i == "decimal" ^ s == "decimal")
|
|
continue;
|
|
if (isWhole(i) == isWhole(s) && i != s)
|
|
continue;
|
|
|
|
string c = "double";
|
|
if (isWhole(i) && !isWhole(s))
|
|
{
|
|
c = s;
|
|
}
|
|
else if (!isWhole(i) && isWhole(s))
|
|
{
|
|
c = i;
|
|
}
|
|
else if (isWhole(i) && isWhole(s))
|
|
{
|
|
if (i != s)
|
|
continue;
|
|
c = "double";
|
|
}
|
|
else if (!isWhole(i) && !isWhole(s))
|
|
{
|
|
if (i == "decimal" || s == "decimal")
|
|
c = "decimal";
|
|
}
|
|
#>
|
|
|
|
/// <summary>
|
|
/// Creates a range vector (like NumPy's arange function).
|
|
/// </summary>
|
|
///
|
|
/// <param name="a">The inclusive lower bound of the range.</param>
|
|
/// <param name="b">The exclusive upper bound of the range.</param>
|
|
/// <param name="stepSize">The step size to be taken between elements.
|
|
/// This parameter can be negative to create a decreasing range.</param>
|
|
<#=remarks#>
|
|
public static <#=r#>[] Range(<#=i#> a, <#=i#> b, <#=s#> stepSize)
|
|
{
|
|
if (a == b)
|
|
return new <#=r#>[] { };
|
|
|
|
if (stepSize == 0)
|
|
throw new ArgumentOutOfRangeException("stepSize", "stepSize must be different from zero.");
|
|
|
|
<#=r#>[] r;
|
|
|
|
if (a < b)
|
|
{
|
|
if (stepSize < 0)
|
|
throw new ArgumentOutOfRangeException("stepSize", "If a < b, stepSize must be positive.");
|
|
|
|
uint steps = (uint)System.Math.Ceiling(((<#=c#>)(b - a) / (<#=c#>)stepSize));
|
|
|
|
r = new <#=r#>[steps];
|
|
for (uint i = 0; i < r.Length; i++)
|
|
r[i] = (<#=r#>)(a + i * stepSize);
|
|
}
|
|
else
|
|
{
|
|
if (stepSize > 0)
|
|
{
|
|
uint steps = (uint)System.Math.Ceiling(((<#=c#>)(a - b) / (<#=c#>)stepSize));
|
|
r = new <#=r#>[steps];
|
|
for (uint i = 0; i < r.Length; i++)
|
|
r[i] = (<#=r#>)(a - i * stepSize);
|
|
}
|
|
else
|
|
{
|
|
uint steps = (uint)System.Math.Ceiling(((<#=c#>)(b - a) / (<#=c#>)stepSize));
|
|
r = new <#=r#>[steps];
|
|
for (uint i = 0; i < r.Length; i++)
|
|
r[i] = (<#=r#>)(a + i * stepSize);
|
|
}
|
|
}
|
|
|
|
if (a < b)
|
|
{
|
|
if (r[r.Length - 1] > b)
|
|
r[r.Length - 1] = b;
|
|
}
|
|
else
|
|
{
|
|
if (r[r.Length - 1] > a)
|
|
r[r.Length - 1] = a;
|
|
}
|
|
|
|
return r;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Enumerates through a range (like Python's xrange function).
|
|
/// </summary>
|
|
///
|
|
/// <param name="a">The inclusive lower bound of the range.</param>
|
|
/// <param name="b">The exclusive upper bound of the range.</param>
|
|
/// <param name="stepSize">The step size to be taken between elements.
|
|
/// This parameter can be negative to create a decreasing range.</param>
|
|
<#=remarks#>
|
|
public static IEnumerable<<#=r#>> EnumerableRange(<#=i#> a, <#=i#> b, <#=s#> stepSize)
|
|
{
|
|
if (a == b)
|
|
yield break;
|
|
|
|
if (stepSize == 0)
|
|
throw new ArgumentOutOfRangeException("stepSize", "stepSize must be different from zero.");
|
|
|
|
<#=r#> last;
|
|
|
|
if (a < b)
|
|
{
|
|
if (stepSize < 0)
|
|
throw new ArgumentOutOfRangeException("stepSize", "If a < b, stepSize must be positive.");
|
|
|
|
uint steps = (uint)System.Math.Ceiling(((<#=c#>)(b - a) / (<#=c#>)stepSize)) - 1;
|
|
for (uint i = 0; i < steps; i++)
|
|
yield return (<#=r#>)(a + i * stepSize);
|
|
last = (<#=r#>)(a + steps * stepSize);
|
|
}
|
|
else
|
|
{
|
|
if (stepSize > 0)
|
|
{
|
|
uint steps = (uint)System.Math.Ceiling(((<#=c#>)(a - b) / (<#=c#>)stepSize)) - 1;
|
|
for (uint i = 0; i < steps; i++)
|
|
yield return (<#=r#>)(a - i * stepSize);
|
|
last = (<#=r#>)(a - steps * stepSize);
|
|
}
|
|
else
|
|
{
|
|
uint steps = (uint)System.Math.Ceiling(((<#=c#>)(b - a) / (<#=c#>)stepSize)) - 1;
|
|
for (uint i = 0; i < steps; i++)
|
|
yield return (<#=r#>)(a + i * stepSize);
|
|
last = (<#=r#>)(a + steps * stepSize);
|
|
}
|
|
}
|
|
|
|
if (a < b)
|
|
{
|
|
yield return last > b ? b : last;
|
|
}
|
|
else
|
|
{
|
|
yield return last > a ? a : last;
|
|
}
|
|
}
|
|
<#
|
|
}
|
|
}
|
|
|
|
string[] ranges = { "DoubleRange", "Range", "ByteRange", "IntRange" };
|
|
string[] rtypes = { "double", "float", "byte", "int" };
|
|
|
|
for (int k = 0; k < ranges.Length; k++)
|
|
{
|
|
string i = ranges[k];
|
|
string t = rtypes[k];
|
|
#>
|
|
|
|
/// <summary>
|
|
/// Creates a range vector (like NumPy's arange function).
|
|
/// </summary>
|
|
///
|
|
/// <param name="range">The range from where values should be created.</param>
|
|
<#=remarks#>
|
|
public static <#=t#>[] Range(this <#=i#> range)
|
|
{
|
|
return Range(range.Min, range.Max);
|
|
}
|
|
|
|
<#
|
|
for (int j = 0; j < ranges.Length; j++)
|
|
{
|
|
string s = rtypes[j];
|
|
|
|
string r = t;
|
|
if (isWhole(t) && !isWhole(s))
|
|
{
|
|
r = s;
|
|
}
|
|
else if (!isWhole(t) && isWhole(s))
|
|
{
|
|
r = t;
|
|
}
|
|
else if (isWhole(t) && isWhole(s))
|
|
{
|
|
if (t != s)
|
|
continue;
|
|
}
|
|
else if (!isWhole(t) && !isWhole(s))
|
|
{
|
|
if (t == "decimal" || s == "decimal")
|
|
r = "decimal";
|
|
if (t == "double" || s == "double")
|
|
r = "double";
|
|
}
|
|
#>
|
|
/// <summary>
|
|
/// Creates a range vector (like NumPy's arange function).
|
|
/// </summary>
|
|
///
|
|
/// <param name="range">The range from where values should be created.</param>
|
|
/// <param name="stepSize">The step size to be taken between elements.
|
|
/// This parameter can be negative to create a decreasing range.</param>
|
|
<#=remarks#>
|
|
public static <#=r#>[] Range(this <#=i#> range, <#=s#> stepSize)
|
|
{
|
|
return Range(range.Min, range.Max, stepSize);
|
|
}
|
|
<#
|
|
}
|
|
}
|
|
#>
|
|
}
|
|
} |