public void SliceDimension() { var c = new DataCube3 <int, int, int, int>(); c.Set(0, 0, 0, 1); c.Set(0, 0, 1, 2); c.Set(0, 1, 0, 3); c.Set(0, 1, 1, 4); c.Set(1, 0, 0, 10); c.Set(1, 0, 1, 20); c.Set(1, 1, 0, 30); c.Set(1, 1, 1, 40); var firstDimensionSlices = c.SliceDimension1(); Assert.Equal(2, firstDimensionSlices.Values.Count()); var zeroSlice = firstDimensionSlices.Get(0).Get(); Assert.Equal(4, zeroSlice.Values.Count()); Assert.Equal(1, zeroSlice.Get(0, 0).Get()); Assert.Equal(2, zeroSlice.Get(0, 1).Get()); Assert.Equal(3, zeroSlice.Get(1, 0).Get()); Assert.Equal(4, zeroSlice.Get(1, 1).Get()); var oneSlice = firstDimensionSlices.Get(1).Get(); Assert.Equal(4, oneSlice.Values.Count()); Assert.Equal(10, oneSlice.Get(0, 0).Get()); Assert.Equal(20, oneSlice.Get(0, 1).Get()); Assert.Equal(30, oneSlice.Get(1, 0).Get()); Assert.Equal(40, oneSlice.Get(1, 1).Get()); }
public void Transform() { var c = new DataCube3 <int, int, int, int>(); c.Set(0, 0, 0, 1); c.Set(0, 0, 1, 2); c.Set(0, 1, 0, 3); c.Set(0, 1, 1, 4); c.Set(1, 0, 0, 10); c.Set(1, 0, 1, 20); c.Set(1, 1, 0, 30); c.Set(1, 1, 1, 40); var sum = c.Transform(_ => Position0.Create(), (a, b) => a + b); Assert.Equal(1 + 2 + 3 + 4 + 10 + 20 + 30 + 40, sum.Value.Get()); var Position = c.Transform(_ => Position0.Create(), (a, b) => a * b); Assert.Equal(1 * 2 * 3 * 4 * 10 * 20 * 30 * 40, Position.Value.Get()); var firstDimensionSums = c.Transform(p => Position1.Create(p.ProductValue1), (a, b) => a + b); Assert.Equal(2, firstDimensionSums.Values.Count()); Assert.Equal(1 + 2 + 3 + 4, firstDimensionSums.Get(0).Get()); Assert.Equal(10 + 20 + 30 + 40, firstDimensionSums.Get(1).Get()); }
public void RollUpDimension() { var c = new DataCube3 <int, int, int, int>(); c.Set(0, 0, 0, 1); c.Set(0, 0, 1, 2); c.Set(0, 1, 0, 3); c.Set(0, 1, 1, 4); c.Set(1, 0, 0, 10); c.Set(1, 0, 1, 20); c.Set(1, 1, 0, 30); c.Set(1, 1, 1, 40); var withoutFirstDimension = c.RollUpDimension1((a, b) => a + b); Assert.Equal(4, withoutFirstDimension.Values.Count()); Assert.Equal(1 + 10, withoutFirstDimension.Get(0, 0).Get()); Assert.Equal(2 + 20, withoutFirstDimension.Get(0, 1).Get()); Assert.Equal(3 + 30, withoutFirstDimension.Get(1, 0).Get()); Assert.Equal(4 + 40, withoutFirstDimension.Get(1, 1).Get()); var thirdDimension = withoutFirstDimension.RollUpDimension1((a, b) => a + b); Assert.Equal(2, thirdDimension.Values.Count()); Assert.Equal(1 + 10 + 3 + 30, thirdDimension.Get(0).Get()); Assert.Equal(2 + 20 + 4 + 40, thirdDimension.Get(1).Get()); }
/// <summary> /// Creates a new 3-dimensional data cube. /// </summary> public static DataCube3 <P1, P2, P3, TValue> Create <T, P1, P2, P3, TValue>( IEnumerable <T> source, Func <T, P1> p1, Func <T, P2> p2, Func <T, P3> p3, Func <T, TValue> value) { var dataCube = new DataCube3 <P1, P2, P3, TValue>(); foreach (var v in source) { dataCube.Set( p1(v), p2(v), p3(v), value(v) ); } return(dataCube); }