use of org.knime.core.data.IntValue in project knime-core by knime.
the class TableSorterTest method runMemoryTest.
private void runMemoryTest(final int numRows, final int maxNumRowsPerContainer, final int maxOpenContainers) throws CanceledExecutionException {
// Create data with fields that consume a lot memory
DataTable inputTable = new TestData(numRows, 1);
BufferedDataTable bdt = m_exec.createBufferedDataTable(inputTable, m_exec);
BufferedDataTableSorter sorter = new BufferedDataTableSorter(bdt, Arrays.asList("Index"), new boolean[] { true });
sorter.setMaxOpenContainers(maxOpenContainers);
BufferedDataTable defaultResult = sorter.sort(m_exec);
sorter.setMaxRows(maxNumRowsPerContainer);
// 10MB free memory
long currentlyUsed = MemoryAlertSystem.getUsedMemory();
double fraction = Math.min(1, (currentlyUsed + (10 << 20)) / (double) MemoryAlertSystem.getMaximumMemory());
MemoryAlertSystem.getInstance().setFractionUsageThreshold(fraction);
try {
sorter.setMemService(MemoryAlertSystem.getInstance());
// run again with change settings
BufferedDataTable result = sorter.sort(m_exec);
// Check if column is sorted in ascending order
int prevValue = Integer.MIN_VALUE;
for (DataRow row : result) {
int thisValue = ((IntValue) row.getCell(0)).getIntValue();
Assert.assertTrue(thisValue >= prevValue);
}
// Check if it has the same results as defaultResult
Assert.assertTrue(defaultResult.getRowCount() == result.getRowCount());
RowIterator defaultIter = defaultResult.iterator();
RowIterator iter = result.iterator();
while (defaultIter.hasNext()) {
DataRow defaultRow = defaultIter.next();
DataRow row = iter.next();
Assert.assertTrue(defaultRow.getKey().getString().equals(row.getKey().getString()));
Iterator<DataCell> defaultCellIter = defaultRow.iterator();
Iterator<DataCell> cellIter = row.iterator();
while (defaultCellIter.hasNext()) {
Assert.assertTrue(defaultCellIter.next().equals(cellIter.next()));
}
}
} finally {
MemoryAlertSystem.getInstance().setFractionUsageThreshold(MemoryAlertSystem.DEFAULT_USAGE_THRESHOLD);
}
}
use of org.knime.core.data.IntValue in project knime-core by knime.
the class CreateByteVectorNodeModel method createRearranger.
private ColumnRearranger createRearranger(final DataTableSpec inSpec) {
final ColumnRearranger ret = new ColumnRearranger(inSpec);
final String[] includes = m_inputColumns.applyTo(inSpec).getIncludes();
if (m_removeInput.getBooleanValue()) {
ret.remove(includes);
}
final DataColumnSpecCreator newCol = new DataColumnSpecCreator(DataTableSpec.getUniqueColumnName(inSpec, m_outputColumn.getStringValue()), DenseByteVectorCell.TYPE);
newCol.setElementNames(includes);
final int[] sourceColumnIndices = SourceColumnsAsProperties.indices(m_inputColumns.applyTo(inSpec), inSpec);
for (int i = sourceColumnIndices.length; i-- > 0; ) {
if (sourceColumnIndices[i] < 0) {
throw new IllegalStateException("Unknown column: " + includes[i]);
}
}
ret.append(new SingleCellFactory(newCol.createSpec()) {
@Override
public DataCell getCell(final DataRow row) {
final DenseByteVectorCellFactory fac = new DenseByteVectorCellFactory(sourceColumnIndices.length);
for (int i = sourceColumnIndices.length; i-- > 0; ) {
DataCell cell = row.getCell(sourceColumnIndices[i]);
if (cell.isMissing()) {
if (m_failOnMissing.getBooleanValue()) {
throw new IllegalArgumentException("Missing value in the row: " + row.getKey() + "\nin the column: " + includes[i]);
} else {
// return DataType.getMissingCell();
fac.setValue(i, 0);
}
} else if (cell instanceof IntValue) {
int intValue = ((IntValue) cell).getIntValue();
if (intValue < 0 || intValue > 255) {
if (m_failOnOutOfInterval.getBooleanValue()) {
throw new IllegalArgumentException("Invalid value: " + intValue + "\nin row: " + row.getKey() + "\nin the column: " + includes[i]);
} else {
fac.setValue(i, 0);
}
} else {
fac.setValue(i, intValue);
}
} else {
throw new IllegalStateException("Not an int value: " + cell + " (" + cell.getType() + ")");
}
}
return fac.createDataCell();
}
});
return ret;
}
use of org.knime.core.data.IntValue in project knime-core by knime.
the class LinearInterpolationStatisticTB method consumeRow.
/**
* {@inheritDoc}
*/
@Override
protected void consumeRow(final DataRow dataRow) {
DataCell cell = dataRow.getCell(getColumnIndex());
if (cell.isMissing()) {
incMissing();
} else {
for (int i = 0; i < getNumMissing(); i++) {
DataCell res;
if (getPrevious().isMissing()) {
res = cell;
} else {
if (m_isDateColumn) {
DateAndTimeValue val = (DateAndTimeValue) cell;
DateAndTimeValue prevVal = (DateAndTimeValue) getPrevious();
boolean hasDate = val.hasDate() | prevVal.hasDate();
boolean hasTime = val.hasTime() | prevVal.hasTime();
boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
long prev = prevVal.getUTCTimeInMillis();
long next = val.getUTCTimeInMillis();
long lin = Math.round(prev + 1.0 * (i + 1) / (1.0 * (getNumMissing() + 1)) * (next - prev));
res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
} else {
DoubleValue val = (DoubleValue) cell;
double prev = ((DoubleValue) getPrevious()).getDoubleValue();
double next = val.getDoubleValue();
double lin = prev + 1.0 * (i + 1) / (1.0 * (getNumMissing() + 1)) * (next - prev);
if (getPrevious() instanceof IntValue) {
// get an int, create an int
res = new IntCell((int) Math.round(lin));
} else if (getPrevious() instanceof LongValue) {
// get an long, create an long
res = new LongCell(Math.round(lin));
} else {
res = new DoubleCell(lin);
}
}
}
addMapping(res);
}
resetMissing(cell);
}
}
use of org.knime.core.data.IntValue in project knime-core by knime.
the class AverageInterpolationStatisticTB method consumeRow.
/**
* {@inheritDoc}
*/
@Override
protected void consumeRow(final DataRow dataRow) {
DataCell cell = dataRow.getCell(getColumnIndex());
if (cell.isMissing()) {
incMissing();
} else {
for (int i = 0; i < getNumMissing(); i++) {
DataCell res;
if (getPrevious().isMissing()) {
res = cell;
} else {
if (m_isDateColumn) {
DateAndTimeValue val = (DateAndTimeValue) cell;
DateAndTimeValue prevVal = (DateAndTimeValue) getPrevious();
boolean hasDate = val.hasDate() | prevVal.hasDate();
boolean hasTime = val.hasTime() | prevVal.hasTime();
boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
long prev = prevVal.getUTCTimeInMillis();
long next = val.getUTCTimeInMillis();
long lin = Math.round((prev + next) / 2);
res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
} else {
DoubleValue val = (DoubleValue) cell;
double prev = ((DoubleValue) getPrevious()).getDoubleValue();
double next = val.getDoubleValue();
double lin = (prev + next) / 2;
if (getPrevious() instanceof IntValue) {
// get an int, create an int
res = new IntCell((int) Math.round(lin));
} else if (getPrevious() instanceof LongValue) {
// get an long, create an long
res = new LongCell(Math.round(lin));
} else {
res = new DoubleCell(lin);
}
}
}
addMapping(res);
}
resetMissing(cell);
}
}
use of org.knime.core.data.IntValue in project knime-core by knime.
the class LinearInterpolationStatisticMB method consumeRow.
/**
* {@inheritDoc}
*/
@Override
protected void consumeRow(final DataRow dataRow) {
DataCell cell = dataRow.getCell(m_colIdx);
if (cell.isMissing()) {
m_numMissing++;
} else {
for (int i = 0; i < m_numMissing; i++) {
DataCell res;
if (m_previous.isMissing()) {
res = cell;
} else {
if (m_isDateColumn) {
DateAndTimeValue val = (DateAndTimeValue) cell;
DateAndTimeValue prevVal = (DateAndTimeValue) m_previous;
boolean hasDate = val.hasDate() | prevVal.hasDate();
boolean hasTime = val.hasTime() | prevVal.hasTime();
boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
long prev = prevVal.getUTCTimeInMillis();
long next = val.getUTCTimeInMillis();
long lin = Math.round(prev + 1.0 * (i + 1) / (1.0 * (m_numMissing + 1)) * (next - prev));
res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
} else {
DoubleValue val = (DoubleValue) cell;
double prev = ((DoubleValue) m_previous).getDoubleValue();
double next = val.getDoubleValue();
double lin = prev + 1.0 * (i + 1) / (1.0 * (m_numMissing + 1)) * (next - prev);
if (m_previous instanceof IntValue) {
// get an int, create an int
res = new IntCell((int) Math.round(lin));
} else if (m_previous instanceof LongValue) {
// get an long, create an long
res = new LongCell(Math.round(lin));
} else {
res = new DoubleCell(lin);
}
}
}
m_values.add(res);
}
m_numMissing = 0;
m_previous = cell;
}
}
Aggregations