[10088] | 1 | using System;
|
---|
| 2 | using System.Linq;
|
---|
| 3 | using System.Linq.Expressions;
|
---|
| 4 | using Irony.Interpreter;
|
---|
| 5 | using Irony.Parsing;
|
---|
| 6 |
|
---|
| 7 | namespace HeuristicLab.BenchmarkGenerator {
|
---|
| 8 | public class CustomLanguageRuntime : LanguageRuntime {
|
---|
| 9 | public CustomLanguageRuntime(LanguageData data)
|
---|
| 10 | : base(data) {
|
---|
| 11 | }
|
---|
| 12 |
|
---|
| 13 | protected override void InitOperatorImplementations() {
|
---|
| 14 | base.InitOperatorImplementations();
|
---|
| 15 | AddBinary(ExpressionType.AddChecked, typeof(Object[]), (x, y) => ComponentSum((object[])x, (object[])y));
|
---|
| 16 | AddBinary(ExpressionType.SubtractChecked, typeof(Object[]), (x, y) => ComponentDifference((object[])x, (object[])y));
|
---|
| 17 | AddBinary(ExpressionType.MultiplyChecked, typeof(Object[]), (x, y) => ComponentProduct((object[])x, (object[])y));
|
---|
| 18 | AddBinary(ExpressionType.Divide, typeof(Object[]), (x, y) => ComponentDivision((object[])x, (object[])y));
|
---|
| 19 | // AddBinary(ExpressionType.Multiply, typeof(DoubleArray), (x, y) => (DoubleArray)x * (DoubleArray)y);
|
---|
| 20 | // AddBinary(ExpressionType.Add, typeof(DoubleArray), (x, y) => (DoubleArray)x + (DoubleArray)y);
|
---|
| 21 | // AddBinary(ExpressionType.Divide, typeof(DoubleArray), (x, y) => (DoubleArray)x / (DoubleArray)y);
|
---|
| 22 | // AddBinary(ExpressionType.Subtract, typeof(DoubleArray), (x, y) => (DoubleArray)x - (DoubleArray)y);
|
---|
| 23 | // AddConverter(typeof(double[]), typeof(DoubleArray), x => new DoubleArray((double[])x));
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | private object[] ComponentProduct(object[] a, object[] b) {
|
---|
| 27 | var aa = a.Cast<double>();
|
---|
| 28 | var bb = b.Cast<double>();
|
---|
| 29 | return aa.Zip(bb, (v1, v2) => v1 * v2).Cast<object>().ToArray();
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | private object[] ComponentDivision(object[] a, object[] b) {
|
---|
| 33 | var aa = a.Cast<double>();
|
---|
| 34 | var bb = b.Cast<double>();
|
---|
| 35 | return aa.Zip(bb, (v1, v2) => v1 / v2).Cast<object>().ToArray();
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | private object[] ComponentSum(object[] a, object[] b) {
|
---|
| 39 | var aa = a.Cast<double>();
|
---|
| 40 | var bb = b.Cast<double>();
|
---|
| 41 | return aa.Zip(bb, (v1, v2) => v1 + v2).Cast<object>().ToArray();
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | private object[] ComponentDifference(object[] a, object[] b) {
|
---|
| 45 | var aa = a.Cast<double>();
|
---|
| 46 | var bb = b.Cast<double>();
|
---|
| 47 | return aa.Zip(bb, (v1, v2) => v1 - v2).Cast<object>().ToArray();
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 | }
|
---|