Search in sources :

Example 6 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project Osmand by osmandapp.

the class BinaryMapIndexReader method getTransportRoutes.

/**
 * Transport public methods
 */
public TIntObjectHashMap<TransportRoute> getTransportRoutes(int[] filePointers) throws IOException {
    TIntObjectHashMap<TransportRoute> result = new TIntObjectHashMap<TransportRoute>();
    Map<TransportIndex, TIntArrayList> groupPoints = new HashMap<TransportIndex, TIntArrayList>();
    for (int filePointer : filePointers) {
        TransportIndex ind = getTransportIndex(filePointer);
        if (ind != null) {
            if (!groupPoints.containsKey(ind)) {
                groupPoints.put(ind, new TIntArrayList());
            }
            groupPoints.get(ind).add(filePointer);
        }
    }
    Iterator<Entry<TransportIndex, TIntArrayList>> it = groupPoints.entrySet().iterator();
    if (it.hasNext()) {
        Entry<TransportIndex, TIntArrayList> e = it.next();
        TransportIndex ind = e.getKey();
        TIntArrayList pointers = e.getValue();
        pointers.sort();
        TIntObjectHashMap<String> stringTable = new TIntObjectHashMap<String>();
        for (int i = 0; i < pointers.size(); i++) {
            int filePointer = pointers.get(i);
            TransportRoute transportRoute = transportAdapter.getTransportRoute(filePointer, stringTable, false);
            result.put(filePointer, transportRoute);
        }
        transportAdapter.initializeStringTable(ind, stringTable);
        for (TransportRoute r : result.values(new TransportRoute[result.size()])) {
            transportAdapter.initializeNames(false, r, stringTable);
        }
    }
    return result;
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) HashMap(java.util.HashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) TIntArrayList(gnu.trove.list.array.TIntArrayList) Entry(java.util.Map.Entry) TransportRoute(net.osmand.data.TransportRoute) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) TransportIndex(net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex)

Example 7 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project BuildCraft by BuildCraft.

the class IItemBuildCraft method registerVariants.

@SideOnly(Side.CLIENT)
default void registerVariants() {
    Item thisItem = (Item) this;
    TIntObjectHashMap<ModelResourceLocation> variants = new TIntObjectHashMap<>();
    addModelVariants(variants);
    for (int key : variants.keys()) {
        ModelResourceLocation variant = variants.get(key);
        if (RegistryConfig.DEBUG) {
            BCLog.logger.info("[lib.registry][" + thisItem.getRegistryName() + "] Registering a variant " + variant + " for damage " + key);
        }
        ModelLoader.setCustomModelResourceLocation(thisItem, key, variant);
    }
}
Also used : Item(net.minecraft.item.Item) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 8 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project cogcomp-nlp by CogComp.

the class TextAnnotation method getSpansMatching.

public List<IntPair> getSpansMatching(String text) {
    if (allSpans == null) {
        synchronized (this) {
            if (allSpans == null) {
                this.allSpans = TCollections.synchronizedMap(new TIntObjectHashMap<ArrayList<IntPair>>());
                /**
                 * creates a hash for each contiguous substring, and creates an entry for it in
                 * allSpans NOTE: spans previously used "at-the-end" indexing but then the
                 * offsets won't agree with actual constituents, so CHANGED IT 2016/05/11. MS
                 */
                for (int start = 0; start < this.size() - 1; start++) {
                    StringBuilder sb = new StringBuilder();
                    for (int end = start; end < this.size(); end++) {
                        String token = tokens[end];
                        token = token.replaceAll("``", "\"").replaceAll("''", "\"");
                        token = SentenceUtils.convertFromPTBBrackets(token);
                        sb.append(token).append(" ");
                        int hash = sb.toString().trim().hashCode();
                        if (!allSpans.containsKey(hash))
                            allSpans.put(hash, new ArrayList<IntPair>());
                        List<IntPair> list = allSpans.get(hash);
                        list.add(new IntPair(start, end + 1));
                    }
                }
            }
        }
    }
    int hashCode = text.trim().hashCode();
    int length = text.split("\\s+").length;
    List<IntPair> list = allSpans.get(hashCode);
    if (list == null)
        list = new ArrayList<>();
    return list;
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) IntPair(edu.illinois.cs.cogcomp.core.datastructures.IntPair)

