Mercurial > hg > ugly-duckling
annotate src/app/services/feature-extraction/FeatureReducers.ts @ 302:c6dd5752f7f7
Change to new StreamingResponse type.
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Fri, 12 May 2017 01:40:21 +0100 |
parents | 73beb0e970c5 |
children | dc415a620b15 |
rev | line source |
---|---|
dev@241 | 1 /** |
dev@241 | 2 * Created by lucast on 26/04/2017. |
dev@241 | 3 */ |
dev@302 | 4 import {StreamingResponse} from "piper/StreamingService"; |
dev@241 | 5 |
dev@241 | 6 export const arrayReducer = <T>(acc: T[], val: T[]): T[] => { |
dev@302 | 7 for (let i = 0, len = val.length; i < len; ++i) { |
dev@302 | 8 acc.push(val[i]); |
dev@302 | 9 } |
dev@241 | 10 return acc; |
dev@241 | 11 }; |
dev@241 | 12 |
dev@241 | 13 export const typedArrayReducer = (acc: Float32Array, |
dev@241 | 14 val: Float32Array): Float32Array => { |
dev@241 | 15 return Float32Array.of(...acc, ...val); |
dev@241 | 16 }; |
dev@241 | 17 |
dev@241 | 18 const inPlaceTypedArrayReducer = (acc: Float32Array, |
dev@241 | 19 val: Float32Array, |
dev@241 | 20 i: number): Float32Array => { |
dev@241 | 21 acc.set(val, i); |
dev@241 | 22 return acc; |
dev@241 | 23 }; |
dev@241 | 24 |
dev@241 | 25 export const streamingResponseReducer = (acc: StreamingResponse, |
dev@302 | 26 val: StreamingResponse): |
dev@302 | 27 StreamingResponse => { |
dev@302 | 28 acc.progress = val.progress; |
dev@302 | 29 if (val.configuration) { |
dev@302 | 30 acc.configuration = val.configuration; |
dev@302 | 31 } |
dev@302 | 32 arrayReducer(acc.features, val.features); |
dev@302 | 33 return acc; |
dev@302 | 34 }; |