Java Code Examples for cern.colt.list.IntArrayList#add()

The following examples show how to use cern.colt.list.IntArrayList#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectMatrix2D.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
Fills the coordinates and values of cells having non-zero values into the specified lists.
Fills into the lists, starting at index 0.
After this call returns the specified lists all have a new size, the number of non-zero values.
<p>
In general, fill order is <i>unspecified</i>.
This implementation fills like <tt>for (row = 0..rows-1) for (column = 0..columns-1) do ... </tt>.
However, subclasses are free to us any other order, even an order that may change over time as cell values are changed.
(Of course, result lists indexes are guaranteed to correspond to the same cell).
<p>
<b>Example:</b>
<br>
<pre>
2 x 3 matrix:
0, 0, 8
0, 7, 0
-->
rowList    = (0,1)
columnList = (2,1)
valueList  = (8,7)
</pre>
In other words, <tt>get(0,2)==8, get(1,1)==7</tt>.

@param rowList the list to be filled with row indexes, can have any size.
@param columnList the list to be filled with column indexes, can have any size.
@param valueList the list to be filled with values, can have any size.
*/
public void getNonZeros(IntArrayList rowList, IntArrayList columnList, ObjectArrayList valueList) {
	rowList.clear(); 
	columnList.clear(); 
	valueList.clear();
	int r = rows;
	int c = columns;
	for (int row=0; row < r; row++) {
		for (int column=0; column < c; column++) {
			Object value = getQuick(row,column);
			if (value != null) {
				rowList.add(row);
				columnList.add(column);
				valueList.add(value);
			}
		}
	}
}
 
Example 2
Source File: DoubleMatrix2D.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
Fills the coordinates and values of cells having non-zero values into the specified lists.
Fills into the lists, starting at index 0.
After this call returns the specified lists all have a new size, the number of non-zero values.
<p>
In general, fill order is <i>unspecified</i>.
This implementation fills like <tt>for (row = 0..rows-1) for (column = 0..columns-1) do ... </tt>.
However, subclasses are free to us any other order, even an order that may change over time as cell values are changed.
(Of course, result lists indexes are guaranteed to correspond to the same cell).
<p>
<b>Example:</b>
<br>
<pre>
2 x 3 matrix:
0, 0, 8
0, 7, 0
-->
rowList    = (0,1)
columnList = (2,1)
valueList  = (8,7)
</pre>
In other words, <tt>get(0,2)==8, get(1,1)==7</tt>.

@param rowList the list to be filled with row indexes, can have any size.
@param columnList the list to be filled with column indexes, can have any size.
@param valueList the list to be filled with values, can have any size.
*/
public void getNonZeros(IntArrayList rowList, IntArrayList columnList, DoubleArrayList valueList) {
	rowList.clear(); 
	columnList.clear(); 
	valueList.clear();
	int r = rows;
	int c = columns;
	for (int row=0; row < r; row++) {
		for (int column=0; column < c; column++) {
			double value = getQuick(row,column);
			if (value != 0) {
				rowList.add(row);
				columnList.add(column);
				valueList.add(value);
			}
		}
	}
}
 
Example 3
Source File: DoubleMatrix1D.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
Fills the coordinates and values of cells having non-zero values into the specified lists.
Fills into the lists, starting at index 0.
After this call returns the specified lists all have a new size, the number of non-zero values.
<p>
In general, fill order is <i>unspecified</i>.
This implementation fills like: <tt>for (index = 0..size()-1)  do ... </tt>.
However, subclasses are free to us any other order, even an order that may change over time as cell values are changed.
(Of course, result lists indexes are guaranteed to correspond to the same cell).
<p>
<b>Example:</b>
<br>
<pre>
0, 0, 8, 0, 7
-->
indexList  = (2,4)
valueList  = (8,7)
</pre>
In other words, <tt>get(2)==8, get(4)==7</tt>.