Example 9 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project GDSC-SMLM by aherbert.

the class BenchmarkSpotFilter method getSimulationCoordinates.

/**
 * Gets the coordinates for the current simulation. This extract all the results in memory into a
 * list per frame and is cached for the simulation Id.
 *
 * @return the coordinates
 */
private TIntObjectHashMap<PsfSpot[]> getSimulationCoordinates() {
    Pair<Integer, TIntObjectHashMap<PsfSpot[]>> coords = coordinateCache.get();
    if (coords.getKey() != simulationParameters.id) {
        // Always use float coordinates.
        // The Worker adds a pixel offset for the spot coordinates.
        final TIntObjectHashMap<List<Coordinate>> coordinates = ResultsMatchCalculator.getCoordinates(results, false);
        // Spot PSFs may overlap so we must determine the amount of signal overlap and amplitude
        // effect for each spot...
        final int nThreads = Prefs.getThreads();
        final BlockingQueue<Integer> jobs = new ArrayBlockingQueue<>(nThreads * 2);
        final List<OverlapWorker> workers = new LinkedList<>();
        final List<Thread> threads = new LinkedList<>();
        final Ticker overlapTicker = ImageJUtils.createTicker(coordinates.size(), nThreads, "Computing PSF overlap ...");
        for (int i = 0; i < nThreads; i++) {
            final OverlapWorker worker = new OverlapWorker(jobs, coordinates, overlapTicker);
            final Thread t = new Thread(worker);
            workers.add(worker);
            threads.add(t);
            t.start();
        }
        // Process the frames
        coordinates.forEachKey(value -> {
            put(jobs, value);
            return true;
        });
        // Finish all the worker threads by passing in a null job
        for (int i = 0; i < threads.size(); i++) {
            put(jobs, -1);
        }
        // Wait for all to finish
        final TIntObjectHashMap<PsfSpot[]> actualCoordinates = new TIntObjectHashMap<>();
        for (int i = 0; i < threads.size(); i++) {
            try {
                threads.get(i).join();
            } catch (final InterruptedException ex) {
                Thread.currentThread().interrupt();
                throw new ConcurrentRuntimeException("Unexpected interrupt", ex);
            }
            actualCoordinates.putAll(workers.get(i).coordinates);
        }
        threads.clear();
        // For testing
        final SimpleRegression regression = new SimpleRegression(false);
        for (final PsfSpot[] spots : actualCoordinates.valueCollection()) {
            for (final PsfSpot spot : spots) {
                regression.addData(spot.getAmplitude(), calculator.getAmplitude(spot.getPeakResult().getParameters()));
            }
        }
        ImageJUtils.log("PixelAmplitude vs Amplitude = %f, slope=%f, n=%d", regression.getR(), regression.getSlope(), regression.getN());
        ImageJUtils.finished();
        coords = Pair.of(simulationParameters.id, actualCoordinates);
        coordinateCache.set(coords);
    }
    return coords.getRight();
}
Also used : Ticker(uk.ac.sussex.gdsc.core.logging.Ticker) PeakResultPoint(uk.ac.sussex.gdsc.smlm.results.PeakResultPoint) BasePoint(uk.ac.sussex.gdsc.core.match.BasePoint) LinkedList(java.util.LinkedList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PsfSpot(uk.ac.sussex.gdsc.smlm.ij.plugins.PsfSpot) ConcurrentRuntimeException(org.apache.commons.lang3.concurrent.ConcurrentRuntimeException) SimpleRegression(org.apache.commons.math3.stat.regression.SimpleRegression) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) SettingsList(uk.ac.sussex.gdsc.core.utils.SettingsList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList)

Example 10 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project GDSC-SMLM by aherbert.

the class BenchmarkFilterAnalysis method getCoordinates.

