view src/app/services/feature-extraction/FeatureReducers.ts @ 303:dc415a620b15

Merge branch 'dev/tracks-shape' of github.com:cannam/ugly-duckling into dev/tracks-shape =
author Lucas Thompson <dev@lucas.im>
date Fri, 12 May 2017 02:19:03 +0100
parents c6dd5752f7f7 46a6b91ea51b
children 98490d0ceb77
line wrap: on
line source
/**
 * Created by lucast on 26/04/2017.
 */
import {StreamingResponse} from "piper/StreamingService";

export const arrayReducer = <T>(acc: T[], val: T[]): T[] => {
  for (let i = 0, len = val.length; i < len; ++i) {
    acc.push(val[i]);
  }
  return acc;
};

export const typedArrayReducer = (acc: Float32Array,
                                  val: Float32Array): Float32Array => {
  return Float32Array.of(...acc, ...val);
};

const inPlaceTypedArrayReducer = (acc: Float32Array,
                                  val: Float32Array,
                                  i: number): Float32Array => {
  acc.set(val, i);
  return acc;
};

export const streamingResponseReducer = (acc: StreamingResponse,
                                         val: StreamingResponse):
  StreamingResponse => {
  acc.progress = val.progress;
  if (val.configuration) {
    acc.configuration = val.configuration;
  }
  arrayReducer(acc.features, val.features);
  return acc;
};