@param indexList the list to be filled with indexes, can have any size.
@param valueList the list to be filled with values, can have any size.
*/
public void getNonZeros(IntArrayList indexList, DoubleArrayList valueList, int maxCardinality) {
	boolean fillIndexList = indexList != null;
	boolean fillValueList = valueList != null;
	int card = cardinality(maxCardinality);
	if (fillIndexList) indexList.setSize(card);
	if (fillValueList) valueList.setSize(card);
	if (!(card<maxCardinality)) return;

	if (fillIndexList) indexList.setSize(0);
	if (fillValueList) valueList.setSize(0);
	int s = size;
	for (int i=0; i < s; i++) {
		double value = getQuick(i);
		if (value != 0) {
			if (fillIndexList) indexList.add(i);
			if (fillValueList) valueList.add(value);
		}
	}
}
 
Example 4
Source File: DoubleMatrix3D.java    From jAudioGIT with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
Constructs and returns a new <i>selection view</i> that is a matrix holding all <b>slices</b> matching the given condition.
Applies the condition to each slice and takes only those where <tt>condition.apply(viewSlice(i))</tt> yields <tt>true</tt>.
To match rows or columns, use a dice view.
<p>
<b>Example:</b>
<br>
<pre>
// extract and view all slices which have an aggregate sum > 1000
matrix.viewSelection( 
&nbsp;&nbsp;&nbsp;new DoubleMatrix2DProcedure() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public final boolean apply(DoubleMatrix2D m) { return m.zSum > 1000; }
&nbsp;&nbsp;&nbsp;}
);
</pre>
For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>.
The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa. 

@param  condition The condition to be matched.
@return the new view.
*/
public DoubleMatrix3D viewSelection(DoubleMatrix2DProcedure condition) {
	IntArrayList matches = new IntArrayList();
	for (int i=0; i < slices; i++) {
		if (condition.apply(viewSlice(i))) matches.add(i);
	}
	
	matches.trimToSize();
	return viewSelection(matches.elements(), null, null); // take all rows and columns
}
 
