Skip to content

Commit 6e49fb3

Browse files
Merge pull request #69 from marcin-golebiowski/development
Add RemapFunctions to DerivativesHelper
2 parents b2498bb + fdd8d8e commit 6e49fb3

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

SpiceSharpBehavioral/Parsers/Nodes/DerivativesHelper.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static class DerivativesHelper
1212
/// <summary>
1313
/// The default function rules.
1414
/// </summary>
15-
public static readonly Dictionary<string, FunctionRule> Defaults = new Dictionary<string, FunctionRule>
15+
public static Dictionary<string, FunctionRule> Defaults { get; set; } = new Dictionary<string, FunctionRule>(StringComparer.OrdinalIgnoreCase)
1616
{
1717
{ "abs", (f, da) => Derivatives.ChainRule(f, da.Check(1), "sgn") },
1818
{ "sgn", Zero },
@@ -52,6 +52,20 @@ public static class DerivativesHelper
5252
{ "arg", (f, da) => DAtan2(f, new[] { Node.Function("imag", da.Check(1)[0]), Node.Function("real", da[0]) }) },
5353
};
5454

55+
/// <summary>
56+
/// Helper methods that changes the equality comparer for function names.
57+
/// </summary>
58+
/// <param name="comparer">The name comparer.</param>
59+
public static void RemapFunctions(IEqualityComparer<string> comparer)
60+
{
61+
var nmap = new Dictionary<string, FunctionRule>(comparer);
62+
foreach (var map in Defaults)
63+
{
64+
nmap.Add(map.Key, map.Value);
65+
}
66+
Defaults = nmap;
67+
}
68+
5569
private static IReadOnlyList<Node> Check(this IReadOnlyList<Node> arguments, int expected)
5670
{
5771
if (arguments == null || arguments.Count != expected)

0 commit comments

Comments
 (0)