Example usage for java.util Arrays fill

List of usage examples for java.util Arrays fill

Introduction

In this page you can find the example usage for java.util Arrays fill.

Prototype

public static void fill(Object[] a, Object val) 

Source Link

Document

Assigns the specified Object reference to each element of the specified array of Objects.

Usage

From source file:edu.cmu.cs.lti.ark.fn.identification.latentmodel.TrainBatchModelDerThreaded.java

private double getValuesAndGradients() {
    double value = 0.0;
    for (double[] tGradient : tGradients)
        Arrays.fill(tGradient, 0.0);
    Arrays.fill(tValues, 0.0);/*from w  ww.  j a  va 2  s  .  c om*/

    final ThreadPool threadPool = new ThreadPool(numThreads);
    int task = 0;
    for (int i = 0; i < eventFiles.size(); i += BATCH_SIZE) {
        final int taskId = task;
        final int start = i;
        final int end = Math.min(i + BATCH_SIZE, eventFiles.size());
        threadPool.runTask(new Runnable() {
            public void run() {
                logger.info("Task " + taskId + " : start");
                try {
                    processBatch(taskId, start, end);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
                logger.info("Task " + taskId + " : end");
            }
        });
        task++;
    }
    threadPool.join();
    // merge the calculated tValues and gradients together
    Arrays.fill(gradients, 0.0);
    for (int i = 0; i < numThreads; i++) {
        value += tValues[i];
        for (int j = 0; j < modelSize; j++) {
            gradients[j] += tGradients[i][j];
        }
    }
    System.out.println("Finished value and gradient computation.");
    return value;
}

From source file:org.cloudfoundry.identity.uaa.codestore.CodeStoreEndpointsTests.java

@Test
public void testStoreLargeData() throws Exception {
    char[] oneMb = new char[1024 * 1024];
    Arrays.fill(oneMb, 'a');
    String data = new String(oneMb);
    Timestamp expiresAt = new Timestamp(System.currentTimeMillis() + 60000);
    ExpiringCode expiringCode = new ExpiringCode(null, expiresAt, data);

    ExpiringCode generatedCode = codeStoreEndpoints.generateCode(expiringCode);

    String code = generatedCode.getCode();
    ExpiringCode actualCode = codeStoreEndpoints.retrieveCode(code);

    assertEquals(generatedCode, actualCode);
}

From source file:com.espertech.esper.rowregex.EventRowRegexNFAViewFactory.java

/**
 * Ctor.//w w w .  j a  va 2s.  c o  m
 * @param viewChain views
 * @param matchRecognizeSpec specification
 * @param statementContext statement context
 * @param isUnbound true for unbound stream
 * @param annotations annotations
 * @throws ExprValidationException if validation fails
 */
public EventRowRegexNFAViewFactory(ViewFactoryChain viewChain, MatchRecognizeSpec matchRecognizeSpec,
        StatementContext statementContext, boolean isUnbound, Annotation[] annotations)
        throws ExprValidationException {
    EventType parentViewType = viewChain.getEventType();
    this.matchRecognizeSpec = matchRecognizeSpec;
    this.isUnbound = isUnbound;
    this.isIterateOnly = HintEnum.ITERATE_ONLY.getHint(annotations) != null;

    // Determine single-row and multiple-row variables
    variablesSingle = new LinkedHashSet<String>();
    Set<String> variablesMultiple = new LinkedHashSet<String>();
    EventRowRegexHelper.recursiveInspectVariables(matchRecognizeSpec.getPattern(), false, variablesSingle,
            variablesMultiple);

    // each variable gets associated with a stream number (multiple-row variables as well to hold the current event for the expression).
    int streamNum = 0;
    variableStreams = new LinkedHashMap<String, Pair<Integer, Boolean>>();
    for (String variableSingle : variablesSingle) {
        variableStreams.put(variableSingle, new Pair<Integer, Boolean>(streamNum, false));
        streamNum++;
    }
    for (String variableMultiple : variablesMultiple) {
        variableStreams.put(variableMultiple, new Pair<Integer, Boolean>(streamNum, true));
        streamNum++;
    }

    // mapping of stream to variable
    streamVariables = new TreeMap<Integer, String>();
    for (Map.Entry<String, Pair<Integer, Boolean>> entry : variableStreams.entrySet()) {
        streamVariables.put(entry.getValue().getFirst(), entry.getKey());
    }

    // assemble all single-row variables for expression validation
    String[] singleVarStreamNames = new String[variableStreams.size()];
    String[] allStreamNames = new String[variableStreams.size()];
    EventType[] singleVarTypes = new EventType[variableStreams.size()];
    EventType[] allTypes = new EventType[variableStreams.size()];

    streamNum = 0;
    for (String variableSingle : variablesSingle) {
        singleVarStreamNames[streamNum] = variableSingle;
        singleVarTypes[streamNum] = parentViewType;
        allStreamNames[streamNum] = variableSingle;
        allTypes[streamNum] = parentViewType;
        streamNum++;
    }
    for (String variableMultiple : variablesMultiple) {
        allStreamNames[streamNum] = variableMultiple;
        allTypes[streamNum] = parentViewType;
        streamNum++;
    }

    // determine type service for use with DEFINE
    // validate each DEFINE clause expression
    Set<String> definedVariables = new HashSet<String>();
    List<ExprAggregateNode> aggregateNodes = new ArrayList<ExprAggregateNode>();
    for (MatchRecognizeDefineItem defineItem : matchRecognizeSpec.getDefines()) {
        if (definedVariables.contains(defineItem.getIdentifier())) {
            throw new ExprValidationException(
                    "Variable '" + defineItem.getIdentifier() + "' has already been defined");
        }
        definedVariables.add(defineItem.getIdentifier());

        String[] streamNamesDefine = new String[singleVarStreamNames.length];
        System.arraycopy(singleVarStreamNames, 0, streamNamesDefine, 0, singleVarStreamNames.length);
        EventType[] typesDefine = new EventType[singleVarTypes.length];
        System.arraycopy(singleVarTypes, 0, typesDefine, 0, singleVarTypes.length);
        boolean[] isIStreamOnly = new boolean[singleVarTypes.length];
        Arrays.fill(isIStreamOnly, true);

        // the own stream is available for querying
        if (!variableStreams.containsKey(defineItem.getIdentifier())) {
            throw new ExprValidationException(
                    "Variable '" + defineItem.getIdentifier() + "' does not occur in pattern");
        }
        int streamNumDefine = variableStreams.get(defineItem.getIdentifier()).getFirst();
        streamNamesDefine[streamNumDefine] = defineItem.getIdentifier();
        typesDefine[streamNumDefine] = parentViewType;

        StreamTypeService typeServiceDefines = new StreamTypeServiceImpl(typesDefine, streamNamesDefine,
                isIStreamOnly, statementContext.getEngineURI(), false);
        ExprNode exprNodeResult = handlePreviousFunctions(defineItem.getExpression());
        ExprValidationContext validationContext = new ExprValidationContext(typeServiceDefines,
                statementContext.getMethodResolutionService(), null, statementContext.getSchedulingService(),
                statementContext.getVariableService(), statementContext,
                statementContext.getEventAdapterService(), statementContext.getStatementName(),
                statementContext.getStatementId(), statementContext.getAnnotations());
        ExprNode validated = ExprNodeUtility.getValidatedSubtree(exprNodeResult, validationContext);
        defineItem.setExpression(validated);

        ExprAggregateNodeUtil.getAggregatesBottomUp(validated, aggregateNodes);
        if (!aggregateNodes.isEmpty()) {
            throw new ExprValidationException("An aggregate function may not appear in a DEFINE clause");
        }
    }

    // determine type service for use with MEASURE
    Map<String, Object> measureTypeDef = new LinkedHashMap<String, Object>();
    for (String variableSingle : variablesSingle) {
        measureTypeDef.put(variableSingle, parentViewType);
    }
    for (String variableMultiple : variablesMultiple) {
        measureTypeDef.put(variableMultiple, new EventType[] { parentViewType });
    }
    String outputEventTypeName = statementContext.getStatementId() + "_rowrecog";
    compositeEventType = statementContext.getEventAdapterService().createAnonymousMapType(outputEventTypeName,
            measureTypeDef);
    StreamTypeService typeServiceMeasure = new StreamTypeServiceImpl(compositeEventType, "MATCH_RECOGNIZE",
            true, statementContext.getEngineURI());

    // find MEASURE clause aggregations
    boolean measureReferencesMultivar = false;
    List<ExprAggregateNode> measureAggregateExprNodes = new ArrayList<ExprAggregateNode>();
    for (MatchRecognizeMeasureItem measureItem : matchRecognizeSpec.getMeasures()) {
        ExprAggregateNodeUtil.getAggregatesBottomUp(measureItem.getExpr(), measureAggregateExprNodes);
    }
    if (!measureAggregateExprNodes.isEmpty()) {
        boolean[] isIStreamOnly = new boolean[allStreamNames.length];
        Arrays.fill(isIStreamOnly, true);
        StreamTypeServiceImpl typeServiceAggregateMeasure = new StreamTypeServiceImpl(allTypes, allStreamNames,
                isIStreamOnly, statementContext.getEngineURI(), false);
        Map<Integer, List<ExprAggregateNode>> measureExprAggNodesPerStream = new HashMap<Integer, List<ExprAggregateNode>>();

        for (ExprAggregateNode aggregateNode : measureAggregateExprNodes) {
            int count = 0;
            ExprNodeIdentifierVisitor visitor = new ExprNodeIdentifierVisitor(true);

            ExprValidationContext validationContext = new ExprValidationContext(typeServiceAggregateMeasure,
                    statementContext.getMethodResolutionService(), null,
                    statementContext.getSchedulingService(), statementContext.getVariableService(),
                    statementContext, statementContext.getEventAdapterService(),
                    statementContext.getStatementName(), statementContext.getStatementId(),
                    statementContext.getAnnotations());
            for (ExprNode child : aggregateNode.getChildNodes()) {
                ExprNode validated = ExprNodeUtility.getValidatedSubtree(child, validationContext);
                validated.accept(visitor);
                aggregateNode.getChildNodes().set(count++, new ExprNodeValidated(validated));
            }
            validationContext = new ExprValidationContext(typeServiceMeasure,
                    statementContext.getMethodResolutionService(), null,
                    statementContext.getSchedulingService(), statementContext.getVariableService(),
                    statementContext, statementContext.getEventAdapterService(),
                    statementContext.getStatementName(), statementContext.getStatementId(),
                    statementContext.getAnnotations());
            aggregateNode.validate(validationContext);

            // verify properties used within the aggregation
            Set<Integer> aggregatedStreams = new HashSet<Integer>();
            for (Pair<Integer, String> pair : visitor.getExprProperties()) {
                aggregatedStreams.add(pair.getFirst());
            }

            Integer multipleVarStream = null;
            for (int streamNumAggregated : aggregatedStreams) {
                String variable = streamVariables.get(streamNumAggregated);
                if (variablesMultiple.contains(variable)) {
                    measureReferencesMultivar = true;
                    if (multipleVarStream == null) {
                        multipleVarStream = streamNumAggregated;
                        continue;
                    }
                    throw new ExprValidationException(
                            "Aggregation functions in the measure-clause must only refer to properties of exactly one group variable returning multiple events");
                }
            }

            if (multipleVarStream == null) {
                throw new ExprValidationException(
                        "Aggregation functions in the measure-clause must refer to one or more properties of exactly one group variable returning multiple events");
            }

            List<ExprAggregateNode> aggNodesForStream = measureExprAggNodesPerStream.get(multipleVarStream);
            if (aggNodesForStream == null) {
                aggNodesForStream = new ArrayList<ExprAggregateNode>();
                measureExprAggNodesPerStream.put(multipleVarStream, aggNodesForStream);
            }
            aggNodesForStream.add(aggregateNode);
        }

        aggregationService = AggregationServiceFactory.getServiceMatchRecognize(streamVariables.size(),
                measureExprAggNodesPerStream, statementContext.getMethodResolutionService(), statementContext);
    } else {
        aggregationService = null;
    }

    // validate each MEASURE clause expression
    Map<String, Object> rowTypeDef = new LinkedHashMap<String, Object>();
    ExprNodeIdentifierCollectVisitor streamRefVisitorNonAgg = new ExprNodeIdentifierCollectVisitor();
    for (MatchRecognizeMeasureItem measureItem : matchRecognizeSpec.getMeasures()) {
        if (measureItem.getName() == null) {
            throw new ExprValidationException(
                    "The measures clause requires that each expression utilizes the AS keyword to assign a column name");
        }
        ExprNode validated = validateMeasureClause(measureItem.getExpr(), typeServiceMeasure, variablesMultiple,
                variablesSingle, statementContext);
        measureItem.setExpr(validated);
        rowTypeDef.put(measureItem.getName(), validated.getExprEvaluator().getType());
        validated.accept(streamRefVisitorNonAgg);
    }

    // Determine if any of the multi-var streams are referenced in the measures (non-aggregated only)
    for (ExprIdentNode ref : streamRefVisitorNonAgg.getExprProperties()) {
        String rootPropName = ref.getResolvedPropertyNameRoot();
        if (variablesMultiple.contains(rootPropName) || (rootPropName == null)) {
            measureReferencesMultivar = true;
            break;
        }
    }
    isSelectAsksMultimatches = measureReferencesMultivar;

    // create rowevent type
    String rowEventTypeName = statementContext.getStatementId() + "_rowrecogrow";
    rowEventType = statementContext.getEventAdapterService().createAnonymousMapType(rowEventTypeName,
            rowTypeDef);

    // validate partition-by expressions, if any
    if (!matchRecognizeSpec.getPartitionByExpressions().isEmpty()) {
        StreamTypeService typeServicePartition = new StreamTypeServiceImpl(parentViewType,
                "MATCH_RECOGNIZE_PARTITION", true, statementContext.getEngineURI());
        List<ExprNode> validated = new ArrayList<ExprNode>();
        ExprValidationContext validationContext = new ExprValidationContext(typeServicePartition,
                statementContext.getMethodResolutionService(), null, statementContext.getSchedulingService(),
                statementContext.getVariableService(), statementContext,
                statementContext.getEventAdapterService(), statementContext.getStatementName(),
                statementContext.getStatementId(), statementContext.getAnnotations());
        for (ExprNode partitionExpr : matchRecognizeSpec.getPartitionByExpressions()) {
            validated.add(ExprNodeUtility.getValidatedSubtree(partitionExpr, validationContext));
        }
        matchRecognizeSpec.setPartitionByExpressions(validated);
    }
}

From source file:com.google.uzaygezen.core.LongArrayBitVector.java

@Override
public void clear() {
    Arrays.fill(data, 0L);
}

From source file:it.unibo.alchemist.language.protelis.util.HoodOp.java

private static Tuple cTup(final Object v, final int size) {
    final Object[] r = new Object[size];
    Arrays.fill(r, v);
    return Tuples.create(r);
}

From source file:com.espertech.esper.core.start.EPPreparedExecuteMethodQuery.java

/**
 * Ctor.//from   w w w. ja  v a 2 s.com
 * @param statementSpec is a container for the definition of all statement constructs that
 * may have been used in the statement, i.e. if defines the select clauses, insert into, outer joins etc.
 * @param services is the service instances for dependency injection
 * @param statementContext is statement-level information and statement services
 * @throws ExprValidationException if the preparation failed
 */
public EPPreparedExecuteMethodQuery(StatementSpecCompiled statementSpec, EPServicesContext services,
        StatementContext statementContext) throws ExprValidationException {
    boolean queryPlanLogging = services.getConfigSnapshot().getEngineDefaults().getLogging()
            .isEnableQueryPlan();
    if (queryPlanLogging) {
        queryPlanLog.info("Query plans for Fire-and-forget query '" + statementContext.getExpression() + "'");
    }

    this.statementSpec = statementSpec;
    this.services = services;

    EPPreparedExecuteMethodHelper.validateFAFQuery(statementSpec);

    int numStreams = statementSpec.getStreamSpecs().length;
    EventType[] typesPerStream = new EventType[numStreams];
    String[] namesPerStream = new String[numStreams];
    processors = new NamedWindowProcessor[numStreams];
    agentInstanceContext = new AgentInstanceContext(statementContext, null, -1, null, null,
            statementContext.getDefaultAgentInstanceScriptContext());

    // resolve types and named window processors
    for (int i = 0; i < numStreams; i++) {
        final StreamSpecCompiled streamSpec = statementSpec.getStreamSpecs()[i];
        NamedWindowConsumerStreamSpec namedSpec = (NamedWindowConsumerStreamSpec) streamSpec;

        String streamName = namedSpec.getWindowName();
        if (namedSpec.getOptionalStreamName() != null) {
            streamName = namedSpec.getOptionalStreamName();
        }
        namesPerStream[i] = streamName;

        processors[i] = services.getNamedWindowService().getProcessor(namedSpec.getWindowName());
        if (processors[i] == null) {
            throw new ExprValidationException(
                    "A named window by name '" + namedSpec.getWindowName() + "' does not exist");
        }
        typesPerStream[i] = processors[i].getTailView().getEventType();
    }

    // compile filter to optimize access to named window
    filters = new FilterSpecCompiled[numStreams];
    if (statementSpec.getFilterRootNode() != null) {
        LinkedHashMap<String, Pair<EventType, String>> tagged = new LinkedHashMap<String, Pair<EventType, String>>();
        for (int i = 0; i < numStreams; i++) {
            try {
                StreamTypeServiceImpl types = new StreamTypeServiceImpl(typesPerStream, namesPerStream,
                        new boolean[numStreams], services.getEngineURI(), false);
                filters[i] = FilterSpecCompiler.makeFilterSpec(typesPerStream[i], namesPerStream[i],
                        Collections.singletonList(statementSpec.getFilterRootNode()), null, tagged, tagged,
                        types, null, statementContext, Collections.singleton(i));
            } catch (Exception ex) {
                log.warn("Unexpected exception analyzing filter paths: " + ex.getMessage(), ex);
            }
        }
    }

    // obtain result set processor
    boolean[] isIStreamOnly = new boolean[namesPerStream.length];
    Arrays.fill(isIStreamOnly, true);
    StreamTypeService typeService = new StreamTypeServiceImpl(typesPerStream, namesPerStream, isIStreamOnly,
            services.getEngineURI(), true);
    EPStatementStartMethodHelperValidate.validateNodes(statementSpec, statementContext, typeService, null);

    ResultSetProcessorFactoryDesc resultSetProcessorPrototype = ResultSetProcessorFactoryFactory
            .getProcessorPrototype(statementSpec, statementContext, typeService, null, new boolean[0], true,
                    ContextPropertyRegistryImpl.EMPTY_REGISTRY, null);
    resultSetProcessor = EPStatementStartMethodHelperAssignExpr
            .getAssignResultSetProcessor(agentInstanceContext, resultSetProcessorPrototype);

    if (statementSpec.getSelectClauseSpec().isDistinct()) {
        if (resultSetProcessor.getResultEventType() instanceof EventTypeSPI) {
            eventBeanReader = ((EventTypeSPI) resultSetProcessor.getResultEventType()).getReader();
        }
        if (eventBeanReader == null) {
            eventBeanReader = new EventBeanReaderDefaultImpl(resultSetProcessor.getResultEventType());
        }
    }

    // plan joins or simple queries
    if (numStreams > 1) {
        StreamJoinAnalysisResult streamJoinAnalysisResult = new StreamJoinAnalysisResult(numStreams);
        Arrays.fill(streamJoinAnalysisResult.getNamedWindow(), true);
        for (int i = 0; i < numStreams; i++) {
            NamedWindowProcessorInstance processorInstance = processors[i]
                    .getProcessorInstance(agentInstanceContext);
            if (processors[i].isVirtualDataWindow()) {
                streamJoinAnalysisResult.getViewExternal()[i] = processorInstance.getRootViewInstance()
                        .getVirtualDataWindow();
            }
            String[][] uniqueIndexes = processors[i].getUniqueIndexes(processorInstance);
            streamJoinAnalysisResult.getUniqueKeys()[i] = uniqueIndexes;
        }

        boolean hasAggregations = !resultSetProcessorPrototype.getAggregationServiceFactoryDesc()
                .getExpressions().isEmpty();
        joinSetComposerPrototype = JoinSetComposerPrototypeFactory.makeComposerPrototype(null, null,
                statementSpec.getOuterJoinDescList(), statementSpec.getFilterRootNode(), typesPerStream,
                namesPerStream, streamJoinAnalysisResult, queryPlanLogging, statementContext.getAnnotations(),
                new HistoricalViewableDesc(numStreams), agentInstanceContext, false, hasAggregations);
    }

    // check context partition use
    if (statementSpec.getOptionalContextName() != null) {
        if (numStreams > 1) {
            throw new ExprValidationException(
                    "Joins in runtime queries for context partitions are not supported");
        }
    }
}

From source file:gr.aueb.cs.nlp.wordtagger.data.structure.features.FeatureBuilder.java

/**
 * calculates the number of feats a word would have if they were generated from a given model,
 *  and given lookback and lookbehind.//from  w ww.  ja  v  a  2s .com
 * @param lookBehind, the previous words that should be taken into account for word generation,
 * any woord with value %newarticle% is ignored and used in order to stop feature generation 
 * and force a zero padding
 * @param lookAhead, words ahead of the word to be taken into account, works same as lookbehind
 * @return the numebr of features
 */
public int noFeats(int lookBehind, int lookAhead) {
    List<Word> set = new ArrayList<>();
    set.add(new Word("dummy", "null"));
    for (int i = 0; i < set.size(); i++) {
        Word w = set.get(i);
        double[] feats = ambiFeats(w, suffixLength);
        double[] featsBack = new double[0];
        boolean backwardDummy = true;
        for (int j = 1; j <= lookBehind; j++) {
            backwardDummy &= i - j >= 0 && !set.get(i - j).equals("%newarticle%");
            if (backwardDummy) {
                Word prev = set.get(i - j);
                featsBack = ArrayUtils.addAll(featsBack, ambiFeats(prev, suffixLength));
            } else {
                double[] dummy = new double[generator.getCategories().size() * (suffixLength + 1)];
                Arrays.fill(dummy, 0.0);
                featsBack = ArrayUtils.addAll(featsBack, dummy);
            }
        }

        double[] featsForw = new double[0];
        boolean forwardDummy = true;
        for (int j = 1; j <= lookAhead; j++) {
            forwardDummy &= i + j < set.size() && !set.get(i + j).equals("%newarticle%");
            if (forwardDummy) {
                Word next = set.get(i + j);
                featsForw = ArrayUtils.addAll(featsForw, ambiFeats(next, suffixLength));
            } else {
                double[] dummy = new double[generator.getCategories().size() * (suffixLength + 1)];
                Arrays.fill(dummy, 0.0);
                if (featsForw.length == 0) {
                    featsForw = dummy;
                } else {
                    featsForw = ArrayUtils.addAll(featsForw, dummy);
                }
            }
        }

        feats = ArrayUtils.addAll(feats, featsBack);
        feats = ArrayUtils.addAll(feats, featsForw);
        feats = ArrayUtils.addAll(feats, simpleFeats(w));
        w.setFeatureVec(new FeatureVector(feats));
    }
    return set.get(0).getFeatureVec().getValues().length;
}

From source file:circdesigna.DesignSequenceConstraints.java

/**
 * Modifies getBaseCounts_shared.//from ww w  .  j  a  va 2 s . c  o  m
 */
private boolean getBaseCounts(int[] domain) {
    if (hasBaseCounts) {
        return true;
    }

    hasBaseCounts = true;
    //Ensure correct length of share vector
    if (getBaseCounts_shared == null || getBaseCounts_shared.length != Std.monomer.getNumMonomers()) {
        getBaseCounts_shared = new int[Std.monomer.getNumMonomers()];
    }
    Arrays.fill(getBaseCounts_shared, 0);
    for (int k = 0; k < domain.length; k++) {
        getBaseCounts_shared[Std.monomer.noFlags(domain[k])]++;
    }
    return true;
}