本文整理汇总了C#中ILArray.GetShifted方法的典型用法代码示例。如果您正苦于以下问题:C# ILArray.GetShifted方法的具体用法?C# ILArray.GetShifted怎么用?C# ILArray.GetShifted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILArray
的用法示例。
在下文中一共展示了ILArray.GetShifted方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Iterator_Performance
public void Test_Iterator_Performance() {
int errorCode = 0;
// success?
try {
double[] data = new double[4 * 3 * 2] {0, 1,2,3,4,5,6,7,8,9,10
,11,12,13,14,15,16,17,18,19,20,21,22,23 };
ILArray<double> A = new ILArray<double>(data, 4,3,2);
ILArray<double> Ar = (ILArray<double>)A.GetShifted(2);
ILPerformer p = new ILPerformer();
int counter = 0;
ILIterator<double> it = A.CreateIterator(ILIteratorPositions.ILEnd, 0);
ILIterator<double> it1 = Ar.CreateIterator(ILIteratorPositions.ILEnd, 2);
double val = 0.0;
do {
if (it.Increment() != counter++)
throw new Exception("invalid iterator value!");
} while (!it.IsAtEnd());
// shifted (1) physical
errorCode = 1;
double[] results = new double[24] {0,4,8,12,16,20,1,5,9,13,17,21
,2,6,10,14,18,22,3,7,11,15,19,23};
it = A.CreateIterator(ILIteratorPositions.ILEnd, 1);
counter = 0;
do {
if (it.Increment() != results[counter])
throw new Exception("invalid phy iterator value!");
if (it1.Increment() != results[counter++])
throw new Exception("invalid ref iterator value!");
} while (!it.IsAtEnd());
results = new double[24] {0,4,8,12,16,20,1,5,9,13,17,21
,2,6,10,14,18,22,3,7,11,15,19,23};
data = new double[1000 * 1000 * 10];
A = new ILArray<double>(data, 1000, 1000, 10);
//// test the IEnumerable way of doing this
//errorCode = 1;
//p.Tic();
//foreach (double v in A) {
// val = v;
//}
//p.Toc();
//Info("[1000 x 1000 x 10] IEnumarable 'foreach' Iterator: " + p.ToString());
errorCode = 2;
// iterate the classic way:
val = 2.23;
double dura = 0.0, dura1= 0.0;
double itIncCounter = 0.0;
it = A.CreateIterator(ILIteratorPositions.ILStart, 0);
it1 = A.CreateIterator(ILIteratorPositions.ILStart, 1);
ILPerformer p1 = new ILPerformer();
do {
p1.Tic();
val = it1.Increment();
p1.Toc();
dura1 += p1.Duration; // outer time needed
p.Tic();
val = it.Increment();
p.Toc();
//dummy += Environment.TickCount - it.Dummy; // internal time needed
dura += p.Duration; // outer time needed
itIncCounter++;
} while (itIncCounter < data.Length);
Info("[1000 x 1000 x 10] ILIterator Phys leadDim: 0 ->"
+ dura.ToString() + " leadDim: 1 ->" + dura1.ToString()
+ " incCount:" + itIncCounter);
errorCode = 3;
ILArray<double> B = (ILArray<double>)A.T;
p.Tic();
it = B.CreateIterator(ILIteratorPositions.ILStart, 0);
it1 = B.CreateIterator(ILIteratorPositions.ILStart, 1);
dura = 0.0; dura1 = 0.0; itIncCounter = 0;
do {
p1.Tic();
val = it1.Increment();
p1.Toc();
dura1 += p1.Duration; // outer time needed
p.Tic();
val = it.Increment();
p.Toc();
//dummy += Environment.TickCount - it.Dummy; // internal time needed
dura += p.Duration; // outer time needed
itIncCounter++;
} while (itIncCounter < data.Length);
p.Toc();
Info("[1000 x 1000 x 10] ILIterator - Ref. leadDim: 0 ->"
+ dura.ToString() + " leadDim: 1 ->" + dura1.ToString()
+ " incCount:" + itIncCounter);
Success("Test_Iterator_Performance successful.");
} catch (Exception e) {
Error("Test_Iterator_Performance failed at step: " + errorCode + " Msg: " + e.Message);
}
}
示例2: Test_readonly
public void Test_readonly() {
int errorCode = 0;
// after detaching all references but one, that storage is writeable ?
try {
object[] data = new object[120];
for (int i = 120; i-- > 0; )
data[i] = (double)i;
ILArray<object> B = new ILArray<object>(data, 5, 4, 1, 3, 2, 1);
errorCode = 1;
if (B.IsReadonly() == true)
throw new Exception();
errorCode = 2;
ILArray<object> A1 = B[3,"0:2,4;1,3;0;2,1,0,1"];
if (A1.IsReadonly() == false | B.IsReadonly() == false)
throw new Exception();
errorCode = 3;
ILArray<object> A2 = B.GetShifted(2);
if (A1.IsReadonly() == false | B.IsReadonly() == false | A2.IsReadonly() == false)
throw new Exception();
errorCode = 4;
A1.Detach();
if (A1.IsReadonly() == true | B.IsReadonly() == false | A2.IsReadonly() == false)
throw new Exception();
errorCode = 5;
A2.Detach();
if (A1.IsReadonly() == true | B.IsReadonly() == true | A2.IsReadonly() == true)
throw new Exception();
errorCode = 6;
ILArray<object> A3 = A2.S(3);
if (A3.IsReadonly() == false | A2.IsReadonly() == false)
throw new Exception();
errorCode = 7;
A2.Detach();
if (A3.IsReadonly() == true | A2.IsReadonly() == true)
throw new Exception();
errorCode = 8;
if (Object.Equals(A3,null)) {
ILArray<object> A4 = A3[2,"0:2,1"];
if (A3.IsReadonly() == false | A4.IsReadonly() == false)
throw new Exception();
A4.Dispose();
}
// after leaving the scope -> A3 is only reference now?
// (Is not defined when the GC will clean up A4!)
if (A3.IsReadonly() == true)
throw new Exception("A3 should be writable!");
Success("Test_readonly successful.");
}
catch (Exception e) {
Error("Test_readonly failed at step: " + errorCode + " Msg: " + e.Message);
}
}
示例3: Success
/* public void Test_Eye() {
int errorCode = 0;
try {
double[] data = new double[24];
for (int i = 0; i < data.Length; i++)
data[i] = i;
ILArray<double> A = new ILArray<double>(data, 2, 3, 4);
Success("Test_Apply successfull");
}
catch (Exception e) {
Error("Test_Apply failed at errorCode: " + errorCode + " Reason: " + e.Message);
}
}
*/
public void Test_Cat() {
int errorCode = 0;
try {
double[] data = new double[24];
for (int i = 0; i < data.Length; i++)
data[i] = i;
ILArray<double> A = new ILArray<double>(data, 2, 3, 4);
ILArray<double> B = A.GetShifted(3);
ILArray<double> C = ILMath.horzcat(A, A);
ILArray<double> CRef = ILMath.horzcat(B, B);
double[] result = new double[48] { 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 18, 19, 20, 21, 22, 23 };
ILArray<double> Result = new ILArray<double>(result, 2, 6, 4);
if (!Result.Equals(C)) {
throw new Exception("Test Cat: Test result failed: invalid values detected.");
}
errorCode = 2;
if (!Result.Equals(CRef)) {
throw new Exception("Test Cat: Test result failed: invalid values detected.");
}
errorCode = 3;
// test vertcat
result = new double[72] { 0, 1, 0, 1, 0, 1, 2, 3, 2, 3, 2, 3, 4, 5, 4, 5, 4, 5, 6, 7, 6, 7, 6, 7, 8, 9, 8, 9, 8, 9, 10, 11, 10, 11, 10, 11, 12, 13, 12, 13, 12, 13, 14, 15, 14, 15, 14, 15, 16, 17, 16, 17, 16, 17, 18, 19, 18, 19, 18, 19, 20, 21, 20, 21, 20, 21, 22, 23, 22, 23, 22, 23 };
Result = new ILArray<double>(result, 6, 3, 4);
C = ILMath.vertcat(A,A,A);
if (!Result.Equals(C)) {
throw new Exception("Test Cat: Test result failed: invalid values detected.");
}
errorCode = 4;
CRef = ILMath.vertcat(B,B,B);
if (!Result.Equals(C)) {
throw new Exception("Test Cat: Test result failed: invalid values detected.");
}
// test large
errorCode = 5;
A = (ILArray<double>)ILMath.ones(1000, 1000, 10);
Result = A.Concat(A, 2);
if (Result.m_dimensions.NumberOfDimensions != 3 || Result.m_dimensions[0] != 1000 || Result.m_dimensions[1] != 1000
|| Result.m_dimensions[2] != 20) {
throw new Exception("Test Cat: Result dimension mismatch!");
}
ILArray<double> dummy = ILMath.sum(Result);
if (ILMath.sumall(dummy)!= 20000000)
throw new Exception("sum partially wrong!");
dummy = ILMath.sum(dummy);
if (ILMath.sumall(dummy)!= 20000000)
throw new Exception("sum partially wrong!");
dummy = ILMath.sum(dummy);
if (ILMath.sumall(dummy)!= 20000000)
throw new Exception("sum partially wrong!");
if (ILMath.sum(ILMath.sum(ILMath.sum(Result))) != 20000000) {
throw new Exception ("Test Cat: Invalid values detected.");
}
// test Reference Concatenation
errorCode = 6;
B = A.GetShifted(3);
Result = B.Concat(B,2);
if (Result.m_dimensions.NumberOfDimensions != 3 || Result.m_dimensions[0] != 1000 || Result.m_dimensions[1] != 1000
|| Result.m_dimensions[2] != 20) {
throw new Exception("Test Cat: Result dimension mismatch!");
}
dummy = ILMath.sum(Result);
if (ILMath.sumall(dummy)!= 20000000)
throw new Exception("sum partially wrong!");
dummy = ILMath.sum(dummy);
if (ILMath.sumall(dummy)!= 20000000)
throw new Exception("sum partially wrong!");
dummy = ILMath.sum(dummy);
if (ILMath.sumall(dummy)!= 20000000)
throw new Exception("sum partially wrong!");
if (ILMath.sum(ILMath.sum(ILMath.sum(Result))) != 20000000) {
throw new Exception ("Test Cat: Invalid values detected.");
}
Success("Test_Cat successfull");
} catch (Exception e) {
Error("Test_Cat failed at errorCode: " + errorCode + " Reason: " + e.Message);
}
}