public static Type GetSubstituteType(Type type, bool serializing) { if (!serializing) { if (type == typeof(Field)) { return(typeof(FieldEx)); } for (int i = 0; i < m_substituteTypes.GetLength(0); i++) { if (type == m_substituteTypes[i, 0]) { return(m_substituteTypes[i, 1]); } } } else { if (type.BaseType == typeof(Tablix)) { return(typeof(Tablix)); } for (int j = 0; j < m_substituteTypes.GetLength(0); j++) { if (type == m_substituteTypes[j, 1]) { return(m_substituteTypes[j, 0]); } } } return(type); }
/// <summary> /// Escribe en la consola el contenido de un vector bi-dimencional, agregando un encabezado para cada columna. /// <returns></returns> public static bool EscribirMatriz <Type>(string[] prmVectorEncabezados, Type[,] prmMatriz, bool prmAlinearDerecha) { try { if (prmAlinearDerecha) { for (int varIteradorColumna = 0; varIteradorColumna < prmMatriz.GetLength(1); varIteradorColumna++) { Console.WriteLine(prmVectorEncabezados[varIteradorColumna]); for (int varIteradorFila = 0; varIteradorFila < prmMatriz.GetLength(0); varIteradorFila++) { Console.WriteLine("\t" + prmMatriz[varIteradorFila, varIteradorColumna]); } } } else { for (int varIteradorColumna = 0; varIteradorColumna < prmMatriz.GetLength(1); varIteradorColumna++) { for (int varIteradorFila = 0; varIteradorFila < prmMatriz.GetLength(0); varIteradorFila++) { Console.WriteLine(prmMatriz[varIteradorFila, varIteradorColumna]); } } } return(true); } catch (Exception) { Console.WriteLine("Hubo un error inesperado. "); return(false); }; }
public NDArray(Type[,] nD) { if (nD == null) { throw new ArgumentException(); } int dim0 = nD.GetLength(0); int dim1 = nD.GetLength(1); int dim = dim0 * dim1; Shape = new int[] { dim0, dim1 }; tmpArr = new int[Shape.Length]; items = new Type[dim]; int a = 0; for (int i = 0; i < dim0; ++i) { for (int j = 0; j < dim1; ++j) { items[a++] = nD[i, j]; } } }
internal void Fill <Type>(ref Type[,] x, Type a)//配列の定数敷き詰め { for (int i0 = 0; i0 < x.GetLength(0); i0++) { for (int i1 = 0; i1 < x.GetLength(1); i1++) { x[i0, i1] = a; } } }
public static void Loop <Type>(this Type[,] array, Action <Type> DoThing) { for (int k = 0; k < array.GetLength(0); k++) { for (int l = 0; l < array.GetLength(1); l++) { DoThing(array[k, l]); } } }
public static Type[,] DeepCopy <Type>(Type[,] source) { Type[,] copy = new Type[source.GetLength(0), source.GetLength(1)]; for (int i = 0; i < copy.GetLength(0); i++) { for (int j = 0; j < copy.GetLength(1); j++) { copy[i, j] = source[i, j]; } } return(copy); }
public static void RotateArrayAnticlockwise <Type>(Type[,] array) { // 引数の2次元配列 array を反時計回りに回転させたものを返す int rows = array.GetLength(0); int cols = array.GetLength(1); var t = new Type[cols, rows]; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { t[cols - j - 1, i] = array[i, j]; } } }
public static NDarray <Type> CreateNDarray <Type>(Type[,] data) { int dim0 = data.GetLength(0); int dim1 = data.GetLength(1); Type[] data0 = new Type[dim0 * dim1]; for (int i = 0; i < dim0; ++i) { for (int j = 0; j < dim1; ++j) { data0[i * dim1 + j] = data[i, j]; } } return(CreateNDarray(data0, new int[] { dim0, dim1 })); }
/***returns protocol for type of connections found * Even = good connections * Odd = no connection or error * -1 = short circuit * 0 = connected to lightbulb * */ int validateConnections(NodePosition sourcePosition, ref Type[,] connections, Direction direction, ref HashSet <NodePosition> discovered) { if (discovered.Contains(sourcePosition)) { return(1); } //checks if position in bounds of the circuitBoard if ((sourcePosition.x < connections.GetLength(0) && sourcePosition.x >= 0) && (sourcePosition.y < connections.GetLength(1) && sourcePosition.y >= 0)) { if (connections[sourcePosition.x, sourcePosition.y] == Type.Goal) { return(0); } else if (connections[sourcePosition.x, sourcePosition.y] == Type.Wires) { return(2); } else if (connections[sourcePosition.x, sourcePosition.y] == Type.Battery) { return(-1); } else { discovered.Add(sourcePosition); return(1); } } return(1); }
/// <summary> /// Вид форматной строки: {index[:formatString][,alignment]} /// </summary> public string ToString(string format, IFormatProvider provider) { if (data == null) { return("null"); } provider = provider ?? CultureInfo.CurrentCulture; string width = "0"; if (string.IsNullOrEmpty(format)) { format = "{0:G} "; } else if (format.IndexOf(',') != -1) { int index = format.IndexOf(','); width = format.Substring(index + 1); format = string.Format("{{0,{0}:{1}}}", width, format.Substring(0, index)); if (width == "" || format == "") { throw new FormatException("Неверный формат для печати объекта"); } } else { width = char.IsLetter(format[0]) || format[0] == '0' ? "12" : format; format = string.Format(char.IsLetter(format[0]) || format[0] == '0' ? "{{0:{0}}} " : "{{0,{0}}}", format); } StringBuilder str = new StringBuilder(Convert.ToInt32(width) * data.Length + 2 * data.GetLength(0)); for (int i = 0; i < Rows; i++) { for (int j = 0; j < Cols; j++) { str.AppendFormat(format, ((dynamic)data[i, j]).ToString(provider)); } str.AppendFormat("\n"); } return(str.ToString()); }
/// <summary> /// Escribe en la consola el contenido de un vector bi-dimencional, agregando una etiqueta. /// </summary> /// <returns></returns> public static bool EscribirMatriz <Type>(string prmEtiqueta, Type[,] prmMatriz) { try { Console.WriteLine(prmEtiqueta); for (int varIteradorColumna = 0; varIteradorColumna < prmMatriz.GetLength(1); varIteradorColumna++) { for (int varIteradorFila = 0; varIteradorFila < prmMatriz.GetLength(0); varIteradorFila++) { Console.WriteLine(prmMatriz[varIteradorFila, varIteradorColumna]); } } return(true); } catch (Exception) { Console.WriteLine("Hubo un error inesperado. "); return(false); }; }
private static int FindElevator(Type[,] area, int floor) { for (var i = 0; i < area.GetLength(0); i++) { if (area[i, floor] == Type.Elevator) { return(i); } } return(-1); }
public void Release(ref Type[,] target) { if (target == null) { return; } if (isClearOnAlloc == false) { System.Array.Clear(target, 0, target.Length); } Stack <Type[, ]> stack; if (stackDict.TryGetValue(CacheIndex(target.GetLength(0), target.GetLength(1)), out stack) == false) { stack = new Stack <Type[, ]>(Config.STACK_CAP); } stack.Push(target); target = null; }
public override Type GetSubstituteType(Type type) { if (!m_serializing) { for (int i = 0; i < m_substituteTypes.GetLength(0); i++) { if (type == m_substituteTypes[i, 0]) { return(m_substituteTypes[i, 1]); } } } else { for (int j = 0; j < m_substituteTypes.GetLength(0); j++) { if (type == m_substituteTypes[j, 1]) { return(m_substituteTypes[j, 0]); } } } return(type); }
public TMatrix(Type[,] data) { if (data == null) { return; } this.data = data.GetLength(0) * data.GetLength(1) != 0 ? new Type[data.GetLength(0), data.GetLength(1)] : null; for (int i = 0; i < Rows; i++) { for (int j = 0; j < Cols; j++) { if (data[i, j] is ICloneable) { this.data[i, j] = (Type)((ICloneable)data[i, j]).Clone(); } else { this.data[i, j] = data[i, j]; } } } }
public GridWrapper(Type[,] data, Type nullValue) { this.data = data; width = data.GetLength(0); height = data.GetLength(1); }