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

The following examples show how to use cern.colt.list.IntArrayList#trimToSize() . 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: RCMDoubleMatrix2D.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sets the matrix cell at coordinate <tt>[row,column]</tt> to the specified value.
 *
 * <p>Provided with invalid parameters this method may access illegal indexes without throwing any exception.
 * <b>You should only use this method when you are absolutely sure that the coordinate is within bounds.</b>
 * Precondition (unchecked): <tt>0 &lt;= column &lt; columns() && 0 &lt;= row &lt; rows()</tt>.
 *
 * @param     row   the index of the row-coordinate.
 * @param     column   the index of the column-coordinate.
 * @param    value the value to be filled into the specified cell.
 */
public void setQuick(int row, int column, double value) {
	int i=row;
	int j=column;
	
	int k=-1;
	IntArrayList indexList = indexes[i];
	if (indexList != null) k = indexList.binarySearch(j);
	
	if (k>=0) { // found
		if (value==0) {
			DoubleArrayList valueList = values[i];
			indexList.remove(k);
			valueList.remove(k);
			int s = indexList.size();
			if (s>2 && s*3 < indexList.elements().length) {
				indexList.setSize(s*3/2);
				indexList.trimToSize();
				indexList.setSize(s);
				
				valueList.setSize(s*3/2);
				valueList.trimToSize();
				valueList.setSize(s);		
			}
		}
		else {
			values[i].setQuick(k,value);
		}
	}
	else { // not found
		if (value==0) return;

		k = -k-1;

		if (indexList == null) {
			indexes[i] = new IntArrayList(3);
			values[i]  = new DoubleArrayList(3);
		}
		indexes[i].beforeInsert(k,j);
		values[i].beforeInsert(k,value);
	}
}
 
Example 2
Source File: RCMDoubleMatrix2D.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Sets the matrix cell at coordinate <tt>[row,column]</tt> to the specified value.
 *
 * <p>Provided with invalid parameters this method may access illegal indexes without throwing any exception.
 * <b>You should only use this method when you are absolutely sure that the coordinate is within bounds.</b>
 * Precondition (unchecked): <tt>0 &lt;= column &lt; columns() && 0 &lt;= row &lt; rows()</tt>.
 *
 * @param     row   the index of the row-coordinate.
 * @param     column   the index of the column-coordinate.
 * @param    value the value to be filled into the specified cell.
 */
public void setQuick(int row, int column, double value) {
	int i=row;
	int j=column;
	
	int k=-1;
	IntArrayList indexList = indexes[i];
	if (indexList != null) k = indexList.binarySearch(j);
	
	if (k>=0) { // found
		if (value==0) {
			DoubleArrayList valueList = values[i];
			indexList.remove(k);
			valueList.remove(k);
			int s = indexList.size();
			if (s>2 && s*3 < indexList.elements().length) {
				indexList.setSize(s*3/2);
				indexList.trimToSize();
				indexList.setSize(s);
				
				valueList.setSize(s*3/2);
				valueList.trimToSize();
				valueList.setSize(s);		
			}
		}
		else {
			values[i].setQuick(k,value);
		}
	}
	else { // not found
		if (value==0) return;

		k = -k-1;

		if (indexList == null) {
			indexes[i] = new IntArrayList(3);
			values[i]  = new DoubleArrayList(3);
		}
		indexes[i].beforeInsert(k,j);
		values[i].beforeInsert(k,value);
	}
}
 
Example 3
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 4
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 5
Source File: DoubleMatrix3D.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 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 6
Source File: ObjectMatrix3D.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 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 7
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 8
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 9
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 10
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 11
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 12
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 13
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
}
 
Example 14
Source File: ObjectMatrix2D.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 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
}