本文整理汇总了C#中ILArray类的典型用法代码示例。如果您正苦于以下问题:C# ILArray类的具体用法?C# ILArray怎么用?C# ILArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ILArray类属于命名空间,在下文中一共展示了ILArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: sphere
/// <summary>
/// Create surface data of a sphere
/// </summary>
/// <param name="n">number of facettes per angle</param>
/// <param name="X">[output] X coords</param>
/// <param name="Y">[output] Y coords</param>
/// <param name="Z">[output] Z coords</param>
public static void sphere(int n, out ILArray<double> X,out ILArray<double> Y,out ILArray<double> Z) {
ILArray<double> phi = repmat(linspace(-pi,pi,n).T,1,n);
ILArray<double> rho = repmat(linspace(0,pi,n),n,1);
Y = sin(phi) * sin(rho);
X = cos(phi) * sin(rho);
Z = cos(rho);
}
示例2: TestBucketSortArrayMatrixRow
private void TestBucketSortArrayMatrixRow() {
try {
ILArray<string> A = new ILArray<string>(3,4);
A[0,0] = "abc";
A[0,1] = "rtu";
A[0,2] = "sfkw";
A[0,3] = "lsdkfi";
A[1,0] = "iowejkc";
A[1,1] = "cjks";
A[1,2] = "wokys";
A[1,3] = "suem,";
A[2,0] = "fgj";
A[2,1] = "JKSF";
A[2,2] = "SEs";
A[2,3] = "SEFsr";
ILArray<double> ind;
ILArray<string> res = ILMath.sort(A,out ind,0,false);
if (!res.Equals(A[ind]))
throw new Exception("invalid indices/values detected");
ILArray<Int16> indI = ILMath.toint16(ILMath.counter(0.0,1.0,A.Dimensions.ToIntArray()));
res = ILMath.sort(A,ref indI, 0, true, new ILASCIIKeyMapper());
if (!res.Equals(A[indI]))
throw new Exception("invalid indices/values detected");
Success(" elapsed: " + m_stopwatch.ElapsedMilliseconds + " ms");
} catch (Exception e) {
Error(0, e.Message);
}
}
示例3: WT_order
// Wake Code - Matlab
// Rasmus Christensen
// Control and Automation, Aalborg University
#endregion
internal static void WT_order(out ILArray<double> xOrder, out ILArray<double> yOrder, ILArray<double> xTurb, ILArray<double> yTurb)
{
#region "Used variables declaration"
ILArray<double> sorted;
ILArray<double> turbineOrder;
int sortCtr;
int i;
int j;
#endregion
sorted = sortrows(__[ xTurb.T, yTurb.T ], 1);
turbineOrder = zeros(length(sorted), 2);
sortCtr = 0;
for (i = 1; i <= length(sorted); i++)
{
for (j = i + 1; j <= length(sorted); j++)
{
if (sorted._(i, 1) == sorted._(j, 1))
{
sortCtr = sortCtr + 1;
}
}
turbineOrder[_(i, ':', i + sortCtr), _(':')] = sortrows(sorted[_(i, ':', i + sortCtr), _(':')], 2);
sortCtr = 0;
}
xOrder = turbineOrder[_(':'), _(1)];
yOrder = turbineOrder[_(':'), _(2)];
}
示例4: sin
/// <summary>
/// Sinus of array elements
/// </summary>
/// <param name="A">input array</param>
/// <returns>Sinus of elements from input array</returns>
/// <remarks><para>If the input array is empty, an empty array will be returned.</para>
/// <para>The array returned will be a dense array.</para></remarks>
public static /*!HC:outCls*/ ILArray<double> /*!HC:HCfuncname*/ sin (/*!HC:inCls1*/ ILArray<double> A) {
if (A.IsEmpty)
return /*!HC:outCls*/ ILArray<double> .empty(A.Dimensions);
ILDimension inDim = A.Dimensions;
/*!HC:outArr*/ double [] retDblArr;
// build ILDimension
int newLength = inDim.NumberOfElements;
//retDblArr = new /*!HC:outArr*/ double [newLength];
retDblArr = ILMemoryPool.Pool.New</*!HC:outArr*/ double > (newLength);
int leadDimLen = inDim [0];
// physical -> pointer arithmetic
unsafe
{
fixed (/*!HC:outArr*/ double * pOutArr = retDblArr)
fixed (/*!HC:inArr1*/ double * pInArr = A.m_data) {
/*!HC:outArr*/ double * lastElement = pOutArr + retDblArr.Length;
/*!HC:outArr*/ double * tmpOut = pOutArr;
/*!HC:inArr1*/ double * tmpIn = pInArr;
while (tmpOut < lastElement) { // HC02
/*!HC:HCCompute02*/
*tmpOut++ = /*!HC:HCoperation*/ Math.Sin ( *tmpIn++ ) /*!HC:HCpostOp*/ ;
}
}
}
return new /*!HC:outCls*/ ILArray<double> ( retDblArr, inDim );
}
示例5: ind2sub
/// <summary>
/// convert sequential index into subscript indices
/// </summary>
/// <param name="A">input array</param>
/// <param name="seqindex">sequential index</param>
/// <returns>subscript indices</returns>
/// <remarks><para>the length of the value returned will be the number of dimensions of A</para>
/// <para>if A is null or empty array, the return value will be of length 0</para>
/// </remarks>
/// <exception cref="System.IndexOutOfRangeException">if seqindex is < 0 or > numel(A)</exception>
public static int[] ind2sub(ILArray<complex> A, int seqindex) {
if (object.Equals(A,null) || A.IsEmpty)
return new int[0];
int [] ret = new int[A.Dimensions.NumberOfDimensions];
A.GetValueSeq(seqindex,ref ret);
return ret;
}
示例6: ROTATE_corrd
// Wake Code - Matlab
// Rasmus Christensen
// Control and Automation, Aalborg University
// N_turb = number of turbines.
// X_turb = x-position of turbine.
// Y_turb = y-position of turbine.
#endregion
internal static void ROTATE_corrd(out ILArray<double> out_x, out ILArray<double> out_y, ILArray<double> xTurb, ILArray<double> yTurb, double rotA)
{
#region "Used variables declaration"
ILArray<double> x_out;
ILArray<double> y_out;
int i;
#endregion
x_out = zeros(1, length(xTurb)); // Initialization x-coordinates
y_out = zeros(1, length(yTurb)); // Initialization y-coordinates
rotA = rotA * pi / 180; // Conversion to radians
for (i = 1; i <= length(xTurb); i++)
{
x_out._(i, '=', xTurb._(i) * cos(rotA) - xTurb._(i) * sin(rotA));
y_out._(i, '=', xTurb._(i) * sin(rotA) + yTurb._(i) * cos(rotA));
}
if (min_(x_out) < 0) // Moves the x-points if these are negative.
{
x_out = x_out + 500 + abs(min_(x_out));
}
if (min_(y_out) < 0) // Moves the y-points if these are negative.
{
y_out = y_out + 500 + abs(min_(y_out));
}
out_x = x_out;
out_y = y_out;
}
示例7: load
private static void load(string windMatFilePath, out ILArray<double> wind)
{
using (var WindMatFile = new ILMatFile(windMatFilePath))
{
wind = WindMatFile.GetArray<double>("wind");
}
}
示例8: trace
// DO NOT EDIT INSIDE THIS REGION !! CHANGES WILL BE LOST !!
/// <summary>
/// trace of matrix
/// </summary>
/// <param name="A">input matrix, size [m x n]</param>
/// <returns>scalar of same type as A with the sum of diagonal elements of A.</returns>
public static ILArray<complex> trace ( ILArray<complex> A) {
if (A.IsEmpty)
return ILArray<complex> .empty(A.Dimensions);
if (A.IsVector || A.IsScalar)
return A[0];
return sum(diag(A));
}
示例9: forwBackwGenCheck
private static void forwBackwGenCheck(IILFFT fft, ILArray<fcomplex> A, ILArray<fcomplex> Result, int dim, float mult) {
ILArray<fcomplex> B = fft.FFTForward1D(A, dim);
if (ILMath.sumall(ILMath.abs(Result - B))/A.Dimensions.NumberOfElements / A.Dimensions[dim] > (double)ILMath.MachineParameterFloat.eps * mult)
throw new Exception("invalid value");
B = fft.FFTBackward1D(B, dim);
if (ILMath.sumall(ILMath.abs(A - B))/A.Dimensions.NumberOfElements / A.Dimensions[dim] > (double)ILMath.MachineParameterFloat.eps * mult)
throw new Exception("invalid value");}
示例10: Vector
// The special constructor is used to deserialize values.
public Vector(SerializationInfo info, StreamingContext context)
{
label = (double)info.GetValue("label", typeof(double));
valuesMDF = (ILArray<double>)info.GetValue("valuesMDF", typeof(ILArray<double>));
values = (ILArray<double>)info.GetValue("values", typeof(ILArray<double>));
id = (int)info.GetValue("id", typeof(int));
}
示例11: cross
public static ILArray<double> cross(ILArray<double> A, ILArray<double> B, int dim)
{
// Input checking
if (!A.m_dimensions.IsSameShape(B.m_dimensions))
throw new ILDimensionMismatchException("Inputs must have the same size and shape.");
ILDimension outDims = A.m_dimensions;
double[] outArray = ILMemoryPool.Pool.New<double>(outDims.NumberOfElements);
if (dim >= outDims.NumberOfDimensions || dim < 0)
throw new Exception("Specified dim is out of bounds of the array!");
if (outDims[dim] != 3)
throw new Exception("Must have length 3 in the dimension where the cross product is taken.");
// Cross Product
int SID = outDims.SequentialIndexDistance(dim);
int crosses = outDims.NumberOfElements / 3;
int SID2 = 2 * SID;
for (int i = 0; i < crosses; i++)
{
outArray[i] = A.m_data[SID + i] * B.m_data[SID2 + i] - A.m_data[SID2 + i] * B.m_data[SID + i];
outArray[SID + i] = A.m_data[SID2 + i] * B.m_data[i] - A.m_data[i] * B.m_data[SID2 + i];
outArray[SID2 + i] = A.m_data[i] * B.m_data[SID + i] - A.m_data[SID + i] * B.m_data[i];
}
return new ILArray<double>(outArray, outDims);
}
示例12: ClusterX
public ClusterX(SerializationInfo info, StreamingContext context)
: base(info, context)
{
child = (Node)info.GetValue("child", typeof(Node));
covarianceMatrixMDF = (ILArray<double>)info.GetValue("covarianceMatrixMDF", typeof(ILArray<double>));
label = (double)info.GetValue("label", typeof(double));
}
示例13: Cluster
// The special constructor is used to deserialize values.
public Cluster(SerializationInfo info, StreamingContext context)
{
clusterPair = (ClusterPair)info.GetValue("clusterPair", typeof(ClusterPair));
items = (List<Vector>)info.GetValue("items", typeof(List<Vector>));
mean = (Vector)info.GetValue("mean", typeof(Vector));
meanMDF = (ILArray<double>)info.GetValue("meanMDF", typeof(ILArray<double>));
parent = (Node)info.GetValue("parent", typeof(Node));
}
示例14: imag
/// <summary>
/// imaginary part of complex array elements
/// </summary>
/// <param name="X">complex input array</param>
/// <returns>imaginary part of complex array</returns>
public static /*!HC:outCls1*/ ILArray<double> imag (/*!HC:inCls1*/ ILArray<complex> X) {
int nrX = X.m_dimensions.NumberOfElements;
/*!HC:outArr1*/ double [] retArr = new /*!HC:outArr1*/ double [nrX];
/*!HC:outCls1*/ ILArray<double> ret = new /*!HC:outCls1*/ ILArray<double> (retArr,X.m_dimensions);
for (int i= 0; i < nrX; i++) {
retArr[i] = X.GetValue(i).imag;
}
return ret;
}
示例15: Test_Serialize
public void Test_Serialize() {
int errorCode = 0;
try {
double[] data = new double[1000 * 1000 * 10];
String filename = "ILDoubleArray_SerializeTest1.ils";
for (int i = 0; i < data.Length; i++)
data[i] = (double)i;
ILArray<double> A = new ILArray<double>(data, 1000,1000,10);
FileStream fs = new FileStream(filename, FileMode.Create);
Info("Serializing to file: (please wait...)");
A.Serialize(fs);
fs.Close();
FileInfo fi = new FileInfo(filename);
Info("Serialized to file: [1000 x 1000 x 10] => " + ((int)(fi.Length/1024)) + "kB");
// create reference storage from smaler range -> should Detach()
errorCode = 1;
filename = "ILDoubleArray_SerializeTest2.ils";
fs = new FileStream(filename, FileMode.Create);
ILArray<double> AR1 = (ILArray<double>)A[0,"0:600;30:400;0:end"];
AR1.Serialize(fs);
fs.Close();
fi = new FileInfo(filename);
Info("Serialized to file: [600 x 360 x 10] => " + ((int)(fi.Length / 1024)) + "kB");
// if reference storage saved effective memory - keep it as reference
errorCode = 2;
filename = "ILDoubleArray_SerializeTest3.ils";
fs = new FileStream(filename, FileMode.Create);
ILArray<double> AR2 = (ILArray<double>)A[0,"0:end,0:end;0:end,0:end;0:end"];
AR2.Serialize(fs);
fs.Close();
fi = new FileInfo(filename);
Info("Serialized to file: [2000 x 2000 x 20] => " + ((int)(fi.Length / 1024)) + "kB");
// test if small reference would NOT store full data array
errorCode = 4;
filename = "ILDoubleArray_SerializeTest4.ils";
fs = new FileStream(filename, FileMode.Create);
ILArray<double> AR3 = (ILArray<double>)A["3;3;1"];
AR3.Serialize(fs);
fs.Close();
fi = new FileInfo(filename);
Info("Serialized to file: [1 x 1] => " + ((int)(fi.Length / 1024)) + "kB");
if (fi.Length > 1024 * 2)
throw new Exception("Small reference storages should get detached before serializing!");
errorCode = 5;
Success("Test_serialize successfull");
} catch (SerializationException e) {
Error("Test_serialize failed on ErrorCode: "+ errorCode +"due: " + e.Message);
} catch (Exception e) {
Error("Test_serialize failed on ErrorCode: " + errorCode + "due: " + e.Message);
}
}