Example 5
Source File: OpenDoubleIntHashMap.java    From jAudioGIT with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
Fills all pairs satisfying a given condition into the specified lists.
Fills into the lists, starting at index 0.
After this call returns the specified lists both have a new size, the number of pairs satisfying the condition.
Iteration order is guaranteed to be <i>identical</i> to the order used by method {@link #forEachKey(DoubleProcedure)}.
<p>
<b>Example:</b>
<br>
<pre>
DoubleIntProcedure condition = new DoubleIntProcedure() { // match even values only
	public boolean apply(double key, int value) { return value%2==0; }
}
keys = (8,7,6), values = (1,2,2) --> keyList = (6,8), valueList = (2,1)</tt>
</pre>

@param condition    the condition to be matched. Takes the current key as first and the current value as second argument.
@param keyList the list to be filled with keys, can have any size.
@param valueList the list to be filled with values, can have any size.
*/
public void pairsMatching(final DoubleIntProcedure condition, final DoubleArrayList keyList, final IntArrayList valueList) {
	keyList.clear();
	valueList.clear();
	
	for (int i = table.length ; i-- > 0 ;) {
		if (state[i]==FULL && condition.apply(table[i],values[i])) {
			keyList.add(table[i]);
			valueList.add(values[i]);
		}
	}
}
 
Example 6
Source File: OpenIntDoubleHashMap.java    From jAudioGIT with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
Fills all pairs satisfying a given condition into the specified lists.
Fills into the lists, starting at index 0.
After this call returns the specified lists both have a new size, the number of pairs satisfying the condition.
Iteration order is guaranteed to be <i>identical</i> to the order used by method {@link #forEachKey(IntProcedure)}.
<p>
<b>Example:</b>
<br>
<pre>
IntDoubleProcedure condition = new IntDoubleProcedure() { // match even keys only
	public boolean apply(int key, double value) { return key%2==0; }
}
keys = (8,7,6), values = (1,2,2) --> keyList = (6,8), valueList = (2,1)</tt>
</pre>

@param condition    the condition to be matched. Takes the current key as first and the current value as second argument.
@param keyList the list to be filled with keys, can have any size.
@param valueList the list to be filled with values, can have any size.
*/
public void pairsMatching(final IntDoubleProcedure condition, final IntArrayList keyList, final DoubleArrayList valueList) {
	keyList.clear();
	valueList.clear();
	
	for (int i = table.length ; i-- > 0 ;) {
		if (state[i]==FULL && condition.apply(table[i],values[i])) {
			keyList.add(table[i]);
			valueList.add(values[i]);
		}
	}
}
 
Example 7
Source File: ObjectMatrix1D.java    From jAudioGIT with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
Fills the coordinates and values of cells having non-zero values into the specified lists.
Fills into the lists, starting at index 0.
After this call returns the specified lists all have a new size, the number of non-zero values.
<p>
In general, fill order is <i>unspecified</i>.
This implementation fills like: <tt>for (index = 0..size()-1)  do ... </tt>.
However, subclasses are free to us any other order, even an order that may change over time as cell values are changed.
(Of course, result lists indexes are guaranteed to correspond to the same cell).
<p>
<b>Example:</b>
<br>
<pre>
0, 0, 8, 0, 7
-->
indexList  = (2,4)
valueList  = (8,7)
</pre>
In other words, <tt>get(2)==8, get(4)==7</tt>.

@param indexList the list to be filled with indexes, can have any size.
@param valueList the list to be filled with values, can have any size.
*/
public void getNonZeros(IntArrayList indexList, ObjectArrayList valueList) {
	boolean fillIndexList = indexList != null;
	boolean fillValueList = valueList != null;
	if (fillIndexList) indexList.clear(); 
	if (fillValueList) valueList.clear();
	int s = size;
	for (int i=0; i < s; i++) {
		Object value = getQuick(i);
		if (value != null) {
			if (fillIndexList) indexList.add(i);
			if (fillValueList) valueList.add(value);
		}
	}
}
 
Example 8
Source File: ObjectMatrix1D.java    From jAudioGIT with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
Constructs and returns a new <i>selection view</i> that is a matrix holding the cells matching the given condition.
Applies the condition to each cell and takes only those cells where <tt>condition.apply(get(i))</tt> yields <tt>true</tt>.
<p>
<b>Example:</b>
<br>
<pre>
// extract and view all cells with even value
matrix = 0 1 2 3 
matrix.viewSelection( 
&nbsp;&nbsp;&nbsp;new ObjectProcedure() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public final boolean apply(Object a) { return a % 2 == 0; }
&nbsp;&nbsp;&nbsp;}
);
-->
matrix ==  0 2
</pre>
For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>.
The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa. 

@param  condition The condition to be matched.
@return the new view.
*/
public ObjectMatrix1D viewSelection(cern.colt.function.ObjectProcedure condition) {
	IntArrayList matches = new IntArrayList();
	for (int i=0; i < size; i++) {
		if (condition.apply(getQuick(i))) matches.add(i);
	}
	matches.trimToSize();
	return viewSelection(matches.elements());
}
 
Example 9
Source File: OpenIntIntHashMap.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
Fills all pairs satisfying a given condition into the specified lists.
Fills into the lists, starting at index 0.
After this call returns the specified lists both have a new size, the number of pairs satisfying the condition.
Iteration order is guaranteed to be <i>identical</i> to the order used by method {@link #forEachKey(IntProcedure)}.
<p>
<b>Example:</b>
<br>
<pre>
IntIntProcedure condition = new IntIntProcedure() { // match even keys only
	public boolean apply(int key, int value) { return key%2==0; }
}
keys = (8,7,6), values = (1,2,2) --> keyList = (6,8), valueList = (2,1)</tt>
</pre>

@param condition    the condition to be matched. Takes the current key as first and the current value as second argument.
@param keyList the list to be filled with keys, can have any size.
@param valueList the list to be filled with values, can have any size.
*/
public void pairsMatching(final IntIntProcedure condition, final IntArrayList keyList, final IntArrayList valueList) {
	keyList.clear();
	valueList.clear();
	
	for (int i = table.length ; i-- > 0 ;) {
		if (state[i]==FULL && condition.apply(table[i],values[i])) {
			keyList.add(table[i]);
			valueList.add(values[i]);
		}
	}
}
 
Example 10
Source File: DoubleMatrix1D.java    From jAudioGIT with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
Constructs and returns a new <i>selection view</i> that is a matrix holding the cells matching the given condition.
Applies the condition to each cell and takes only those cells where <tt>condition.apply(get(i))</tt> yields <tt>true</tt>.
<p>
<b>Example:</b>
<br>
<pre>
// extract and view all cells with even value
matrix = 0 1 2 3 
matrix.viewSelection( 
&nbsp;&nbsp;&nbsp;new DoubleProcedure() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public final boolean apply(double a) { return a % 2 == 0; }
&nbsp;&nbsp;&nbsp;}
);
-->
matrix ==  0 2
</pre>
For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>.
The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa. 

@param  condition The condition to be matched.
@return the new view.
*/
public DoubleMatrix1D viewSelection(cern.colt.function.DoubleProcedure condition) {
	IntArrayList matches = new IntArrayList();
	for (int i=0; i < size; i++) {
		if (condition.apply(getQuick(i))) matches.add(i);
	}
	matches.trimToSize();
	return viewSelection(matches.elements());
}
 
Example 11
Source File: DoubleMatrix1D.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
Constructs and returns a new <i>selection view</i> that is a matrix holding the cells matching the given condition.
Applies the condition to each cell and takes only those cells where <tt>condition.apply(get(i))</tt> yields <tt>true</tt>.
<p>
<b>Example:</b>
<br>
<pre>
// extract and view all cells with even value
matrix = 0 1 2 3 
matrix.viewSelection( 
&nbsp;&nbsp;&nbsp;new DoubleProcedure() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public final boolean apply(double a) { return a % 2 == 0; }
&nbsp;&nbsp;&nbsp;}
);
-->
matrix ==  0 2
</pre>
For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>.
The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa. 

