本文整理汇总了C#中Variable.GetData方法的典型用法代码示例。如果您正苦于以下问题:C# Variable.GetData方法的具体用法?C# Variable.GetData怎么用?C# Variable.GetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Variable
的用法示例。
在下文中一共展示了Variable.GetData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDataSetVariable
public static void TestDataSetVariable(string tableName, LookupColumnTest lookupColumnTest, Variable v)
{
var columnTest = lookupColumnTest.Invoke(v.Name);
if (columnTest.Include)
{
var count = columnTest.Expected.Count();
var actualTruncated = (double[])null;
switch (v.TypeOfData.Name.ToString().ToLower())
{
case "single":
var actual = (float[])v.GetData();
actualTruncated = actual.Select(a => (double)a).Take(count).ToArray();
break;
case "double":
actualTruncated = ((double[])v.GetData()).Take(count).ToArray();
break;
default:
throw new Exception("unexpected column type");
}
DoColumnTest(tableName, v.Name, columnTest, actualTruncated);
}
else
{
Console.WriteLine("Skipping : {0}", v.Name);
}
}
示例2: SplitSecondDimension
public static Point[][] SplitSecondDimension(Variable variable)
{
if (variable == null)
throw new ArgumentNullException("variable");
if (variable.Rank != 2)
throw new ArgumentException("Only 2d variables are supported");
int n = variable.GetShape()[1];
int m = variable.GetShape()[0];
Array d = variable.GetData();
Point[][] pts = new Point[n][];
for (int i = 0; i < n; i++)
{
List<Point> tmp = new List<Point>(m);
if (variable.TypeOfData == typeof(float))
{
float[,] dt = (float[,])d;
object mvObj = variable.GetMissingValue();
if (mvObj == null)
{
for (int j = 0; j < m; j++)
if (!Double.IsNaN(dt[j, i]))
tmp.Add(new Point(j, dt[j, i]));
}
else
{
float mv;
try
{
mv = Convert.ToSingle(mvObj);
}
catch (Exception exc)
{
Trace.WriteLine("PolyPolyline: cannot convert missing value attribute to float: " + exc.Message);
mv = float.NaN;
}
for (int j = 0; j < m; j++)
if (dt[j, i] != mv)
tmp.Add(new Point(j, dt[j, i]));
}
}
else if (variable.TypeOfData == typeof(double))
{
double[,] dt = (double[,])d;
object mvObj = variable.GetMissingValue();
if (mvObj == null)
{
for (int j = 0; j < m; j++)
if (!Double.IsNaN(dt[j, i]))
tmp.Add(new Point(j, dt[j, i]));
}
else
{
double mv;
try
{
mv = Convert.ToDouble(mvObj);
}
catch (Exception exc)
{
Trace.WriteLine("PolyPolyline: cannot convert missing value attribute to double: " + exc.Message);
mv = double.NaN;
}
for (int j = 0; j < m; j++)
if (dt[j, i] != mv)
tmp.Add(new Point(j, dt[j, i]));
}
}
else
{
object mv = variable.GetMissingValue();
for (int j = 0; j < m; j++)
{
object obj = d.GetValue(j, i);
if (!Object.Equals(obj, mv))
tmp.Add(new Point(j, Convert.ToDouble(obj)));
}
}
pts[i] = tmp.ToArray();
}
return pts;
}
示例3: TestDataSet3DVariable
public static void TestDataSet3DVariable(string tableName, LookupColumn3dTest lookupColumn3dTest, LookupColumnTest lookupColumnTest, Variable v)
{
var columnTest = lookupColumnTest.Invoke(v.Name);
if (columnTest.Include)
{
ColumnTest.TestDataSetVariable(tableName, lookupColumnTest, v);
}
else
{
var column3dTest = lookupColumn3dTest.Invoke(v.Name);
if (column3dTest.Include)
{
var actualTruncated = (double[, ,])null;
switch (v.TypeOfData.Name.ToString().ToLower())
{
case "double":
{
var actual = (double[, ,])v.GetData();
var count1 = column3dTest.Expected.GetLength(0);
var count2 = column3dTest.Expected.GetLength(1);
var count3 = column3dTest.Expected.GetLength(2);
actualTruncated = new double[count1, count2, count3];
for (var ii = 0; ii < count1; ii++)
{
for (var jj = 0; jj < count2; jj++)
{
for (var kk = 0; kk < count3; kk++)
{
actualTruncated[ii, jj, kk] = actual[ii, jj, kk];
}
}
}
}
break;
default:
throw new Exception("unexpected column type");
}
DoColumn3dTest(column3dTest, actualTruncated);
}
else
{
Console.WriteLine("Skipping : {0}", v.Name);
}
}
}
示例4: PrintData
static void PrintData(Variable v, string range, string format)
{
try
{
// Find out which data to take
int rank = v.Rank;
var shape = v.GetShape();
var origin = rank == 0 ? null : new int[rank];
var count = rank == 0 ? null : new int[rank];
var stride = rank == 0 ? null : new int[rank];
for (int i = 0; i < rank; i++)
{
origin[i] = 0;
count[i] = shape[i];
stride[i] = 1;
}
if (range != null)
{
// parse range specification 'from:to' or 'from:step:to'
var ranges = range.Split(',');
for (int i = 0; i < rank && i < ranges.Length; i++)
{
var fromto = ranges[i].Split(':');
if (!int.TryParse(fromto[0], out origin[i])) origin[i] = 0;
if (origin[i] < 0) origin[i] = 0;
if (origin[i] >= shape[i]) origin[i] = shape[i] - 1;
if (fromto.Length < 2) count[i] = 1;
else
{
if (!int.TryParse(fromto[fromto.Length - 1], out count[i])) count[i] = 0;
if (count[i] == 0 || count[i] >= shape[i]) count[i] = shape[i] - 1;
if (count[i] < origin[i]) count[i] = origin[i];
if (fromto.Length > 2)
{
if (!int.TryParse(fromto[1], out stride[i])) stride[i] = 1;
if (stride[i] <= 0) stride[i] = 1;
}
count[i] = 1 + (count[i] - origin[i]) / stride[i];
}
}
}
// Now get the data
Array data = v.GetData(origin, stride, count);
if (data == null || (rank > 0 && data.Rank != rank))
Console.Error.WriteLine("No data");
else
{
int prefix = string.Join(",", Array.ConvertAll(shape, i => i.ToString())).Length + 2;
// parse format
int cell = 8;
string frm = "{0,8}";
if (format != null)
{
int p = format.IndexOf(':');
if (p < 0)
{
if (!int.TryParse(format, out cell)) cell = 8;
frm = "{0," + cell + "}";
}
else
{
if (!int.TryParse(format.Substring(0, p), out cell)) cell = 8;
frm = "{0," + cell + format.Substring(p) + "}";
}
}
// Now print the data
if (rank == 0) // scalar variable
{
Console.WriteLine();
string item = string.Format(frm, data.GetValue(0));
// check that item fits a cell
if (item.Length > cell) item = item.Substring(0, cell - 1) + "#";
Console.Write(" "); Console.Write(item);
}
else // has rank > 0 (array)
{
int[] indices = new int[data.Rank];
int[] varIndices = new int[rank];
int bufferWidth = Math.Max(80, Console.BufferWidth);
// .. to allow for non-console output
string lineSeparator = Environment.NewLine;
while (indices[0] < data.GetLength(0))
{
// print last dimension
Console.Write(lineSeparator);
lineSeparator = string.Empty;
int lastIndex = data.Rank - 1;
indices[lastIndex] = 0;
while (indices[lastIndex] < data.GetLength(lastIndex))
{
// print line of cells
// print prefix of current indices
for (int i = 0; i < rank; i++)
varIndices[i] = origin[i] + indices[i] * stride[i];
string item = ("[" + string.Join(",", Array.ConvertAll(varIndices, i => i.ToString())) + "]").PadRight(prefix);
Console.Write(item);
int left = bufferWidth - item.Length;
while (left > cell && indices[lastIndex] < data.GetLength(lastIndex))
{
//.........这里部分代码省略.........