Java Code Examples for gnu.trove.list.array.TIntArrayList#toArray()

The following examples show how to use gnu.trove.list.array.TIntArrayList#toArray() . 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: UndirectedGraphImpl.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public int[] getEdges() {
    TIntArrayList t = new TIntArrayList(getEdgeCount());
    for (int e = 0; e < edges.size(); e++) {
        if (edges.get(e) != null) {
            t.add(e);
        }
    }
    return t.toArray();
}
 
Example 2
Source File: UncompressedStringDataChunk.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public StringDataChunk tryToCompress() {
    List<String> stepValues = new ArrayList<>();
    TIntArrayList stepLengths = new TIntArrayList();
    int compressedEstimatedSize = 0;
    for (String value : values) {
        if (stepValues.isEmpty()) {
            // create first step
            stepValues.add(value);
            stepLengths.add(1);
            compressedEstimatedSize += CompressedStringDataChunk.getStepEstimatedSize(value);
        } else {
            int previousIndex = stepValues.size() - 1;
            String previousValue = stepValues.get(previousIndex);
            if (Objects.equals(previousValue, value)) {
                stepLengths.set(previousIndex, stepLengths.getQuick(previousIndex) + 1);
            } else {
                // create a new step
                stepValues.add(value);
                stepLengths.add(1);
                compressedEstimatedSize += CompressedStringDataChunk.getStepEstimatedSize(value);
            }
        }
        if (compressedEstimatedSize > estimatedSize) {
            // compression is inefficient
            return this;
        }
    }
    return new CompressedStringDataChunk(offset, values.length, stepValues.toArray(new String[stepValues.size()]),
                                          stepLengths.toArray());
}
 
Example 3
Source File: ModularSequence.java    From clearvolume with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static int computeGapScore(int n, int k, int m)
{
	final TIntArrayList lGapList = computeGapList(n, k, m);
	final int[] lArray = lGapList.toArray();

	int lScore = 1;
	for (final int gaplength : lArray)
		lScore *= gaplength;

	return lScore;
}
 
Example 4
Source File: FoxEatsDemo.java    From htm.java-examples with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns a random, sorted, and  unique array of the specified sample size of
 * selections from the specified list of choices.
 *
 * @param sampleSize the number of selections in the returned sample
 * @param choices    the list of choices to select from
 * @param random     a random number generator
 * @return a sample of numbers of the specified size
 */
int[] sample(int sampleSize, TIntArrayList choices, Random random) {
    TIntHashSet temp = new TIntHashSet();
    int upperBound = choices.size();
    for (int i = 0; i < sampleSize; i++) {
        int randomIdx = random.nextInt(upperBound);
        while (temp.contains(choices.get(randomIdx))) {
            randomIdx = random.nextInt(upperBound);
        }
        temp.add(choices.get(randomIdx));
    }
    TIntArrayList al = new TIntArrayList(temp);
    al.sort();
    return al.toArray();
}
 
Example 5
Source File: StrictHackathonAlgorithm.java    From htm.java-examples with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns a random, sorted, and  unique array of the specified sample size of
 * selections from the specified list of choices.
 *
 * @param sampleSize the number of selections in the returned sample
 * @param choices    the list of choices to select from
 * @param random     a random number generator
 * @return a sample of numbers of the specified size
 */
int[] sample(int sampleSize, TIntArrayList choices, Random random) {
    TIntHashSet temp = new TIntHashSet();
    int upperBound = choices.size();
    for (int i = 0; i < sampleSize; i++) {
        int randomIdx = random.nextInt(upperBound);
        while (temp.contains(choices.get(randomIdx))) {
            randomIdx = random.nextInt(upperBound);
        }
        temp.add(choices.get(randomIdx));
    }
    TIntArrayList al = new TIntArrayList(temp);
    al.sort();
    return al.toArray();
}
 
Example 6
Source File: UndirectedGraphImpl.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public int[] getVertices() {
    TIntArrayList t = new TIntArrayList(vertices.size());
    for (int i = 0; i < vertices.size(); i++) {
        if (vertices.get(i) != null) {
            t.add(i);
        }
    }
    return t.toArray();
}
 
Example 7
Source File: MyArraysTest.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testentropy() {
	int[] w;
	float[] ww;
	float e;
	w= new int[]{ 1, 2, 3, 4, 0, 0, 0 };		
	e = MyArrays.entropy(w);		
	System.out.print(e + " ");
	
	ww= new float[]{ 1, 0, 0, 0, 0, 0, 0 };		
	e = MyArrays.entropy(ww);		
	System.out.print(e + " ");
	
	System.out.println();
	TIntArrayList www = new TIntArrayList();
	for(int i=0;i<100;i++){
	www.add(1);
	w = www.toArray();
	e = MyArrays.entropy(w);		
	System.out.print(e + " ");
	System.out.println(e/w.length);
	}
	System.out.println();
	
	ww= new float[]{ 0.5f, 0.5f };		
	e = MyArrays.entropy(ww);		
	System.out.print(e + " ");
}
 
Example 8
Source File: JointParser.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static int[] addFeature(IFeatureAlphabet fa, ArrayList<String> str,  int ysize) {
	TIntArrayList indices = new TIntArrayList();
	String constant = "////";
	str.add(constant);
	for(String s: str){
		int i = fa.lookupIndex(s,ysize);
		if(i!=-1)
			indices.add(i);
	}
	return indices.toArray();
}
 
