using System;
using System.Collections.Generic;
using System.Linq;
public static class Utils
{
public static T Add<T>(T a, T b)
{
if (typeof(T) == typeof(double))
return (T)(object)((double)(object)a + (double)(object)b);
if (typeof(T) == typeof(float))
return (T)(object)((float)(object)a + (float)(object)b);
if (typeof(T) == typeof(int))
return (T)(object)((int)(object)a + (int)(object)b);
throw new Exception("fuck you");
}
}
public class Vector<T>
{
public Vector(int size)
{
Size = size;
}
public int Size { get; set; }
public T[] Data { get; set; }
public Matrix<T> Add<U>(U matrix) where U : Matrix<T>
{
if (matrix.Len2 != Size)
throw new Exception("error");
var data = new List<List<T>>();
for (int i = 0; i < matrix.Len1; i++)
{
var row = new List<T>();
for (int j = 0; j < matrix.Len2; j++)
{
var val1 = matrix.Data[i][j];
var val2 = Data[j];
row.Add(Utils.Add(val1, val2));
}
data.Add(row);
}
return new Matrix<T>(matrix.Len1, matrix.Len2)
{
Data = data.Select(x => x.ToArray()).ToArray()
};
}
}
public class Matrix<T>
{
public Matrix(int len1, int len2)
{
Len1 = len1;
Len2 = len2;
}
public int Len1 { get; set; }
public int Len2 { get; set; }
public T[][] Data { get; set; }
}
public class Test
{
public static void Main()
{
var vector = new Vector<double>(3) { Data = new double[] { 1, 3, 4} };
var matrix = new Matrix<double>(2, 3) { Data = new[] { new double[] { 1, 3, 2 }, new double[] { 34, 2, 4 } } };
var res = vector.Add(matrix);
Console.WriteLine(res.Data[0][1]);
}
}