private static TIntObjectHashMap<UniqueIdPeakResult[]> getCoordinates(MemoryPeakResults results) {
    final TIntObjectHashMap<UniqueIdPeakResult[]> coords = new TIntObjectHashMap<>();
    if (results.size() > 0) {
        // Do not use HashMap directly to build the coords object since there
        // will be many calls to getEntry(). Instead sort the results and use
        // a new list for each time point
        results.sort();
        final Counter uniqueId = new Counter();
        final FrameCounter counter = new FrameCounter();
        final LocalList<PeakResult> tmp = new LocalList<>();
        // Add the results to the lists
        results.forEach((PeakResultProcedure) result -> {
            if (counter.advanceAndReset(result.getFrame()) && !tmp.isEmpty()) {
                coords.put(counter.previousFrame(), tmp.toArray(new UniqueIdPeakResult[0]));
                tmp.clear();
            }
            tmp.add(new UniqueIdPeakResult(tmp.size(), uniqueId.getAndIncrement(), result));
        });
        if (!tmp.isEmpty()) {
            coords.put(counter.currentFrame(), tmp.toArray(new UniqueIdPeakResult[0]));
        }
    }
    return coords;
}
Also used : Color(java.awt.Color) Arrays(java.util.Arrays) CoordinateStoreFactory(uk.ac.sussex.gdsc.smlm.results.filter.CoordinateStoreFactory) Macro(ij.Macro) ConvergenceChecker(uk.ac.sussex.gdsc.smlm.search.ConvergenceChecker) BasePreprocessedPeakResult(uk.ac.sussex.gdsc.smlm.results.filter.BasePreprocessedPeakResult) MultiPathFitResults(uk.ac.sussex.gdsc.smlm.results.filter.MultiPathFitResults) Filter(uk.ac.sussex.gdsc.smlm.results.filter.Filter) SearchResult(uk.ac.sussex.gdsc.smlm.search.SearchResult) HelpUrls(uk.ac.sussex.gdsc.smlm.ij.plugins.HelpUrls) Vector(java.util.Vector) SearchSpace(uk.ac.sussex.gdsc.smlm.search.SearchSpace) Pair(org.apache.commons.lang3.tuple.Pair) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) Map(java.util.Map) IDirectFilter(uk.ac.sussex.gdsc.smlm.results.filter.IDirectFilter) UnicodeReader(uk.ac.sussex.gdsc.core.utils.UnicodeReader) Triple(org.apache.commons.lang3.tuple.Triple) Chromosome(uk.ac.sussex.gdsc.smlm.ga.Chromosome) FilterScore(uk.ac.sussex.gdsc.smlm.results.filter.FilterScore) LinearInterpolator(org.apache.commons.math3.analysis.interpolation.LinearInterpolator) LoessInterpolator(org.apache.commons.math3.analysis.interpolation.LoessInterpolator) BlockingQueue(java.util.concurrent.BlockingQueue) StopWatch(org.apache.commons.lang3.time.StopWatch) ConcurrencyUtils(uk.ac.sussex.gdsc.core.utils.concurrent.ConcurrencyUtils) MultiPathFitResult(uk.ac.sussex.gdsc.smlm.results.filter.MultiPathFitResult) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) Gaussian2DFunction(uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction) Plot(ij.gui.Plot) PeakFit(uk.ac.sussex.gdsc.smlm.ij.plugins.PeakFit) TIntHashSet(gnu.trove.set.hash.TIntHashSet) ImagePlus(ij.ImagePlus) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) TextArea(java.awt.TextArea) PeakFractionalAssignment(uk.ac.sussex.gdsc.smlm.results.filter.PeakFractionalAssignment) RampedSelectionStrategy(uk.ac.sussex.gdsc.smlm.ga.RampedSelectionStrategy) FileUtils(uk.ac.sussex.gdsc.core.utils.FileUtils) ConvergenceToleranceChecker(uk.ac.sussex.gdsc.smlm.search.ConvergenceToleranceChecker) FitnessFunction(uk.ac.sussex.gdsc.smlm.ga.FitnessFunction) PlugIn(ij.plugin.PlugIn) MultiPathFilter(uk.ac.sussex.gdsc.smlm.results.filter.MultiPathFilter) PolynomialSplineFunction(org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction) Prefs(ij.Prefs) StoredData(uk.ac.sussex.gdsc.core.utils.StoredData) FrameCounter(uk.ac.sussex.gdsc.smlm.results.count.FrameCounter) SimpleDateFormat(java.text.SimpleDateFormat) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) MatchResult(uk.ac.sussex.gdsc.core.match.MatchResult) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ToleranceChecker(uk.ac.sussex.gdsc.smlm.ga.ToleranceChecker) GenericDialog(ij.gui.GenericDialog) PeakResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.PeakResultProcedure) FitConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitConfiguration) Overlay(ij.gui.Overlay) Population(uk.ac.sussex.gdsc.smlm.ga.Population) BenchmarkSpotFilterResult(uk.ac.sussex.gdsc.smlm.ij.plugins.benchmark.BenchmarkSpotFilter.BenchmarkSpotFilterResult) CombinatoricsUtils(org.apache.commons.math3.util.CombinatoricsUtils) FileOutputStream(java.io.FileOutputStream) FractionClassificationResult(uk.ac.sussex.gdsc.core.match.FractionClassificationResult) File(java.io.File) DirectFilter(uk.ac.sussex.gdsc.smlm.results.filter.DirectFilter) ResultsMatchCalculator(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsMatchCalculator) PreprocessedPeakResult(uk.ac.sussex.gdsc.smlm.results.filter.PreprocessedPeakResult) SimpleSelectionStrategy(uk.ac.sussex.gdsc.smlm.ga.SimpleSelectionStrategy) MaximaSpotFilter(uk.ac.sussex.gdsc.smlm.filters.MaximaSpotFilter) BufferedReader(java.io.BufferedReader) DoubleEquality(uk.ac.sussex.gdsc.core.utils.DoubleEquality) FractionScoreStore(uk.ac.sussex.gdsc.smlm.results.filter.MultiPathFilter.FractionScoreStore) NonBlockingGenericDialog(ij.gui.NonBlockingGenericDialog) SimpleRecombiner(uk.ac.sussex.gdsc.smlm.ga.SimpleRecombiner) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) Date(java.util.Date) FilterCandidates(uk.ac.sussex.gdsc.smlm.ij.plugins.benchmark.BenchmarkSpotFit.FilterCandidates) TextWindow(ij.text.TextWindow) BenchmarkSpotFitResult(uk.ac.sussex.gdsc.smlm.ij.plugins.benchmark.BenchmarkSpotFit.BenchmarkSpotFitResult) ParameterType(uk.ac.sussex.gdsc.smlm.results.filter.ParameterType) StoredDataStatistics(uk.ac.sussex.gdsc.core.utils.StoredDataStatistics) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultAssignment(uk.ac.sussex.gdsc.smlm.results.filter.ResultAssignment) PlotWindow(ij.gui.PlotWindow) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) TIntObjectProcedure(gnu.trove.procedure.TIntObjectProcedure) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) Recombiner(uk.ac.sussex.gdsc.smlm.ga.Recombiner) SimpleMutator(uk.ac.sussex.gdsc.smlm.ga.SimpleMutator) BufferedTextWindow(uk.ac.sussex.gdsc.core.ij.BufferedTextWindow) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) FitEngineConfiguration(uk.ac.sussex.gdsc.smlm.engine.FitEngineConfiguration) SpotFinderPreview(uk.ac.sussex.gdsc.smlm.ij.plugins.SpotFinderPreview) Coordinate(uk.ac.sussex.gdsc.core.match.Coordinate) Gaussian2DPeakResultHelper(uk.ac.sussex.gdsc.smlm.results.Gaussian2DPeakResultHelper) Logger(java.util.logging.Logger) FractionalAssignment(uk.ac.sussex.gdsc.core.match.FractionalAssignment) ResultAssignmentDistanceComparator(uk.ac.sussex.gdsc.smlm.results.filter.ResultAssignmentDistanceComparator) FilterXStreamUtils(uk.ac.sussex.gdsc.smlm.results.filter.FilterXStreamUtils) SettingsList(uk.ac.sussex.gdsc.core.utils.SettingsList) List(java.util.List) SearchDimension(uk.ac.sussex.gdsc.smlm.search.SearchDimension) FullScoreFunction(uk.ac.sussex.gdsc.smlm.search.FullScoreFunction) ResultsImageSampler(uk.ac.sussex.gdsc.smlm.ij.results.ResultsImageSampler) Rectangle(java.awt.Rectangle) PeakResultGridManager(uk.ac.sussex.gdsc.smlm.results.PeakResultGridManager) ConsecutiveFailCounter(uk.ac.sussex.gdsc.smlm.results.count.ConsecutiveFailCounter) GridCoordinateStore(uk.ac.sussex.gdsc.smlm.results.filter.GridCoordinateStore) PrecisionMethod(uk.ac.sussex.gdsc.smlm.data.config.FitProtos.PrecisionMethod) FixedDimension(uk.ac.sussex.gdsc.smlm.search.FixedDimension) WindowOrganiser(uk.ac.sussex.gdsc.core.ij.plugin.WindowOrganiser) AtomicReference(java.util.concurrent.atomic.AtomicReference) TrackProgress(uk.ac.sussex.gdsc.core.logging.TrackProgress) TextField(java.awt.TextField) Level(java.util.logging.Level) ParameterUtils(uk.ac.sussex.gdsc.smlm.ij.plugins.ParameterUtils) ImageListener(ij.ImageListener) TemplateSettings(uk.ac.sussex.gdsc.smlm.data.config.TemplateProtos.TemplateSettings) OutputStreamWriter(java.io.OutputStreamWriter) LinkedList(java.util.LinkedList) ScoreFunctionHelper(uk.ac.sussex.gdsc.smlm.search.ScoreFunctionHelper) ConcurrentRuntimeException(org.apache.commons.lang3.concurrent.ConcurrentRuntimeException) GUIFilterSettings(uk.ac.sussex.gdsc.smlm.ij.settings.GUIProtos.GUIFilterSettings) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) Iterator(java.util.Iterator) RampedScore(uk.ac.sussex.gdsc.core.utils.RampedScore) CoordinateStore(uk.ac.sussex.gdsc.smlm.results.filter.CoordinateStore) Checkbox(java.awt.Checkbox) FilterType(uk.ac.sussex.gdsc.smlm.results.filter.FilterType) ConfigurationTemplate(uk.ac.sussex.gdsc.smlm.ij.plugins.ConfigurationTemplate) FilterSet(uk.ac.sussex.gdsc.smlm.results.filter.FilterSet) ClassificationResult(uk.ac.sussex.gdsc.core.match.ClassificationResult) FileInputStream(java.io.FileInputStream) Recorder(ij.plugin.frame.Recorder) Ticker(uk.ac.sussex.gdsc.core.logging.Ticker) SelectionStrategy(uk.ac.sussex.gdsc.smlm.ga.SelectionStrategy) Consumer(java.util.function.Consumer) ImageWindow(ij.gui.ImageWindow) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) SimpleRegression(org.apache.commons.math3.stat.regression.SimpleRegression) HistogramPlot(uk.ac.sussex.gdsc.core.ij.HistogramPlot) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) IJ(ij.IJ) SmlmUsageTracker(uk.ac.sussex.gdsc.smlm.ij.plugins.SmlmUsageTracker) Nullable(uk.ac.sussex.gdsc.core.annotation.Nullable) Comparator(java.util.Comparator) Collections(java.util.Collections) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) UniformRandomProviders(uk.ac.sussex.gdsc.core.utils.rng.UniformRandomProviders) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) FrameCounter(uk.ac.sussex.gdsc.smlm.results.count.FrameCounter) ConsecutiveFailCounter(uk.ac.sussex.gdsc.smlm.results.count.ConsecutiveFailCounter) Counter(uk.ac.sussex.gdsc.smlm.results.count.Counter) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) FrameCounter(uk.ac.sussex.gdsc.smlm.results.count.FrameCounter) BasePreprocessedPeakResult(uk.ac.sussex.gdsc.smlm.results.filter.BasePreprocessedPeakResult) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) PreprocessedPeakResult(uk.ac.sussex.gdsc.smlm.results.filter.PreprocessedPeakResult)

Aggregations

TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)43 ArrayList (java.util.ArrayList)15 LinkedList (java.util.LinkedList)13 PeakResultPoint (uk.ac.sussex.gdsc.smlm.results.PeakResultPoint)12 List (java.util.List)11 Coordinate (uk.ac.sussex.gdsc.core.match.Coordinate)10 Ticker (uk.ac.sussex.gdsc.core.logging.Ticker)9 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)9 TIntHashSet (gnu.trove.set.hash.TIntHashSet)8 IJ (ij.IJ)8 Prefs (ij.Prefs)8 PlugIn (ij.plugin.PlugIn)8 TextWindow (ij.text.TextWindow)8 Arrays (java.util.Arrays)8 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 ImageJUtils (uk.ac.sussex.gdsc.core.ij.ImageJUtils)8 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)8 MathUtils (uk.ac.sussex.gdsc.core.utils.MathUtils)8 TIntProcedure (gnu.trove.procedure.TIntProcedure)7