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.
366 lines
11 KiB
Plaintext
366 lines
11 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 Matrix.Elementwise.tt so this file can be regenerated.
|
|
// ======================================================================
|
|
|
|
namespace Accord.Math
|
|
{
|
|
using System;
|
|
using System.CodeDom.Compiler;
|
|
using Accord.Math;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Numerics;
|
|
|
|
// [GeneratedCode("Accord.NET T4 Templates", "3.1")]
|
|
public static partial class Matrix
|
|
{
|
|
<#
|
|
string[][] types =
|
|
{
|
|
new string[] { "int", "Int32", "integer" },
|
|
new string[] { "short", "Int16", "short integer" },
|
|
new string[] { "float", "Single", "single-precision floating point" },
|
|
new string[] { "double", "Double", "double-precision floating point" },
|
|
new string[] { "long", "Int64", "long integer" },
|
|
new string[] { "byte", "Byte", "8-bit byte" },
|
|
new string[] { "sbyte", "SByte", "signed 7-bit byte" },
|
|
new string[] { "decimal", "Decimal", "decimal fixed-point" },
|
|
new string[] { "bool", "Boolean", "boolean" },
|
|
new string[] { "object", "Object", "object" },
|
|
new string[] { "string", "String", "string" },
|
|
new string[] { "Complex", "Complex", "128-bit complex" },
|
|
};
|
|
|
|
foreach (string[] a in types)
|
|
{
|
|
foreach (string[] b in types)
|
|
{
|
|
if (a == b)
|
|
continue;
|
|
|
|
string a_type = a[0];
|
|
string a_name = a[1];
|
|
string a_desc = a[2];
|
|
string b_type = b[0];
|
|
string b_name = b[1];
|
|
string b_desc = b[2];
|
|
|
|
bool a_blittable = a_type != "object" && a_type != "string";
|
|
bool b_blittable = b_type != "object" && b_type != "string";
|
|
|
|
string begin = String.Format("({0})", b_name);
|
|
string end = "";
|
|
|
|
if (a_type == "bool")
|
|
{
|
|
begin = "";
|
|
end = String.Format(" ? ({0})1 : ({0})0", b_name);
|
|
}
|
|
else if (b_type == "bool")
|
|
{
|
|
if (a_type == "object")
|
|
{
|
|
begin = "Object.Equals(";
|
|
end = ", 0)";
|
|
}
|
|
else
|
|
{
|
|
begin = "";
|
|
end = " != 0";
|
|
}
|
|
}
|
|
|
|
if (a_type == "string")
|
|
{
|
|
if (b_type == "Complex")
|
|
{
|
|
continue;
|
|
}
|
|
if (b_type == "object")
|
|
{
|
|
begin = String.Format("({0})System.Convert.ChangeType(", b_name);
|
|
end = String.Format(", typeof({0}))", b_name);
|
|
}
|
|
else
|
|
{
|
|
begin = String.Format("{0}.Parse(", b_name);
|
|
end = ");";
|
|
}
|
|
}
|
|
|
|
if (a_type == "Complex")
|
|
{
|
|
begin = String.Format("({0})", b_name);
|
|
end = ".Real";
|
|
|
|
if (b_type == "bool")
|
|
{
|
|
begin = "";
|
|
end = ".Real != 0";
|
|
}
|
|
}
|
|
|
|
if (b_type == "string")
|
|
{
|
|
begin = "";
|
|
end = ".ToString()";
|
|
}
|
|
|
|
if (a_type == "object")
|
|
{
|
|
begin = String.Format("({0})System.Convert.ChangeType(", b_name);
|
|
end = String.Format(", typeof({0}))", b_name);
|
|
}
|
|
|
|
#>
|
|
/// <summary>
|
|
/// Converts a <#=a_desc#> to a <#=b_desc#>.
|
|
/// </summary>
|
|
///
|
|
#if NET45 || NET46 || NET462 || NETSTANDARD2_0
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
#endif
|
|
public static <#=b_type#>[] To<#=b_name#>(this <#=a_type#>[] value)
|
|
{
|
|
return To<#=b_name#>(value, new <#=b_type#>[value.Length]);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a <#=a_desc#> to a <#=b_desc#>.
|
|
/// </summary>
|
|
///
|
|
#if NET45 || NET46 || NET462 || NETSTANDARD2_0
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
#endif
|
|
public static <#=b_type#>[,] To<#=b_name#>(this <#=a_type#>[,] value)
|
|
{
|
|
return To<#=b_name#>(value, Matrix.CreateAs<<#=a_type#>, <#=b_type#>>(value));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a <#=a_desc#> to a <#=b_desc#>.
|
|
/// </summary>
|
|
///
|
|
#if NET45 || NET46 || NET462 || NETSTANDARD2_0
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
#endif
|
|
public static <#=b_type#>[,,] To<#=b_name#>(this <#=a_type#>[,,] value)
|
|
{
|
|
return To<#=b_name#>(value, Matrix.CreateAs<<#=a_type#>, <#=b_type#>>(value));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a <#=a_desc#> to a <#=b_desc#>.
|
|
/// </summary>
|
|
///
|
|
#if NET45 || NET46 || NET462 || NETSTANDARD2_0
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
#endif
|
|
public static <#=b_type#>[][] To<#=b_name#>(this <#=a_type#>[][] value)
|
|
{
|
|
return To<#=b_name#>(value, Jagged.CreateAs<<#=a_type#>, <#=b_type#>>(value));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a <#=a_desc#> to a <#=b_desc#>.
|
|
/// </summary>
|
|
///
|
|
#if NET45 || NET46 || NET462 || NETSTANDARD2_0
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
#endif
|
|
public static <#=b_type#>[][][] To<#=b_name#>(this <#=a_type#>[][][] value)
|
|
{
|
|
return To<#=b_name#>(value, Jagged.CreateAs<<#=a_type#>, <#=b_type#>>(value));
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Converts a <#=a_desc#> array to a <#=b_desc#> array.
|
|
/// </summary>
|
|
///
|
|
#if NET45 || NET46 || NET462 || NETSTANDARD2_0
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
#endif
|
|
public static <#=b_type#>[] To<#=b_name#>(this <#=a_type#>[] value, <#=b_type#>[] result)
|
|
{
|
|
for (int i = 0; i < value.Length; i++)
|
|
result[i] = <#=begin#>value[i]<#=end#>;
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a multidimensional <#=a_desc#> array to a multidimensional <#=b_desc#> array.
|
|
/// </summary>
|
|
///
|
|
#if NET45 || NET46 || NET462 || NETSTANDARD2_0
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
#endif
|
|
public static <#=b_type#>[,] To<#=b_name#>(this <#=a_type#>[,] value, <#=b_type#>[,] result)
|
|
{
|
|
<#
|
|
if (a_blittable && b_blittable)
|
|
{
|
|
#>
|
|
unsafe
|
|
{
|
|
fixed (<#=a_type#>* src = value)
|
|
fixed (<#=b_type#>* dst = result)
|
|
{
|
|
for (int i = 0; i < value.Length; i++)
|
|
dst[i] = <#=begin#>src[i]<#=end#>;
|
|
}
|
|
}
|
|
<#
|
|
}
|
|
else
|
|
{
|
|
#>
|
|
int r = value.GetLength(0);
|
|
int c = value.GetLength(1);
|
|
for (int i = 0; i < r; i++)
|
|
for (int j = 0; j < c; j++)
|
|
result[i, j] = <#=begin#>value[i, j]<#=end#>;
|
|
<#
|
|
}
|
|
#>
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a multidimensional <#=a_desc#> array to a multidimensional <#=b_desc#> array.
|
|
/// </summary>
|
|
///
|
|
#if NET45 || NET46 || NET462 || NETSTANDARD2_0
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
#endif
|
|
public static <#=b_type#>[,,] To<#=b_name#>(this <#=a_type#>[,,] value, <#=b_type#>[,,] result)
|
|
{
|
|
<#
|
|
if (a_blittable && b_blittable)
|
|
{
|
|
#>
|
|
unsafe
|
|
{
|
|
fixed (<#=a_type#>* src = value)
|
|
fixed (<#=b_type#>* dst = result)
|
|
{
|
|
for (int i = 0; i < value.Length; i++)
|
|
dst[i] = <#=begin#>src[i]<#=end#>;
|
|
}
|
|
}
|
|
<#
|
|
}
|
|
else
|
|
{
|
|
#>
|
|
int r = value.GetLength(0);
|
|
int c = value.GetLength(1);
|
|
int d = value.GetLength(2);
|
|
for (int i = 0; i < r; i++)
|
|
for (int j = 0; j < c; j++)
|
|
for (int k = 0; k < d; k++)
|
|
result[i, j, k] = <#=begin#>value[i, j, k]<#=end#>;
|
|
<#
|
|
}
|
|
#>
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a multidimensional <#=a_desc#> array to a jagged <#=b_desc#> array.
|
|
/// </summary>
|
|
///
|
|
#if NET45 || NET46 || NET462 || NETSTANDARD2_0
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
#endif
|
|
public static <#=b_type#>[][] To<#=b_name#>(this <#=a_type#>[,] value, <#=b_type#>[][] result)
|
|
{
|
|
<#// TODO: Optimize#>
|
|
for (int i = 0; i < result.Length; i++)
|
|
for (int j = 0; j < result[i].Length; j++)
|
|
result[i][j] = <#=begin#>value[i, j]<#=end#>;
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a jagged <#=a_desc#> array to a jagged <#=b_desc#> array.
|
|
/// </summary>
|
|
///
|
|
#if NET45 || NET46 || NET462 || NETSTANDARD2_0
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
#endif
|
|
public static <#=b_type#>[][] To<#=b_name#>(this <#=a_type#>[][] value, <#=b_type#>[][] result)
|
|
{
|
|
for (int i = 0; i < value.Length; i++)
|
|
for (int j = 0; j < value[i].Length; j++)
|
|
result[i][j] = <#=begin#>value[i][j]<#=end#>;
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a jagged <#=a_desc#> array to a jagged <#=b_desc#> array.
|
|
/// </summary>
|
|
///
|
|
#if NET45 || NET46 || NET462 || NETSTANDARD2_0
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
#endif
|
|
public static <#=b_type#>[][][] To<#=b_name#>(this <#=a_type#>[][][] value, <#=b_type#>[][][] result)
|
|
{
|
|
for (int i = 0; i < value.Length; i++)
|
|
for (int j = 0; j < value[i].Length; j++)
|
|
for (int k = 0; k < value[i][j].Length; k++)
|
|
result[i][j][k] = <#=begin#>value[i][j][k]<#=end#>;
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a jagged <#=a_desc#> array to a multidimensional <#=b_desc#> array.
|
|
/// </summary>
|
|
///
|
|
#if NET45 || NET46 || NET462 || NETSTANDARD2_0
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
#endif
|
|
public static <#=b_type#>[,] To<#=b_name#>(this <#=a_type#>[][] value, <#=b_type#>[,] result)
|
|
{
|
|
<#// TODO: Optimize#>
|
|
for (int i = 0; i < value.Length; i++)
|
|
for (int j = 0; j < value[i].Length; j++)
|
|
result[i, j] = <#=begin#>value[i][j]<#=end#>;
|
|
return result;
|
|
}
|
|
<#
|
|
}
|
|
}
|
|
#>
|
|
}
|
|
} |