/// <summary> /// MSTS WFiles represent some location with a position, 3x3 matrix and tile coordinates /// This converts it to the ORTS WorldPosition representation /// </summary> internal static WorldPosition WorldPositionFromMSTSLocation(PositionHolder holder, uint uid) { if (holder.LocationSet && holder.PositionSet) { holder.Location.Z *= -1;; Matrix xnaMatrix = new Matrix( holder.Position.M00, holder.Position.M01, -holder.Position.M02, 0, holder.Position.M10, holder.Position.M11, -holder.Position.M12, 0, -holder.Position.M20, -holder.Position.M21, holder.Position.M22, 0, 0, 0, 0, 1); return(new WorldPosition(holder.TileX, holder.TileZ, MatrixExtension.Multiply(xnaMatrix, Matrix.CreateTranslation(holder.Location)))); } else if (holder.LocationSet && holder.DirectionSet) { holder.Direction.Z *= -1; holder.Location.Z *= -1;; return(new WorldPosition(holder.TileX, holder.TileZ, MatrixExtension.Multiply(Matrix.CreateFromQuaternion(holder.Direction), Matrix.CreateTranslation(holder.Location)))); } else { Trace.TraceWarning($"Scenery object UiD {uid} is missing Matrix3x3 and QDirection"); return(WorldPosition.None); } }
public int[] GetIntevalSteps(TimeUnits time) { if (time == TimeUnits.Day) { var inteval = new int[Timeline.Count]; MatrixExtension <int> .Set(inteval, 1); return(inteval); } else if (time == TimeUnits.Month) { var derivedValues = Timeline.GroupBy(t => new { t.Year, t.Month }).Select(group => group.Count()); var inteval = derivedValues.ToArray(); return(inteval); } else if (time == TimeUnits.CommanYear) { var derivedValues = Timeline.GroupBy(t => new { t.Year }).Select(group => group.Count()); var inteval = derivedValues.ToArray(); return(inteval); } return(null); }
public int[] GetIntevalSteps(TimeUnits time, int maxstep) { int count = Timeline.Count; if (maxstep < Timeline.Count) { count = maxstep; } if (time == TimeUnits.Day) { var inteval = new int[count]; MatrixExtension <int> .Set(inteval, 1); return(inteval); } else if (time == TimeUnits.Month) { var list = Timeline; if (maxstep < Timeline.Count) { var newlist = new List <DateTime>(); for (int i = 0; i < maxstep; i++) { newlist.Add(Timeline[i]); } list = newlist; } var derivedValues = list.GroupBy(t => new { t.Year, t.Month }).Select(group => group.Count()); var inteval = derivedValues.ToArray(); return(inteval); } return(null); }
public SquareMatrix <int> AddSquaresMatrixTest(int[,] arr1, int[,] arr2) { var lhs = new SquareMatrix <int>(arr1); var rhs = new SquareMatrix <int>(arr1); return(MatrixExtension.Add(lhs, rhs)); }
public SquareMatrix <int> AddDiagonalMatrixPlusSymetricMatrixTest(int[,] arr1, int[,] arr2) { var lhs = new DiagonalMatrix <int>(arr1); var rhs = new SymmetricMatrix <int>(arr1); return(MatrixExtension.Add(lhs, rhs)); }
private void SaveCascade(string filename) { StreamWriter sw = new StreamWriter(filename); int[] item1 = new int[] { Property.HRUFLG, Property.STRMFLG, Property.FLOWFLG, Property.VISFLG, Property.IPRN, Property.IFILL }; string line = string.Format("{0}\t{1}\t{2}\t#HRUFLG STRMFLG FLOWFLG VISFLG IPRN IFILL DPIT OUTITMAX", string.Join("\t", item1), Property.DPIT, Property.OUTITMAX); sw.WriteLine(line); var hru_type = _Prms.MMSPackage.Parameters["hru_type"].ToInt32().ToArray(); int aci = 0; short[] ht = new short[mGrid.ColumnCount]; for (uint r = 0; r < mGrid.RowCount; r++) { line = ""; MatrixExtension <short> .Set(ht, 0); for (uint c = 0; c < mGrid.ColumnCount; c++) { if (mGrid.IBound[0, (int)r, (int)c] > 0) { ht[c] = (short)hru_type[aci]; aci++; } } line = string.Join("\t", ht); sw.WriteLine(line); } sw.Close(); }
public void GetMatrix_Trivial_Spiral() { var expected = new[, ] { { 1 } }; Assert.AreEqual(expected, MatrixExtension.GetMatrix(1)); }
public void WorldPositionNormalizeToTest() { WorldPosition position = new WorldPosition(-1, 1, MatrixExtension.SetTranslation(Microsoft.Xna.Framework.Matrix.Identity, 3834, 0, -4118)).NormalizeTo(4, 4); Assert.AreEqual(4, position.TileX); Assert.AreEqual(-6406, position.Location.X); Assert.AreEqual(4, position.TileZ); Assert.AreEqual(10262, position.Location.Z); Assert.AreEqual(-10262, position.XNAMatrix.M43); }
public void GetMatrix_Spiral_Of_Size_2() { var expected = new[, ] { { 1, 2 }, { 4, 3 }, }; Assert.AreEqual(expected, MatrixExtension.GetMatrix(2)); }
public void GetMatrix_Spiral_Of_Size_3() { var expected = new[, ] { { 1, 2, 3 }, { 8, 9, 4 }, { 7, 6, 5 }, }; Assert.AreEqual(expected, MatrixExtension.GetMatrix(3)); }
public override void AlterDimLength(int new_length) { if (new_length == Values.Length) { return; } var default_vv = Values[0]; Values = new T[new_length]; MatrixExtension <T> .Set(Values, default_vv); }
public void GetMatrix_Spiral_Of_Size_4() { var expected = new[, ] { { 1, 2, 3, 4 }, { 12, 13, 14, 5 }, { 11, 16, 15, 6 }, { 10, 9, 8, 7 }, }; Assert.AreEqual(expected, MatrixExtension.GetMatrix(4)); }
public void GetMatrix_Spiral_Of_Size_5() { var expected = new[, ] { { 1, 2, 3, 4, 5 }, { 16, 17, 18, 19, 6 }, { 15, 24, 25, 20, 7 }, { 14, 23, 22, 21, 8 }, { 13, 12, 11, 10, 9 }, }; Assert.AreEqual(expected, MatrixExtension.GetMatrix(5)); }
public void MatrixHierarchyAdditionTest2() { var array1 = new string[][] { new string[] { "-3" }, new string[] { "6", "-5" }, new string[] { "5", "7", "4" } }; var array2 = new string[] { "ab", "cd", "ef" }; var resultArray = new string[, ] { { "-3ab", "6", "5" }, { "6", "-5cd", "7" }, { "5", "7", "4ef" } }; var matrixA = new SymmetricalMatrix <string>(array1); var matrixB = new DiagonalMatrix <string>(array2); var sum = MatrixExtension <string> .Add(matrixA, matrixB); CollectionAssert.AreEqual(resultArray, sum.ToArray()); }
public void GetMatrix_Spiral_Of_Size_6() { var expected = new[, ] { { 1, 2, 3, 4, 5, 6, }, { 20, 21, 22, 23, 24, 7, }, { 19, 32, 33, 34, 25, 8, }, { 18, 31, 36, 35, 26, 9, }, { 17, 30, 29, 28, 27, 10, }, { 16, 15, 14, 13, 12, 11, }, }; Assert.AreEqual(expected, MatrixExtension.GetMatrix(6)); }
public void GetMatrix_Spiral_Of_Size_7() { var expected = new[, ] { { 1, 2, 3, 4, 5, 6, 7, }, { 24, 25, 26, 27, 28, 29, 8, }, { 23, 40, 41, 42, 43, 30, 9, }, { 22, 39, 48, 49, 44, 31, 10, }, { 21, 38, 47, 46, 45, 32, 11, }, { 20, 37, 36, 35, 34, 33, 12, }, { 19, 18, 17, 16, 15, 14, 13, }, }; Assert.AreEqual(expected, MatrixExtension.GetMatrix(7)); }
public void GetMatrix_Spiral_Of_Size_40() { var expected = new[, ] { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, }, { 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 41, }, { 155, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 195, 42, }, { 154, 303, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 341, 196, 43, }, { 153, 302, 443, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 479, 342, 197, 44, }, { 152, 301, 442, 575, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 609, 480, 343, 198, 45, }, { 151, 300, 441, 574, 699, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 731, 610, 481, 344, 199, 46, }, { 150, 299, 440, 573, 698, 815, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 845, 732, 611, 482, 345, 200, 47, }, { 149, 298, 439, 572, 697, 814, 923, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 951, 846, 733, 612, 483, 346, 201, 48, }, { 148, 297, 438, 571, 696, 813, 922, 1023, 1116, 1117, 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1126, 1127, 1128, 1129, 1130, 1131, 1132, 1133, 1134, 1135, 1136, 1137, 1138, 1049, 952, 847, 734, 613, 484, 347, 202, 49, }, { 147, 296, 437, 570, 695, 812, 921, 1022, 1115, 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220, 1139, 1050, 953, 848, 735, 614, 485, 348, 203, 50, }, { 146, 295, 436, 569, 694, 811, 920, 1021, 1114, 1199, 1276, 1277, 1278, 1279, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288, 1289, 1290, 1291, 1292, 1293, 1294, 1221, 1140, 1051, 954, 849, 736, 615, 486, 349, 204, 51, }, { 145, 294, 435, 568, 693, 810, 919, 1020, 1113, 1198, 1275, 1344, 1345, 1346, 1347, 1348, 1349, 1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359, 1360, 1295, 1222, 1141, 1052, 955, 850, 737, 616, 487, 350, 205, 52, }, { 144, 293, 434, 567, 692, 809, 918, 1019, 1112, 1197, 1274, 1343, 1404, 1405, 1406, 1407, 1408, 1409, 1410, 1411, 1412, 1413, 1414, 1415, 1416, 1417, 1418, 1361, 1296, 1223, 1142, 1053, 956, 851, 738, 617, 488, 351, 206, 53, }, { 143, 292, 433, 566, 691, 808, 917, 1018, 1111, 1196, 1273, 1342, 1403, 1456, 1457, 1458, 1459, 1460, 1461, 1462, 1463, 1464, 1465, 1466, 1467, 1468, 1419, 1362, 1297, 1224, 1143, 1054, 957, 852, 739, 618, 489, 352, 207, 54, }, { 142, 291, 432, 565, 690, 807, 916, 1017, 1110, 1195, 1272, 1341, 1402, 1455, 1500, 1501, 1502, 1503, 1504, 1505, 1506, 1507, 1508, 1509, 1510, 1469, 1420, 1363, 1298, 1225, 1144, 1055, 958, 853, 740, 619, 490, 353, 208, 55, }, { 141, 290, 431, 564, 689, 806, 915, 1016, 1109, 1194, 1271, 1340, 1401, 1454, 1499, 1536, 1537, 1538, 1539, 1540, 1541, 1542, 1543, 1544, 1511, 1470, 1421, 1364, 1299, 1226, 1145, 1056, 959, 854, 741, 620, 491, 354, 209, 56, }, { 140, 289, 430, 563, 688, 805, 914, 1015, 1108, 1193, 1270, 1339, 1400, 1453, 1498, 1535, 1564, 1565, 1566, 1567, 1568, 1569, 1570, 1545, 1512, 1471, 1422, 1365, 1300, 1227, 1146, 1057, 960, 855, 742, 621, 492, 355, 210, 57, }, { 139, 288, 429, 562, 687, 804, 913, 1014, 1107, 1192, 1269, 1338, 1399, 1452, 1497, 1534, 1563, 1584, 1585, 1586, 1587, 1588, 1571, 1546, 1513, 1472, 1423, 1366, 1301, 1228, 1147, 1058, 961, 856, 743, 622, 493, 356, 211, 58, }, { 138, 287, 428, 561, 686, 803, 912, 1013, 1106, 1191, 1268, 1337, 1398, 1451, 1496, 1533, 1562, 1583, 1596, 1597, 1598, 1589, 1572, 1547, 1514, 1473, 1424, 1367, 1302, 1229, 1148, 1059, 962, 857, 744, 623, 494, 357, 212, 59, }, { 137, 286, 427, 560, 685, 802, 911, 1012, 1105, 1190, 1267, 1336, 1397, 1450, 1495, 1532, 1561, 1582, 1595, 1600, 1599, 1590, 1573, 1548, 1515, 1474, 1425, 1368, 1303, 1230, 1149, 1060, 963, 858, 745, 624, 495, 358, 213, 60, }, { 136, 285, 426, 559, 684, 801, 910, 1011, 1104, 1189, 1266, 1335, 1396, 1449, 1494, 1531, 1560, 1581, 1594, 1593, 1592, 1591, 1574, 1549, 1516, 1475, 1426, 1369, 1304, 1231, 1150, 1061, 964, 859, 746, 625, 496, 359, 214, 61, }, { 135, 284, 425, 558, 683, 800, 909, 1010, 1103, 1188, 1265, 1334, 1395, 1448, 1493, 1530, 1559, 1580, 1579, 1578, 1577, 1576, 1575, 1550, 1517, 1476, 1427, 1370, 1305, 1232, 1151, 1062, 965, 860, 747, 626, 497, 360, 215, 62, }, { 134, 283, 424, 557, 682, 799, 908, 1009, 1102, 1187, 1264, 1333, 1394, 1447, 1492, 1529, 1558, 1557, 1556, 1555, 1554, 1553, 1552, 1551, 1518, 1477, 1428, 1371, 1306, 1233, 1152, 1063, 966, 861, 748, 627, 498, 361, 216, 63, }, { 133, 282, 423, 556, 681, 798, 907, 1008, 1101, 1186, 1263, 1332, 1393, 1446, 1491, 1528, 1527, 1526, 1525, 1524, 1523, 1522, 1521, 1520, 1519, 1478, 1429, 1372, 1307, 1234, 1153, 1064, 967, 862, 749, 628, 499, 362, 217, 64, }, { 132, 281, 422, 555, 680, 797, 906, 1007, 1100, 1185, 1262, 1331, 1392, 1445, 1490, 1489, 1488, 1487, 1486, 1485, 1484, 1483, 1482, 1481, 1480, 1479, 1430, 1373, 1308, 1235, 1154, 1065, 968, 863, 750, 629, 500, 363, 218, 65, }, { 131, 280, 421, 554, 679, 796, 905, 1006, 1099, 1184, 1261, 1330, 1391, 1444, 1443, 1442, 1441, 1440, 1439, 1438, 1437, 1436, 1435, 1434, 1433, 1432, 1431, 1374, 1309, 1236, 1155, 1066, 969, 864, 751, 630, 501, 364, 219, 66, }, { 130, 279, 420, 553, 678, 795, 904, 1005, 1098, 1183, 1260, 1329, 1390, 1389, 1388, 1387, 1386, 1385, 1384, 1383, 1382, 1381, 1380, 1379, 1378, 1377, 1376, 1375, 1310, 1237, 1156, 1067, 970, 865, 752, 631, 502, 365, 220, 67, }, { 129, 278, 419, 552, 677, 794, 903, 1004, 1097, 1182, 1259, 1328, 1327, 1326, 1325, 1324, 1323, 1322, 1321, 1320, 1319, 1318, 1317, 1316, 1315, 1314, 1313, 1312, 1311, 1238, 1157, 1068, 971, 866, 753, 632, 503, 366, 221, 68, }, { 128, 277, 418, 551, 676, 793, 902, 1003, 1096, 1181, 1258, 1257, 1256, 1255, 1254, 1253, 1252, 1251, 1250, 1249, 1248, 1247, 1246, 1245, 1244, 1243, 1242, 1241, 1240, 1239, 1158, 1069, 972, 867, 754, 633, 504, 367, 222, 69, }, { 127, 276, 417, 550, 675, 792, 901, 1002, 1095, 1180, 1179, 1178, 1177, 1176, 1175, 1174, 1173, 1172, 1171, 1170, 1169, 1168, 1167, 1166, 1165, 1164, 1163, 1162, 1161, 1160, 1159, 1070, 973, 868, 755, 634, 505, 368, 223, 70, }, { 126, 275, 416, 549, 674, 791, 900, 1001, 1094, 1093, 1092, 1091, 1090, 1089, 1088, 1087, 1086, 1085, 1084, 1083, 1082, 1081, 1080, 1079, 1078, 1077, 1076, 1075, 1074, 1073, 1072, 1071, 974, 869, 756, 635, 506, 369, 224, 71, }, { 125, 274, 415, 548, 673, 790, 899, 1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990, 989, 988, 987, 986, 985, 984, 983, 982, 981, 980, 979, 978, 977, 976, 975, 870, 757, 636, 507, 370, 225, 72, }, { 124, 273, 414, 547, 672, 789, 898, 897, 896, 895, 894, 893, 892, 891, 890, 889, 888, 887, 886, 885, 884, 883, 882, 881, 880, 879, 878, 877, 876, 875, 874, 873, 872, 871, 758, 637, 508, 371, 226, 73, }, { 123, 272, 413, 546, 671, 788, 787, 786, 785, 784, 783, 782, 781, 780, 779, 778, 777, 776, 775, 774, 773, 772, 771, 770, 769, 768, 767, 766, 765, 764, 763, 762, 761, 760, 759, 638, 509, 372, 227, 74, }, { 122, 271, 412, 545, 670, 669, 668, 667, 666, 665, 664, 663, 662, 661, 660, 659, 658, 657, 656, 655, 654, 653, 652, 651, 650, 649, 648, 647, 646, 645, 644, 643, 642, 641, 640, 639, 510, 373, 228, 75, }, { 121, 270, 411, 544, 543, 542, 541, 540, 539, 538, 537, 536, 535, 534, 533, 532, 531, 530, 529, 528, 527, 526, 525, 524, 523, 522, 521, 520, 519, 518, 517, 516, 515, 514, 513, 512, 511, 374, 229, 76, }, { 120, 269, 410, 409, 408, 407, 406, 405, 404, 403, 402, 401, 400, 399, 398, 397, 396, 395, 394, 393, 392, 391, 390, 389, 388, 387, 386, 385, 384, 383, 382, 381, 380, 379, 378, 377, 376, 375, 230, 77, }, { 119, 268, 267, 266, 265, 264, 263, 262, 261, 260, 259, 258, 257, 256, 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 238, 237, 236, 235, 234, 233, 232, 231, 78, }, { 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, }, }; Assert.AreEqual(expected, MatrixExtension.GetMatrix(40)); }
public void GetMatrix_Spiral_Of_Size_8() { var expected = new[, ] { { 1, 2, 3, 4, 5, 6, 7, 8, }, { 28, 29, 30, 31, 32, 33, 34, 9, }, { 27, 48, 49, 50, 51, 52, 35, 10, }, { 26, 47, 60, 61, 62, 53, 36, 11, }, { 25, 46, 59, 64, 63, 54, 37, 12, }, { 24, 45, 58, 57, 56, 55, 38, 13, }, { 23, 44, 43, 42, 41, 40, 39, 14, }, { 22, 21, 20, 19, 18, 17, 16, 15, }, }; Assert.AreEqual(expected, MatrixExtension.GetMatrix(8)); }
void Awake() { toUnity = MatrixExtension.RosToUnity(); // toRos = transform.localToWorldMatrix.ToUnity (); toRos = toUnity.inverse; // Debug.Log ( "ToUnity: " + toUnity ); // Debug.Log ( "ToRos: " + toRos ); // Debug.Log ( transform.worldToLocalMatrix.ToUnity () ); // Debug.Log ( transform.worldToLocalMatrix.ToUnity ().inverse ); // Debug.Log ( "forward to ros: " + Vector3.forward.ToRos () ); // Quaternion q = QuaternionToRos ( transform.rotation ); // Vector3 v = q * Vector3.forward; // Debug.Log ( "v " + v ); // Debug.Log ( "rot " + transform.rotation + " q " + q ); // Debug.Log ( "forward " + Vector3.up.ToRos () ); }
public void WorldPositionNormalizeTest() { WorldPosition position = new WorldPosition(new WorldLocation(0, 0, 3834, 0, -4118)).Normalize(); Assert.AreEqual(2, position.TileX); Assert.AreEqual(-262, position.Location.X); Assert.AreEqual(2, position.TileZ); Assert.AreEqual(-22, position.Location.Z); position = new WorldPosition(0, 0, MatrixExtension.SetTranslation(Microsoft.Xna.Framework.Matrix.Identity, 3834, 0, -4118)).Normalize(); Assert.AreEqual(2, position.TileX); Assert.AreEqual(-262, position.Location.X); Assert.AreEqual(-2, position.TileZ); Assert.AreEqual(22, position.Location.Z); Assert.AreEqual(-22, position.XNAMatrix.M43); }
public void MatrixHierarchyAdditionTest1() { var array1 = new int[, ] { { 5, 6, -3 }, { 17, 7, 0 }, { 8, -5, 4 } }; var array2 = new int[, ] { { 2, 3, 0 }, { 6, 11, 1 }, { 3, 3, 7 } }; var resultArray = new int[, ] { { 7, 9, -3 }, { 23, 18, 1 }, { 11, -2, 11 } }; var matrixA = new SquareMatrix <int>(array1); var matrixB = new SquareMatrix <int>(array2); var sum = MatrixExtension <int> .Add(matrixA, matrixB); CollectionAssert.AreEqual(resultArray, sum.ToArray()); }
public override void SaveAs(string filename) { StreamWriter sw = new StreamWriter(filename); WriteDefaultComment(sw, "HFB"); string line = string.Format("{0}\t{1}\t{2}\t# Data set 1: NPHFB MXFB NHFBNP", Parameters["NPHFB"].IntValue, Parameters["MXFB"].IntValue, Parameters["NHFBNP"].IntValue); sw.WriteLine(line); MatrixExtension <float> .Save(CellLocation, sw); line = string.Format("{0}\t# Data Set 5: NACTHFB", Parameters["NACTHFB"].IntValue); sw.WriteLine(line); sw.Close(); }
public void GetMatrix_Spiral_Of_Size_9() { var expected = new[, ] { { 1, 2, 3, 4, 5, 6, 7, 8, 9, }, { 32, 33, 34, 35, 36, 37, 38, 39, 10, }, { 31, 56, 57, 58, 59, 60, 61, 40, 11, }, { 30, 55, 72, 73, 74, 75, 62, 41, 12, }, { 29, 54, 71, 80, 81, 76, 63, 42, 13, }, { 28, 53, 70, 79, 78, 77, 64, 43, 14, }, { 27, 52, 69, 68, 67, 66, 65, 44, 15, }, { 26, 51, 50, 49, 48, 47, 46, 45, 16, }, { 25, 24, 23, 22, 21, 20, 19, 18, 17, }, }; Assert.AreEqual(expected, MatrixExtension.GetMatrix(9)); }
public void GetMatrix_Spiral_Of_Size_10() { var expected = new[, ] { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, }, { 36, 37, 38, 39, 40, 41, 42, 43, 44, 11, }, { 35, 64, 65, 66, 67, 68, 69, 70, 45, 12, }, { 34, 63, 84, 85, 86, 87, 88, 71, 46, 13, }, { 33, 62, 83, 96, 97, 98, 89, 72, 47, 14, }, { 32, 61, 82, 95, 100, 99, 90, 73, 48, 15, }, { 31, 60, 81, 94, 93, 92, 91, 74, 49, 16, }, { 30, 59, 80, 79, 78, 77, 76, 75, 50, 17, }, { 29, 58, 57, 56, 55, 54, 53, 52, 51, 18, }, { 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, }, }; Assert.AreEqual(expected, MatrixExtension.GetMatrix(10)); }
public override void Read(string filename = "") { if (filename == "") { filename = GetInputFile(this.Name); } if (File.Exists(filename)) { var grid = mfgrid; int layer = grid.ActualLayerCount; var upw = this; layer = 3; StreamReader sr = new StreamReader(filename); //Data Set 1: # ILPFCB, HDRY, NPLPF string newline = ReadCommet(sr); float[] fv = TypeConverterEx.Split <float>(newline, 4); upw.ILPFCB = (short)fv[0]; upw.HDRY = fv[1]; upw.NPLPF = (short)fv[2]; upw.IPHDRY = (short)fv[3]; //Data Set 2: # newline = sr.ReadLine(); upw.LAYTYP = TypeConverterEx.Split <int>(newline, layer); //Data Set 3: # newline = sr.ReadLine(); upw.LAYAVG = TypeConverterEx.Split <int>(newline, layer); //Data Set 4: # newline = sr.ReadLine(); upw.CHANI = TypeConverterEx.Split <int>(newline, layer); //Data Set 5: # newline = sr.ReadLine(); upw.LAYVKA = TypeConverterEx.Split <int>(newline, layer); //Data Set 6: # newline = sr.ReadLine(); upw.LAYWET = TypeConverterEx.Split <int>(newline, layer); //Data Set 7: # //grid.LPFProperty.HK = new LayeredMatrix<float>(layer); //grid.LPFProperty.HANI = new LayeredMatrix<float>(layer); //grid.LPFProperty.VKA = new LayeredMatrix<float>(layer); //grid.LPFProperty.SS = new LayeredMatrix<float>(layer); //grid.LPFProperty.SY = new LayeredMatrix<float>(layer); var hania = new float[layer]; MatrixExtension <float> .Set(hania, 1); var hk = new MatrixCube <float>(layer); var hani = new MatrixCube <float>(layer); var vka = new MatrixCube <float>(layer); var ss = new MatrixCube <float>(layer); var sy = new MatrixCube <float>(layer); var wetdry = new MatrixCube <float>(layer); Parameters["HK"].Value = hk; Parameters["HANI"].Value = hani; Parameters["VKA"].Value = vka; Parameters["SS"].Value = ss; Parameters["SY"].Value = sy; Parameters["WETDRY"].Value = wetdry; for (int l = 0; l < layer; l++) { ReadInternalMatrix(sr, hk, grid.RowCount, grid.ColumnCount, l); ReadInternalMatrix(sr, hani, grid.RowCount, grid.ColumnCount, l); ReadInternalMatrix(sr, vka, grid.RowCount, grid.ColumnCount, l); ReadInternalMatrix(sr, ss, grid.RowCount, grid.ColumnCount, l); if (upw.LAYTYP[l] != 0) { ReadInternalMatrix(sr, sy, grid.RowCount, grid.ColumnCount, l); } } sr.Close(); } }
public void MatrixHierarchyAdditionTest() { var squareMatrix = new int[, ] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; var diagonalMatrix = new int[, ] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }; var symmetricalMatrix = new int[, ] { { 1, 2, 3 }, { 2, 1, 4 }, { 3, 4, 1 } }; var resultSquareSquare = new[, ] { { 2, 4, 6 }, { 8, 10, 12 }, { 14, 16, 18 } }; var resultSquareDiagonal = new[, ] { { 2, 2, 3 }, { 4, 6, 6 }, { 7, 8, 10 } }; var resultSquareSymmetrical = new[, ] { { 2, 4, 6 }, { 6, 6, 10 }, { 10, 12, 10 } }; var resultDiagonalDiagonal = new[, ] { { 2, 0, 0 }, { 0, 2, 0 }, { 0, 0, 2 } }; var resultDiagonalSquare = new[, ] { { 2, 0, 0 }, { 0, 6, 0 }, { 0, 0, 10 } }; var resultDiagonalSymmetrical = new[, ] { { 2, 0, 0 }, { 0, 2, 0 }, { 0, 0, 2 } }; var resultSymmetricalSymmetrical = new[, ] { { 2, 4, 6 }, { 4, 2, 8 }, { 6, 8, 2 } }; var resultSymmetricalSquare = new[, ] { { 2, 4, 6 }, { 6, 6, 10 }, { 10, 12, 10 } }; var resultSymmetricalDiagonal = new[, ] { { 2, 2, 3 }, { 2, 2, 4 }, { 3, 4, 2 } }; var matrixSquare = new SquareMatrix <int>(squareMatrix); var matrixDiagonal = new DiagonalMatrix <int>(diagonalMatrix); var matrixSymmetrical = new SymmetricalMatrix <int>(symmetricalMatrix); var sumSquareSquare = MatrixExtension <int> .Addition(matrixSquare, matrixSquare); var sumSquareDiagonal = MatrixExtension <int> .Addition(matrixSquare, matrixDiagonal); var sumSquareSymmetrical = MatrixExtension <int> .Addition(matrixSquare, matrixSymmetrical); var sumDiagonalDiagonal = MatrixExtension <int> .Addition(matrixDiagonal, matrixDiagonal); var sumDiagonalSquare = MatrixExtension <int> .Addition(matrixDiagonal, matrixSquare); var sumDiagonalSymmetrical = MatrixExtension <int> .Addition(matrixDiagonal, matrixSymmetrical); var sumSymmetricalSymmetrical = MatrixExtension <int> .Addition(matrixSymmetrical, matrixSymmetrical); var sumSymmetricalSquare = MatrixExtension <int> .Addition(matrixSymmetrical, matrixSquare); var sumSymmetricalDiagonal = MatrixExtension <int> .Addition(matrixSymmetrical, matrixDiagonal); CollectionAssert.AreEqual(resultSquareSquare, sumSquareSquare.GetMatrix()); CollectionAssert.AreEqual(resultSquareDiagonal, sumSquareDiagonal.GetMatrix()); CollectionAssert.AreEqual(resultSquareSymmetrical, sumSquareSymmetrical.GetMatrix()); CollectionAssert.AreEqual(resultDiagonalDiagonal, sumDiagonalDiagonal.GetMatrix()); CollectionAssert.AreEqual(resultDiagonalSquare, sumDiagonalSquare.GetMatrix()); CollectionAssert.AreEqual(resultDiagonalSymmetrical, sumDiagonalSymmetrical.GetMatrix()); CollectionAssert.AreEqual(resultSymmetricalSymmetrical, sumSymmetricalSymmetrical.GetMatrix()); CollectionAssert.AreEqual(resultSymmetricalSquare, sumSymmetricalSquare.GetMatrix()); CollectionAssert.AreEqual(resultSymmetricalDiagonal, sumSymmetricalDiagonal.GetMatrix()); }
public Matrix <int> Strassen() { return(MatrixExtension.MultiplyStrassen(_matrix3, _matrix4)); }
/// <summary> /// read 3D matrix from binary file with the given filename. 3D array: [variable][step][feature] /// </summary> /// <param name="filename"></param> /// <param name="flag">flag: 1 mean; 2 sum; </param> /// <param name="step"></param> /// <param name="varNames"></param> /// <param name="maxsteps"></param> /// <param name="scale"></param> /// <returns>3D array: [variable][step][feature]</returns> public float[][][] Read(string filename, int flag, int[] intevals, ref int step, ref string[] varNames, int maxsteps = -1, float scale = 1) { float[][][] acmatrix = null; step = 0; int feaNum = 0; FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); BinaryReader br = new BinaryReader(fs); int ninteval = intevals.Length; int varnum = br.ReadInt32(); varNames = new string[varnum]; for (int i = 0; i < varnum; i++) { int varname_len = br.ReadInt32(); varNames[i] = new string(br.ReadChars(varname_len)).Trim(); feaNum = br.ReadInt32(); } if (flag > 0) { acmatrix = new float[varnum][][]; float[][] derived = new float[varnum][]; for (int i = 0; i < varnum; i++) { acmatrix[i] = new float[ninteval][]; derived[i] = new float[feaNum]; for (int t = 0; t < ninteval; t++) { acmatrix[i][t] = new float[feaNum]; } } for (int n = 0; n < ninteval; n++) { MatrixExtension <float> .Set(derived, 0); for (int t = 0; t < intevals[n]; t++) { for (int s = 0; s < feaNum; s++) { for (int v = 0; v < varnum; v++) { //if(!(fs.Position == fs.Length)) //{ derived[v][s] += br.ReadSingle() * scale; //} } } } if (flag == 1) { for (int s = 0; s < feaNum; s++) { for (int v = 0; v < varnum; v++) { derived[v][s] = derived[v][s] / intevals[n]; } } } for (int s = 0; s < feaNum; s++) { for (int v = 0; v < varnum; v++) { acmatrix[v][n][s] = derived[v][s]; } } step++; if (maxsteps > 0) { if (step >= maxsteps) { break; } } } } br.Close(); fs.Close(); return(acmatrix); }
/// <summary> /// Provide quick summerization on specified cells.. Add an offeset when reading. Return 3D array: [subset zone][var][step] /// </summary> /// <param name="filename"></param> /// <param name="intevals"></param> /// <param name="step"></param> /// <param name="varNames"></param> /// <param name="subindex"></param> /// <param name="offset"></param> /// <param name="statFlag"></param> /// <returns></returns> public float[][][] Summerize(string filename, int[] intevals, ref int step, ref string[] varNames, int[][] subindex, float [] offset, NumericalDataType statFlag = NumericalDataType.Average) { step = 0; int feaNum = 0; FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); BinaryReader br = new BinaryReader(fs); int varnum = br.ReadInt32(); int nzone = subindex.Length; varNames = new string[varnum]; float[][][] stat = new float[nzone][][]; for (int i = 0; i < nzone; i++) { stat[i] = new float[varnum][]; } for (int i = 0; i < varnum; i++) { int varname_len = br.ReadInt32(); varNames[i] = new string(br.ReadChars(varname_len)).Trim(); feaNum = br.ReadInt32(); for (int z = 0; z < nzone; z++) { stat[z][i] = new float[intevals.Length]; } } float[][] matrix = new float[varnum][]; for (int i = 0; i < varnum; i++) { matrix[i] = new float[feaNum]; } for (int i = 0; i < intevals.Length; i++) { MatrixExtension <float> .Set(matrix, 0); for (int d = 0; d < intevals[i]; d++) { for (int s = 0; s < feaNum; s++) { for (int v = 0; v < varnum; v++) { matrix[v][s] += (br.ReadSingle() + offset[s]); } } step++; } for (int z = 0; z < nzone; z++) { for (int v = 0; v < varnum; v++) { float temp = 0; foreach (var id in subindex[z]) { temp += matrix[v][id]; } if (statFlag == NumericalDataType.Average) { stat[z][v][i] = temp / subindex[z].Length / intevals[i]; } else if (statFlag == NumericalDataType.Cumulative) { stat[z][v][i] = temp / subindex[z].Length; } } } } br.Close(); fs.Close(); return(stat); }
public void GetMatrix_Size_Of_Matrix_Is_Negative_Throw_ArgumentException(int size) { Assert.Throws <ArgumentException>(() => MatrixExtension.GetMatrix(size), $"Size of matrix '{size}' cannot be less or equal zero."); }