Пример #1
0
 /// <summary>
 /// Returns a vector averaged from the data vectors
 /// </summary>
 /// <param name="indices">Indices of the data vectors to use in the averaged vector</param>
 public IVector GetAverageFromData(IReadOnlyList <int> indices)
 {
     using (var data = _lap.CreateMatrixFromColumns(indices.Select(i => _data[i]).ToList())) {
         var result = data.RowSums();
         result.Multiply(1f / indices.Count);
         return(result);
     }
 }
Пример #2
0
        public void TestMatrixCreationFromColumns()
        {
            var values = new[] {
                Enumerable.Range(0, 10).Select(v => (float)v).ToArray(),
                Enumerable.Range(0, 10).Select(v => (float)v * 2).ToArray(),
                Enumerable.Range(0, 10).Select(v => (float)v * 3).ToArray(),
            };
            var cpuRowList = values.Select(v => _cpu.CreateVector(v)).ToList();
            var cpuMatrix  = _cpu.CreateMatrixFromColumns(cpuRowList);

            var gpuRowList = values.Select(v => _cuda.CreateVector(v)).ToList();

            using (var gpuMatrix = _cuda.CreateMatrixFromColumns(gpuRowList)) {
                FloatingPointHelper.AssertEqual(cpuMatrix.AsIndexable(), gpuMatrix.AsIndexable());
            }
            gpuRowList.ForEach(v => v.Dispose());
        }