@param  condition The condition to be matched.
@return the new view.
*/
public DoubleMatrix1D viewSelection(cern.colt.function.DoubleProcedure condition) {
	IntArrayList matches = new IntArrayList();
	for (int i=0; i < size; i++) {
		if (condition.apply(getQuick(i))) matches.add(i);
	}
	matches.trimToSize();
	return viewSelection(matches.elements());
}
 
Example 12
Source File: DoubleMatrix1D.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
Fills the coordinates and values of cells having non-zero values into the specified lists.
Fills into the lists, starting at index 0.
After this call returns the specified lists all have a new size, the number of non-zero values.
<p>
In general, fill order is <i>unspecified</i>.
This implementation fills like: <tt>for (index = 0..size()-1)  do ... </tt>.
However, subclasses are free to us any other order, even an order that may change over time as cell values are changed.
(Of course, result lists indexes are guaranteed to correspond to the same cell).
<p>
<b>Example:</b>
<br>
<pre>
0, 0, 8, 0, 7
-->
indexList  = (2,4)
valueList  = (8,7)
</pre>
In other words, <tt>get(2)==8, get(4)==7</tt>.

@param indexList the list to be filled with indexes, can have any size.
@param valueList the list to be filled with values, can have any size.
*/
public void getNonZeros(IntArrayList indexList, DoubleArrayList valueList) {
	boolean fillIndexList = indexList != null;
	boolean fillValueList = valueList != null;
	if (fillIndexList) indexList.clear(); 
	if (fillValueList) valueList.clear();
	int s = size;
	for (int i=0; i < s; i++) {
		double value = getQuick(i);
		if (value != 0) {
			if (fillIndexList) indexList.add(i);
			if (fillValueList) valueList.add(value);
		}
	}
}
 