Example 9
Source File: ArrayUtils.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Scans the specified values and applies the {@link Condition} to each
 * value, returning the indexes of the values where the condition evaluates
 * to true.
 *
 * @param values the values to test
 * @param c      the condition used to test each value
 * @return
 */
public static <T> int[] where(T[] values, Condition<T> c) {
    TIntArrayList retVal = new TIntArrayList();
    for (int i = 0; i < values.length; i++) {
        if (c.eval(values[i])) {
            retVal.add(i);
        }
    }
    return retVal.toArray();
}
 
Example 10
Source File: ArrayUtils.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Scans the specified values and applies the {@link Condition} to each
 * value, returning the indexes of the values where the condition evaluates
 * to true.
 *
 * @param values the values to test
 * @param c      the condition used to test each value
 * @return
 */
public static <T> int[] where(List<T> values, Condition<T> c) {
    TIntArrayList retVal = new TIntArrayList();
    int len = values.size();
    for (int i = 0; i < len; i++) {
        if (c.eval(values.get(i))) {
            retVal.add(i);
        }
    }
    return retVal.toArray();
}
 
Example 11
Source File: ArrayUtils.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Scans the specified values and applies the {@link Condition} to each
 * value, returning the indexes of the values where the condition evaluates
 * to true.
 *
 * @param values the values to test
 * @param c      the condition used to test each value
 * @return
 */
public static <T> int[] where(int[] values, Condition<T> c) {
    TIntArrayList retVal = new TIntArrayList();
    int len = values.length;
    for (int i = 0; i < len; i++) {
        if (c.eval(values[i])) {
            retVal.add(i);
        }
    }
    return retVal.toArray();
}
 
Example 12
Source File: ArrayUtils.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns an array of values that test true for all of the
 * specified {@link Condition}s.
 *
 * @param values
 * @param conditions
 * @return
 */
public static int[] retainLogicalAnd(int[] values, Condition<?>[] conditions) {
    TIntArrayList l = new TIntArrayList();
    for (int i = 0; i < values.length; i++) {
        boolean result = true;
        for (int j = 0; j < conditions.length && result; j++) {
            result &= conditions[j].eval(values[i]);
        }
        if (result) l.add(values[i]);
    }
    return l.toArray();
}
 
Example 13
Source File: ArrayUtils.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Scans the specified values and applies the {@link Condition} to each
 * value, returning the indexes of the values where the condition evaluates
 * to true.
 *
 * @param values the values to test
 * @param c      the condition used to test each value
 * @return
 */
public static <T> int[] where(double[] values, Condition<T> c) {
    TIntArrayList retVal = new TIntArrayList();
    int len = values.length;
    for (int i = 0; i < len; i++) {
        if (c.eval(values[i])) {
            retVal.add(i);
        }
    }
    return retVal.toArray();
}
 
Example 14
Source File: Document.java    From JGibbLabeledLDA with GNU General Public License v2.0 4 votes vote down vote up
public Document(TIntArrayList doc, String rawStr, TIntArrayList tlabels)
{
    this(doc, rawStr);
    this.labels = tlabels != null ? tlabels.toArray() : null;
}
 
Example 15
Source File: Position.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Position(Portfolio portfolio, String assetName, TFloatArrayList price, TLongArrayList priceTimeMillSec, TIntArrayList quantity, TLongArrayList quantityTimeMillSec) {
	this( portfolio,  assetName,  price.toArray(),  priceTimeMillSec.toArray(),  quantity.toArray(),  quantityTimeMillSec.toArray());
}
 
Example 16
Source File: Position.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Position(Portfolio portfolio, String assetName, TDoubleArrayList price, TLongArrayList priceTimeMillSec, TIntArrayList quantity, TLongArrayList quantityTimeMillSec) {
	this(portfolio, assetName, price.toArray(),  priceTimeMillSec.toArray(),  quantity.toArray(),  quantityTimeMillSec.toArray());
}
 
Example 17
Source File: Position.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Position(Portfolio portfolio, String assetName, TDoubleArrayList price, TIntArrayList quantity, long timeStepMilliSec) {
	this( portfolio,  assetName,  price.toArray(),  quantity.toArray(),  timeStepMilliSec);
}
 
Example 18
Source File: Position.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Position(Portfolio portfolio, String assetName, TDoubleArrayList price, TIntArrayList quantity, TLongArrayList timeMillSec) {
	this( portfolio,  assetName,  price.toArray(),  quantity.toArray(),  timeMillSec.toArray());
}
 
Example 19
Source File: Position.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Position(Portfolio portfolio, String assetName, TIntArrayList quantity, String[] timeMillSec) {
	this(portfolio,  assetName,  quantity.toArray(),  timeMillSec);
}
 
Example 20
Source File: Position.java    From PE-HFT-Java with GNU General Public License v3.0 4 votes vote down vote up
public Position(Portfolio portfolio, String assetName, TIntArrayList quantity, TLongArrayList timeMillSec) {
	 this( portfolio,  assetName, quantity.toArray(),  timeMillSec.toArray());
}