use of tech.tablesaw.selection.Selection in project symja_android_library by axkr.
the class FloatIndex method atLeast.
public Selection atLeast(float value) {
Selection selection = new BitmapBackedSelection();
Float2ObjectSortedMap<IntArrayList> tail = index.tailMap(value);
for (IntArrayList keys : tail.values()) {
addAllToSelection(keys, selection);
}
return selection;
}
use of tech.tablesaw.selection.Selection in project symja_android_library by axkr.
the class Rows method tail.
public static void tail(int rowsToInclude, Table oldTable, Table newTable) {
int oldTableSize = oldTable.rowCount();
int start = oldTableSize - rowsToInclude;
Selection rows = new BitmapBackedSelection(rowsToInclude);
for (int i = start; i < oldTableSize; i++) {
rows.add(i);
}
copyRowsToTable(rows, oldTable, newTable);
}
use of tech.tablesaw.selection.Selection in project symja_android_library by axkr.
the class StandardTableSliceGroup method splitOn.
/**
* Splits the sourceTable table into sub-tables, grouping on the columns whose names are given in
* splitColumnNames
*/
private void splitOn(String... splitColumnNames) {
Map<ByteArray, Selection> selectionMap = new LinkedHashMap<>();
Map<ByteArray, String> sliceNameMap = new HashMap<>();
List<Column<?>> splitColumns = getSourceTable().columns(splitColumnNames);
if (containsTextColumn(splitColumns)) {
for (int i = 0; i < getSourceTable().rowCount(); i++) {
ByteArrayList byteArrayList = new ByteArrayList();
StringBuilder stringKey = new StringBuilder();
int count = 0;
for (Column<?> col : splitColumns) {
stringKey.append(col.getString(i));
if (count < splitColumns.size() - 1) {
stringKey.append(SPLIT_STRING);
}
byteArrayList.addElements(byteArrayList.size(), col.asBytes(i));
count++;
}
// Add to the matching selection.
ByteArray byteArray = new ByteArray(byteArrayList.toByteArray());
Selection selection = selectionMap.getOrDefault(byteArray, new BitmapBackedSelection());
selection.add(i);
selectionMap.put(byteArray, selection);
sliceNameMap.put(byteArray, stringKey.toString());
}
} else {
// handle the case where split is on non-text-columns
int byteSize = getByteSize(splitColumns);
for (int i = 0; i < getSourceTable().rowCount(); i++) {
StringBuilder stringKey = new StringBuilder();
ByteBuffer byteBuffer = ByteBuffer.allocate(byteSize);
int count = 0;
for (Column<?> col : splitColumns) {
stringKey.append(col.getString(i));
if (count < splitColumns.size() - 1) {
stringKey.append(SPLIT_STRING);
}
byteBuffer.put(col.asBytes(i));
count++;
}
// Add to the matching selection.
ByteArray byteArray = new ByteArray(byteBuffer.array());
Selection selection = selectionMap.getOrDefault(byteArray, new BitmapBackedSelection());
selection.add(i);
selectionMap.put(byteArray, selection);
sliceNameMap.put(byteArray, stringKey.toString());
}
}
// Construct slices for all the values in our maps
for (Entry<ByteArray, Selection> entry : selectionMap.entrySet()) {
TableSlice slice = new TableSlice(getSourceTable(), entry.getValue());
slice.setName(sliceNameMap.get(entry.getKey()));
addSlice(slice);
}
}
use of tech.tablesaw.selection.Selection in project symja_android_library by axkr.
the class DataFrameJoiner method createMultiColSelection.
/**
* Create a big multicolumn selection for all join columns in the given table. Joins two tables.
*
* @param table the table that used to generate Selection.
* @param ri row number of row in table.
* @param indexes a reverse index for every join column in the table.
* @param selectionSize max size in table .
* @param joinColumnIndexes the column index of join key in tables
* @return selection created
*/
private Selection createMultiColSelection(Table table, int ri, List<Index> indexes, int selectionSize, List<Integer> joinColumnIndexes) {
Selection multiColSelection = Selection.withRange(0, selectionSize);
int i = 0;
for (Integer joinColumnIndex : joinColumnIndexes) {
Column<?> col = table.column(joinColumnIndex);
Selection oneColSelection = selectionForColumn(col, ri, indexes.get(i));
// and the selections.
multiColSelection = multiColSelection.and(oneColSelection);
i++;
}
return multiColSelection;
}
use of tech.tablesaw.selection.Selection in project symja_android_library by axkr.
the class RollingColumn method calc.
@SuppressWarnings({ "unchecked" })
public <INCOL extends Column<?>, OUT> Column<?> calc(AggregateFunction<INCOL, OUT> function) {
// TODO: the subset operation copies the array. creating a view would likely be more efficient
Column<?> result = function.returnType().create(generateNewColumnName(function));
for (int i = 0; i < window - 1; i++) {
result.appendMissing();
}
for (int origColIndex = 0; origColIndex < column.size() - window + 1; origColIndex++) {
Selection selection = new BitmapBackedSelection();
selection.addRange(origColIndex, origColIndex + window);
INCOL subsetCol = (INCOL) column.subset(selection.toArray());
OUT answer = function.summarize(subsetCol);
if (answer instanceof Number) {
Number number = (Number) answer;
((DoubleColumn) result).append(number.doubleValue());
} else {
result.appendObj(answer);
}
}
return result;
}
Aggregations