Example 13
Source File: ObjectMatrix1D.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
Constructs and returns a new <i>selection view</i> that is a matrix holding the cells matching the given condition.
Applies the condition to each cell and takes only those cells where <tt>condition.apply(get(i))</tt> yields <tt>true</tt>.
<p>
<b>Example:</b>
<br>
<pre>
// extract and view all cells with even value
matrix = 0 1 2 3 
matrix.viewSelection( 
&nbsp;&nbsp;&nbsp;new ObjectProcedure() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public final boolean apply(Object a) { return a % 2 == 0; }
&nbsp;&nbsp;&nbsp;}
);
-->
matrix ==  0 2
</pre>
For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>.
The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa. 

@param  condition The condition to be matched.
@return the new view.
*/
public ObjectMatrix1D viewSelection(cern.colt.function.ObjectProcedure condition) {
	IntArrayList matches = new IntArrayList();
	for (int i=0; i < size; i++) {
		if (condition.apply(getQuick(i))) matches.add(i);
	}
	matches.trimToSize();
	return viewSelection(matches.elements());
}
 
Example 14
Source File: ObjectMatrix3D.java    From jAudioGIT with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
Constructs and returns a new <i>selection view</i> that is a matrix holding all <b>slices</b> matching the given condition.
Applies the condition to each slice and takes only those where <tt>condition.apply(viewSlice(i))</tt> yields <tt>true</tt>.
To match rows or columns, use a dice view.
<p>
<b>Example:</b>
<br>
<pre>
// extract and view all slices which have an aggregate sum > 1000
matrix.viewSelection( 
&nbsp;&nbsp;&nbsp;new ObjectMatrix2DProcedure() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public final boolean apply(ObjectMatrix2D m) { return m.zSum > 1000; }
&nbsp;&nbsp;&nbsp;}
);
</pre>
For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>.
The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa. 

@param  condition The condition to be matched.
@return the new view.
*/
public ObjectMatrix3D viewSelection(ObjectMatrix2DProcedure condition) {
	IntArrayList matches = new IntArrayList();
	for (int i=0; i < slices; i++) {
		if (condition.apply(viewSlice(i))) matches.add(i);
	}
	
	matches.trimToSize();
	return viewSelection(matches.elements(), null, null); // take all rows and columns
}
 
