//TODO method should go to helper module or VectorModule //TODO probably not very efficient public static IVector <object> BoxVector(IVector vector, IVectorBuilder vectorBuilder) { switch (Type.GetTypeCode(vector.ElementType)) { //TODO implement conversions for all types case TypeCode.String: var strVec = (IVector <string>)vector; var boxedVals = strVec.Data.Values.Select(v => (object)v).ToArray(); var boxedVec = vectorBuilder.Create <object>(boxedVals); return(boxedVec); case TypeCode.Int32: var intVec = (IVector <int>)vector; var boxedValsInt = intVec.Data.Values.Select(v => (object)v).ToArray(); var boxedVecInt = vectorBuilder.Create <object>(boxedValsInt); return(boxedVecInt); case TypeCode.DateTime: var dtVec = (IVector <DateTime>)vector; var boxedValsDt = dtVec.Data.Values.Select(v => (object)v).ToArray(); var boxedVecDt = vectorBuilder.Create <object>(boxedValsDt); return(boxedVecDt); default: return(null); } }
//TODO unsafe public static IVector <T> unboxVector <T>(IVector <object> vector, IVectorBuilder vectorBuilder) { var unboxedVals = vector.Data.Values.Select(v => (T)v).ToArray(); var unboxedVec = vectorBuilder.Create <T>(unboxedVals); return(unboxedVec); }
public IVector <T> Build <T>(IVecConstructionCmd vectorConstruction, IVector <T>[] vectors) { if (vectorConstruction.GetType() == typeof(Return)) { var vcReturn = (Return)vectorConstruction; return(vectors[vcReturn.VectorLocation]); } else if (vectorConstruction.GetType() == typeof(Combine)) { var combine = (Combine)vectorConstruction; var data = combine.VecConstructionCmds.Select(vc => (IVector)VectorBuilderInstance.Build(vc, vectors)).ToArray(); var frameData = VectorBuilderInstance.Create(data); var rowReaders = new object[combine.Size]; for (long i = 0; i < combine.Size; i++) { rowReaders[i] = new RowReaderVector <object>(frameData, VectorBuilderInstance, i); } var objVec = new ArrayVector <object>(new ArrayVectorData <object>(rowReaders)); //var objectSeq = new ObjectSequence<T>(objVec); return(Vector.unboxVector <T>(objVec, VectorBuilderInstance)); } else if (vectorConstruction.GetType() == typeof(GetRange)) { var cmd = (GetRange)vectorConstruction; //TODO var range = (IntervalOf <Int64>)cmd.RangeBoundary; var newVecData = this.buildArrayVector(cmd.VecConstructionCmd, vectors); var newData = new T[(range.End - range.Start + 1)]; long idx = 0; for (long i = range.Start; i <= range.End; i++) { newData[idx] = newVecData[i]; idx++; } return(new ArrayVector <T>(new ArrayVectorData <T>(newData))); } else { return(null); } }