Пример #1
0
 public void TensorConvertToVector()
 {
     using (var cpuTensor = _cpu.Create3DTensor(Enumerable.Range(0, 3).Select(i => _cpu.CreateMatrix(4, 4, (j, k) => (i + 1) * (j + 1) * (k + 1))).ToList()))
         using (var gpuTensor = _cuda.Create3DTensor(cpuTensor.AsIndexable()))
             using (var cpuVector = cpuTensor.ConvertToVector())
                 using (var gpuVector = gpuTensor.ConvertToVector())
                     FloatingPointHelper.AssertEqual(cpuVector.AsIndexable(), gpuVector.AsIndexable());
 }
Пример #2
0
        /// <summary>
        /// Create a 3D tensor
        /// </summary>
        /// <param name="lap"></param>
        /// <param name="tensor">The serialised representation of the 3D tensor</param>
        /// <returns></returns>
        public static I3DTensor Create3DTensor(this ILinearAlgebraProvider lap, FloatTensor tensor)
        {
            var ret = lap.Create3DTensor(tensor.RowCount, tensor.ColumnCount, tensor.Depth);

            ret.Data = tensor;
            return(ret);
            //return lap.Create3DTensor(tensor.Matrix.Select(m => CreateMatrix(lap, m)).ToList());
        }
Пример #3
0
 public void TensorConvertToVector()
 {
     Load();
     using var cpuTensor = _cpu.Create3DTensor(Enumerable.Range(0, 3).
                                               Select(i => _cpu.CreateMatrix(4, 4, (j, k) => (i + 1) * (j + 1) * (k + 1))).ToList());
     using var gpuTensor = _cuda.Create3DTensor(cpuTensor.Data);
     using var cpuVector = cpuTensor.ReshapeAsVector();
     using var gpuVector = gpuTensor.ReshapeAsVector();
     FloatingPointHelper.AssertEqual(cpuVector.AsIndexable(), gpuVector.AsIndexable());
     Cleanup();
 }
Пример #4
0
        /// <summary>
        /// Creates a 3D tensor from a list of matrices
        /// </summary>
        /// <param name="lap"></param>
        /// <param name="matrices">List of matrices</param>
        /// <returns></returns>
        public static I3DTensor Create3DTensor(this ILinearAlgebraProvider lap, FloatMatrix[] matrices)
        {
            var first = matrices[0];
            var ret   = lap.Create3DTensor(first.RowCount, first.ColumnCount, matrices.Length);

            ret.Data = new FloatTensor {
                Matrix = matrices
            };
            return(ret);
        }
Пример #5
0
        I4DTensor _FormIntoTensor(ILinearAlgebraProvider lap, IVector vector, I4DTensor tensor)
        {
            var indexableVector = vector.AsIndexable();
            var tensorList      = new List <I3DTensor>();

            for (var i = 0; i < tensor.Count; i++)
            {
                var matrixList = new List <IMatrix>();
                for (var j = 0; j < tensor.Depth; j++)
                {
                    matrixList.Add(lap.CreateMatrix(tensor.RowCount, tensor.ColumnCount, indexableVector[j]));
                }
                tensorList.Add(lap.Create3DTensor(matrixList));
            }
            return(lap.Create4DTensor(tensorList));
        }
 /// <summary>
 /// Create a 3D tensor
 /// </summary>
 /// <param name="lap"></param>
 /// <param name="tensor">The serialised representation of the 3D tensor</param>
 /// <returns></returns>
 public static I3DTensor Create3DTensor(this ILinearAlgebraProvider lap, FloatTensor tensor)
 {
     return(lap.Create3DTensor(tensor.Matrix.Select(m => CreateMatrix(lap, m)).ToList()));
 }