Example 15
Source File: OpenIntObjectHashMap.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
Fills all pairs satisfying a given condition into the specified lists.
Fills into the lists, starting at index 0.
After this call returns the specified lists both have a new size, the number of pairs satisfying the condition.
Iteration order is guaranteed to be <i>identical</i> to the order used by method {@link #forEachKey(IntProcedure)}.
<p>
<b>Example:</b>
<br>
<pre>
IntObjectProcedure condition = new IntObjectProcedure() { // match even keys only
	public boolean apply(int key, Object value) { return key%2==0; }
}
keys = (8,7,6), values = (1,2,2) --> keyList = (6,8), valueList = (2,1)</tt>
</pre>

@param condition    the condition to be matched. Takes the current key as first and the current value as second argument.
@param keyList the list to be filled with keys, can have any size.
@param valueList the list to be filled with values, can have any size.
*/
public void pairsMatching(final IntObjectProcedure condition, final IntArrayList keyList, final ObjectArrayList valueList) {
	keyList.clear();
	valueList.clear();
	
	for (int i = table.length ; i-- > 0 ;) {
		if (state[i]==FULL && condition.apply(table[i],values[i])) {
			keyList.add(table[i]);
			valueList.add(values[i]);
		}
	}
}
 
Example 16
Source File: OpenDoubleIntHashMap.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
Fills all pairs satisfying a given condition into the specified lists.
Fills into the lists, starting at index 0.
After this call returns the specified lists both have a new size, the number of pairs satisfying the condition.
Iteration order is guaranteed to be <i>identical</i> to the order used by method {@link #forEachKey(DoubleProcedure)}.
<p>
<b>Example:</b>
<br>
<pre>
DoubleIntProcedure condition = new DoubleIntProcedure() { // match even values only
	public boolean apply(double key, int value) { return value%2==0; }
}
keys = (8,7,6), values = (1,2,2) --> keyList = (6,8), valueList = (2,1)</tt>
</pre>

@param condition    the condition to be matched. Takes the current key as first and the current value as second argument.
@param keyList the list to be filled with keys, can have any size.
@param valueList the list to be filled with values, can have any size.
*/
public void pairsMatching(final DoubleIntProcedure condition, final DoubleArrayList keyList, final IntArrayList valueList) {
	keyList.clear();
	valueList.clear();
	
	for (int i = table.length ; i-- > 0 ;) {
		if (state[i]==FULL && condition.apply(table[i],values[i])) {
			keyList.add(table[i]);
			valueList.add(values[i]);
		}
	}
}
 
Example 17
Source File: OpenIntDoubleHashMap.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
Fills all pairs satisfying a given condition into the specified lists.
Fills into the lists, starting at index 0.
After this call returns the specified lists both have a new size, the number of pairs satisfying the condition.
Iteration order is guaranteed to be <i>identical</i> to the order used by method {@link #forEachKey(IntProcedure)}.
<p>
<b>Example:</b>
<br>
<pre>
IntDoubleProcedure condition = new IntDoubleProcedure() { // match even keys only
	public boolean apply(int key, double value) { return key%2==0; }
}
keys = (8,7,6), values = (1,2,2) --> keyList = (6,8), valueList = (2,1)</tt>
</pre>

@param condition    the condition to be matched. Takes the current key as first and the current value as second argument.
@param keyList the list to be filled with keys, can have any size.
@param valueList the list to be filled with values, can have any size.
*/
public void pairsMatching(final IntDoubleProcedure condition, final IntArrayList keyList, final DoubleArrayList valueList) {
	keyList.clear();
	valueList.clear();
	
	for (int i = table.length ; i-- > 0 ;) {
		if (state[i]==FULL && condition.apply(table[i],values[i])) {
			keyList.add(table[i]);
			valueList.add(values[i]);
		}
	}
}
 
Example 18
Source File: DoubleMatrix2D.java    From database with GNU General Public License v2.0 1 votes vote down vote up
/**
Constructs and returns a new <i>selection view</i> that is a matrix holding all <b>rows</b> matching the given condition.
Applies the condition to each row and takes only those row where <tt>condition.apply(viewRow(i))</tt> yields <tt>true</tt>.
To match columns, use a dice view.
<p>
<b>Example:</b>
<br>
<pre>
// extract and view all rows which have a value < threshold in the first column (representing "age")
final double threshold = 16;
matrix.viewSelection( 
&nbsp;&nbsp;&nbsp;new DoubleMatrix1DProcedure() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public final boolean apply(DoubleMatrix1D m) { return m.get(0) < threshold; }
&nbsp;&nbsp;&nbsp;}
);

// extract and view all rows with RMS < threshold
// The RMS (Root-Mean-Square) is a measure of the average "size" of the elements of a data sequence.
matrix = 0 1 2 3
final double threshold = 0.5;
matrix.viewSelection( 
&nbsp;&nbsp;&nbsp;new DoubleMatrix1DProcedure() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public final boolean apply(DoubleMatrix1D m) { return Math.sqrt(m.aggregate(F.plus,F.square) / m.size()) < threshold; }
&nbsp;&nbsp;&nbsp;}
);
</pre>
For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>.
The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa. 

@param  condition The condition to be matched.
@return the new view.
*/
public DoubleMatrix2D viewSelection(DoubleMatrix1DProcedure condition) {
	IntArrayList matches = new IntArrayList();
	for (int i=0; i < rows; i++) {
		if (condition.apply(viewRow(i))) matches.add(i);
	}
	
	matches.trimToSize();
	return viewSelection(matches.elements(), null); // take all columns
}
 
Example 19
Source File: ObjectMatrix2D.java    From database with GNU General Public License v2.0 1 votes vote down vote up
/**
Constructs and returns a new <i>selection view</i> that is a matrix holding all <b>rows</b> matching the given condition.
Applies the condition to each row and takes only those row where <tt>condition.apply(viewRow(i))</tt> yields <tt>true</tt>.
To match columns, use a dice view.
<p>
<b>Example:</b>
<br>
<pre>
// extract and view all rows which have a value < threshold in the first column (representing "age")
final Object threshold = 16;
matrix.viewSelection( 
&nbsp;&nbsp;&nbsp;new ObjectMatrix1DProcedure() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public final boolean apply(ObjectMatrix1D m) { return m.get(0) < threshold; }
&nbsp;&nbsp;&nbsp;}
);

// extract and view all rows with RMS < threshold
// The RMS (Root-Mean-Square) is a measure of the average "size" of the elements of a data sequence.
matrix = 0 1 2 3
final Object threshold = 0.5;
matrix.viewSelection( 
&nbsp;&nbsp;&nbsp;new ObjectMatrix1DProcedure() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public final boolean apply(ObjectMatrix1D m) { return Math.sqrt(m.aggregate(F.plus,F.square) / m.size()) < threshold; }
&nbsp;&nbsp;&nbsp;}
);
</pre>
For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>.
The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa. 

@param  condition The condition to be matched.
@return the new view.
*/
public ObjectMatrix2D viewSelection(ObjectMatrix1DProcedure condition) {
	IntArrayList matches = new IntArrayList();
	for (int i=0; i < rows; i++) {
		if (condition.apply(viewRow(i))) matches.add(i);
	}
	
	matches.trimToSize();
	return viewSelection(matches.elements(), null); // take all columns
}
 
Example 20
Source File: DoubleMatrix2D.java    From jAudioGIT with GNU Lesser General Public License v2.1 1 votes vote down vote up
/**
Constructs and returns a new <i>selection view</i> that is a matrix holding all <b>rows</b> matching the given condition.
Applies the condition to each row and takes only those row where <tt>condition.apply(viewRow(i))</tt> yields <tt>true</tt>.
To match columns, use a dice view.
<p>
<b>Example:</b>
<br>
<pre>
// extract and view all rows which have a value < threshold in the first column (representing "age")
final double threshold = 16;
matrix.viewSelection( 
&nbsp;&nbsp;&nbsp;new DoubleMatrix1DProcedure() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public final boolean apply(DoubleMatrix1D m) { return m.get(0) < threshold; }
&nbsp;&nbsp;&nbsp;}
);

// extract and view all rows with RMS < threshold
// The RMS (Root-Mean-Square) is a measure of the average "size" of the elements of a data sequence.
matrix = 0 1 2 3
final double threshold = 0.5;
matrix.viewSelection( 
&nbsp;&nbsp;&nbsp;new DoubleMatrix1DProcedure() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public final boolean apply(DoubleMatrix1D m) { return Math.sqrt(m.aggregate(F.plus,F.square) / m.size()) < threshold; }
&nbsp;&nbsp;&nbsp;}
);
</pre>
For further examples, see the <a href="package-summary.html#FunctionObjects">package doc</a>.
The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa. 

@param  condition The condition to be matched.
@return the new view.
*/
public DoubleMatrix2D viewSelection(DoubleMatrix1DProcedure condition) {
	IntArrayList matches = new IntArrayList();
	for (int i=0; i < rows; i++) {
		if (condition.apply(viewRow(i))) matches.add(i);
	}
	
	matches.trimToSize();
	return viewSelection(matches.elements(), null); // take all columns
}