Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/17/16 15:41:33 (8 years ago)
Author:
gkronber
Message:

#2697: reverse merge of r14378, r14390, r14391, r14393, r14394, r14396

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/DatasetExtensions.cs

    r14393 r14400  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    24 using System.Linq;
    2523
    2624namespace HeuristicLab.Problems.DataAnalysis {
    2725  public static class DatasetExtensions {
    28     public static double[,] ToArray(this IDataset dataset, IEnumerable<string> variables, IEnumerable<int> rows) {
    29       return ToArray(dataset,
    30         variables,
    31         transformations: variables.Select(_ => (ITransformation<double>)null),  // no transform
    32         rows: rows);
    33     }
    34     public static double[,] ToArray(this IDataset dataset, IEnumerable<string> variables, IEnumerable<ITransformation<double>> transformations, IEnumerable<int> rows) {
    35       string[] variablesArr = variables.ToArray();
    36       int[] rowsArr = rows.ToArray();
    37       ITransformation<double>[] transformArr = transformations.ToArray();
    38       if (transformArr.Length != variablesArr.Length)
    39         throw new ArgumentException("Number of variables and number of transformations must match.");
    40 
    41       double[,] matrix = new double[rowsArr.Length, variablesArr.Length];
    42 
    43       for (int i = 0; i < variablesArr.Length; i++) {
    44         var origValues = dataset.GetDoubleValues(variablesArr[i], rowsArr);
    45         var values = transformArr[i] != null ? transformArr[i].Apply(origValues) : origValues;
    46         int row = 0;
    47         foreach (var value in values) {
    48           matrix[row, i] = value;
    49           row++;
    50         }
     26    public static IEnumerable<T> TakeEvery<T>(this IEnumerable<T> xs, int nth) {
     27      int i = 0;
     28      foreach (var x in xs) {
     29        if (i % nth == 0) yield return x;
     30        i++;
    5131      }
    52 
    53       return matrix;
    5432    }
    5533  }
Note: See TracChangeset for help on using the changeset viewer.