Search in sources :

Example 31 with IntFunction

use of java.util.function.IntFunction in project symja_android_library by axkr.

the class HypergeometricJS method hypergeometric1F2.

public static Complex hypergeometric1F2(Complex a, Complex b, Complex c, Complex x) {
    final int useAsymptotic = 200;
    if (x.norm() > useAsymptotic) {
        Complex p = a.add(b.negate()).add(c.negate()).add(0.5).divide(2.0);
        ArrayList<Complex> ck = new ArrayList<Complex>();
        // 
        ck.add(Complex.ONE);
        ck.add(((a.multiply(3.0).add(b).add(c).add(-2.0)).multiply(a.subtract(b.add(c))).multiply(0.5)).add(b.multiply(c).multiply(2)).add(// 
        -3.0 / 8.0));
        ck.add((a.multiply(3.0).add(b).add(c).add(-2.0)).multiply(a.subtract(b.add(c))).multiply(0.25).add(b.multiply(c).add(-3.0 / 16.0)).pow(2).multiply(// 
        2));
        // 
        ck.add(new Complex(-1.0).multiply(a.multiply(2.0).subtract(3.0)).multiply(b).multiply(c));
        ck.add(a.pow(2.0).multiply(-8.0).add(a.multiply(11.0)).add(b).add(c).add(-2.0).multiply(a.subtract(b.add(c))).multiply(// 
        0.25));
        ck.add(new Complex(-3.0 / 16.0));
        IntFunction<Complex> w = k -> ck.get(k).multiply(x.negate().pow(-k / 2.0)).divide(Math.pow(2.0, k));
        Complex u1 = Complex.I.multiply(p.multiply(Math.PI).add(x.negate().sqrt().multiply(2.0))).exp();
        Complex u2 = new Complex(0.0, -1.0).multiply(p.multiply(Math.PI).add(x.negate().sqrt().multiply(2.0))).exp();
        Complex wLast = w.apply(2);
        Complex w2Negate = wLast.negate();
        Complex s = // 
        u1.multiply(new Complex(0.0, -1.0).multiply(w.apply(1)).add(w2Negate).add(1.0)).add(u2.multiply(Complex.I.multiply(w.apply(1)).add(w2Negate).add(1.0)));
        int k = 3;
        while (wLast.norm() > w.apply(k).norm()) {
            // 
            ck.add(a.multiply(-6.0).add(b.multiply(2)).add(c.multiply(2.0)).add(-4.0).multiply(k).add(a.pow(a).multiply(3.0)).add(b.subtract(c).pow(2.0).negate()).add(a.multiply(b.add(c).add(-2)).multiply(2.0).negate()).add(0.25).add(3.0 * k * k).multiply(1.0 / (2.0 * k)).multiply(// 
            ck.get(k - 1)).subtract(a.negate().add(b).add(c.negate()).add(-0.5).add(k).multiply(a.negate().add(b.negate()).add(c).add(-0.5).add(k)).multiply(a.negate().add(b).add(c).add(-2.5).add(k)).multiply(// 
            ck.get(k - 2))));
            wLast = w.apply(k);
            s = s.add(// 
            u1.multiply(new Complex(0.0, -1.0).pow(k)).multiply(wLast).add(u2.multiply(Complex.I.pow(k)).multiply(wLast)));
            k++;
        }
        Complex t1 = Arithmetic.lanczosApproxGamma(a).reciprocal().multiply(x.negate().pow(p)).multiply(s).divide(2.0 * Math.sqrt(Math.PI));
        Complex t2 = Arithmetic.lanczosApproxGamma(b.subtract(a)).reciprocal().multiply(Arithmetic.lanczosApproxGamma(c.subtract(a)).reciprocal()).multiply(x.negate().pow(a.negate())).multiply(hypergeometricSeries(new Complex[] { a, a.add(b.negate()).add(1), a.add(c.negate().add(1.0)) }, new Complex[] {}, // , true ) );
        x.reciprocal()));
        // hypergeometricSeries( [ a, add(a,neg(b),1), add(a,neg(c),1) ], [], inv(x), true ) );
        return Arithmetic.lanczosApproxGamma(b).multiply(Arithmetic.lanczosApproxGamma(c)).multiply(t1.add(t2));
    }
    return hypergeometricSeries(new Complex[] { a }, new Complex[] { b, c }, x);
}
Also used : Gamma(org.hipparchus.special.Gamma) EvalEngine(org.matheclipse.core.eval.EvalEngine) ResultException(org.matheclipse.core.eval.exception.ResultException) F(org.matheclipse.core.expression.F) Complex(org.hipparchus.complex.Complex) Config(org.matheclipse.core.basic.Config) Math.abs(java.lang.Math.abs) Function(java.util.function.Function) ArrayList(java.util.ArrayList) S(org.matheclipse.core.expression.S) Arithmetic(org.matheclipse.core.builtin.Arithmetic) RecursionLimitExceeded(org.matheclipse.core.eval.exception.RecursionLimitExceeded) IterationLimitExceeded(org.matheclipse.core.eval.exception.IterationLimitExceeded) IntFunction(java.util.function.IntFunction) ArgumentTypeException(org.matheclipse.core.eval.exception.ArgumentTypeException) ArrayList(java.util.ArrayList) Complex(org.hipparchus.complex.Complex)

Example 32 with IntFunction

use of java.util.function.IntFunction in project drill by apache.

the class ConvertMetadataAggregateToDirectScanRule method populateRecords.

/**
 * Populates records list with row group metadata.
 */
private DirectGroupScan populateRecords(Collection<SchemaPath> interestingColumns, Map<String, Class<?>> schema, DrillScanRel scan, ColumnNamesOptions columnNamesOptions) throws IOException {
    ParquetGroupScan parquetGroupScan = (ParquetGroupScan) scan.getGroupScan();
    DrillTable drillTable = Utilities.getDrillTable(scan.getTable());
    Multimap<Path, RowGroupMetadata> rowGroupsMetadataMap = parquetGroupScan.getMetadataProvider().getRowGroupsMetadataMap();
    Table<String, Integer, Object> recordsTable = HashBasedTable.create();
    FormatSelection selection = (FormatSelection) drillTable.getSelection();
    List<String> partitionColumnNames = ColumnExplorer.getPartitionColumnNames(selection.getSelection(), columnNamesOptions);
    FileSystem rawFs = selection.getSelection().getSelectionRoot().getFileSystem(new Configuration());
    DrillFileSystem fileSystem = ImpersonationUtil.createFileSystem(ImpersonationUtil.getProcessUserName(), rawFs.getConf());
    int rowIndex = 0;
    for (Map.Entry<Path, RowGroupMetadata> rgEntry : rowGroupsMetadataMap.entries()) {
        Path path = rgEntry.getKey();
        RowGroupMetadata rowGroupMetadata = rgEntry.getValue();
        List<String> partitionValues = ColumnExplorer.listPartitionValues(path, selection.getSelection().getSelectionRoot(), false);
        for (int i = 0; i < partitionValues.size(); i++) {
            String partitionColumnName = partitionColumnNames.get(i);
            recordsTable.put(partitionColumnName, rowIndex, partitionValues.get(i));
        }
        recordsTable.put(MetastoreAnalyzeConstants.LOCATION_FIELD, rowIndex, ImplicitFileColumns.FQN.getValue(path));
        recordsTable.put(columnNamesOptions.rowGroupIndex(), rowIndex, String.valueOf(rowGroupMetadata.getRowGroupIndex()));
        if (interestingColumns == null) {
            interestingColumns = rowGroupMetadata.getColumnsStatistics().keySet();
        }
        // populates record list with row group column metadata
        for (SchemaPath schemaPath : interestingColumns) {
            ColumnStatistics<?> columnStatistics = rowGroupMetadata.getColumnsStatistics().get(schemaPath);
            // do not gather statistics for array columns as it is not supported by Metastore
            if (containsArrayColumn(rowGroupMetadata.getSchema(), schemaPath)) {
                continue;
            }
            if (IsPredicate.isNullOrEmpty(columnStatistics)) {
                logger.debug("Statistics for {} column wasn't found within {} row group.", schemaPath, path);
                return null;
            }
            for (StatisticsKind<?> statisticsKind : AnalyzeColumnUtils.COLUMN_STATISTICS_FUNCTIONS.keySet()) {
                Object statsValue;
                if (statisticsKind.getName().equalsIgnoreCase(TableStatisticsKind.ROW_COUNT.getName())) {
                    statsValue = TableStatisticsKind.ROW_COUNT.getValue(rowGroupMetadata);
                } else if (statisticsKind.getName().equalsIgnoreCase(ColumnStatisticsKind.NON_NULL_VALUES_COUNT.getName())) {
                    statsValue = TableStatisticsKind.ROW_COUNT.getValue(rowGroupMetadata) - ColumnStatisticsKind.NULLS_COUNT.getFrom(columnStatistics);
                } else {
                    statsValue = columnStatistics.get(statisticsKind);
                }
                String columnStatisticsFieldName = AnalyzeColumnUtils.getColumnStatisticsFieldName(schemaPath.toExpr(), statisticsKind);
                if (statsValue != null) {
                    schema.putIfAbsent(columnStatisticsFieldName, statsValue.getClass());
                    recordsTable.put(columnStatisticsFieldName, rowIndex, statsValue);
                } else {
                    recordsTable.put(columnStatisticsFieldName, rowIndex, BaseParquetMetadataProvider.NULL_VALUE);
                }
            }
        }
        // populates record list with row group metadata
        for (StatisticsKind<?> statisticsKind : AnalyzeColumnUtils.META_STATISTICS_FUNCTIONS.keySet()) {
            String metadataStatisticsFieldName = AnalyzeColumnUtils.getMetadataStatisticsFieldName(statisticsKind);
            Object statisticsValue = rowGroupMetadata.getStatistic(statisticsKind);
            if (statisticsValue != null) {
                schema.putIfAbsent(metadataStatisticsFieldName, statisticsValue.getClass());
                recordsTable.put(metadataStatisticsFieldName, rowIndex, statisticsValue);
            } else {
                recordsTable.put(metadataStatisticsFieldName, rowIndex, BaseParquetMetadataProvider.NULL_VALUE);
            }
        }
        // populates record list internal columns
        recordsTable.put(MetastoreAnalyzeConstants.SCHEMA_FIELD, rowIndex, rowGroupMetadata.getSchema().jsonString());
        recordsTable.put(columnNamesOptions.rowGroupStart(), rowIndex, Long.toString(rowGroupMetadata.getStatistic(() -> ExactStatisticsConstants.START)));
        recordsTable.put(columnNamesOptions.rowGroupLength(), rowIndex, Long.toString(rowGroupMetadata.getStatistic(() -> ExactStatisticsConstants.LENGTH)));
        recordsTable.put(columnNamesOptions.lastModifiedTime(), rowIndex, String.valueOf(fileSystem.getFileStatus(path).getModificationTime()));
        rowIndex++;
    }
    // DynamicPojoRecordReader requires LinkedHashMap with fields order
    // which corresponds to the value position in record list.
    LinkedHashMap<String, Class<?>> orderedSchema = new LinkedHashMap<>();
    for (String s : recordsTable.rowKeySet()) {
        Class<?> clazz = schema.get(s);
        if (clazz != null) {
            orderedSchema.put(s, clazz);
        } else {
            return null;
        }
    }
    IntFunction<List<Object>> collectRecord = currentIndex -> orderedSchema.keySet().stream().map(column -> recordsTable.get(column, currentIndex)).map(value -> value != BaseParquetMetadataProvider.NULL_VALUE ? value : null).collect(Collectors.toList());
    List<List<Object>> records = IntStream.range(0, rowIndex).mapToObj(collectRecord).collect(Collectors.toList());
    DynamicPojoRecordReader<?> reader = new DynamicPojoRecordReader<>(orderedSchema, records);
    ScanStats scanStats = new ScanStats(ScanStats.GroupScanProperty.EXACT_ROW_COUNT, records.size(), 1, schema.size());
    return new DirectGroupScan(reader, scanStats);
}
Also used : MetadataType(org.apache.drill.metastore.metadata.MetadataType) FileSystem(org.apache.hadoop.fs.FileSystem) IsPredicate(org.apache.drill.exec.expr.IsPredicate) LoggerFactory(org.slf4j.LoggerFactory) ColumnStatistics(org.apache.drill.metastore.statistics.ColumnStatistics) DrillFileSystem(org.apache.drill.exec.store.dfs.DrillFileSystem) DictColumnMetadata(org.apache.drill.exec.record.metadata.DictColumnMetadata) PathSegment(org.apache.drill.common.expression.PathSegment) Utilities(org.apache.drill.exec.util.Utilities) Configuration(org.apache.hadoop.conf.Configuration) Map(java.util.Map) Path(org.apache.hadoop.fs.Path) ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) Multimap(org.apache.drill.shaded.guava.com.google.common.collect.Multimap) ColumnStatisticsKind(org.apache.drill.metastore.statistics.ColumnStatisticsKind) Collection(java.util.Collection) SchemaPath(org.apache.drill.common.expression.SchemaPath) BaseParquetMetadataProvider(org.apache.drill.exec.store.parquet.BaseParquetMetadataProvider) MetastoreAnalyzeConstants(org.apache.drill.exec.metastore.analyze.MetastoreAnalyzeConstants) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) ImplicitFileColumns(org.apache.drill.exec.store.ColumnExplorer.ImplicitFileColumns) Collectors(java.util.stream.Collectors) DynamicPojoRecordReader(org.apache.drill.exec.store.pojo.DynamicPojoRecordReader) List(java.util.List) MetadataAggregateContext(org.apache.drill.exec.metastore.analyze.MetadataAggregateContext) IntStream(java.util.stream.IntStream) Table(org.apache.drill.shaded.guava.com.google.common.collect.Table) ColumnExplorer(org.apache.drill.exec.store.ColumnExplorer) Function(java.util.function.Function) ColumnNamesOptions(org.apache.drill.exec.metastore.ColumnNamesOptions) LinkedHashMap(java.util.LinkedHashMap) FormatSelection(org.apache.drill.exec.store.dfs.FormatSelection) ImpersonationUtil(org.apache.drill.exec.util.ImpersonationUtil) TableStatisticsKind(org.apache.drill.metastore.statistics.TableStatisticsKind) ParquetGroupScan(org.apache.drill.exec.store.parquet.ParquetGroupScan) IntFunction(java.util.function.IntFunction) PrelUtil(org.apache.drill.exec.planner.physical.PrelUtil) Logger(org.slf4j.Logger) ScanStats(org.apache.drill.exec.physical.base.ScanStats) ExactStatisticsConstants(org.apache.drill.metastore.statistics.ExactStatisticsConstants) RowGroupMetadata(org.apache.drill.metastore.metadata.RowGroupMetadata) StatisticsKind(org.apache.drill.metastore.statistics.StatisticsKind) HashBasedTable(org.apache.drill.shaded.guava.com.google.common.collect.HashBasedTable) IOException(java.io.IOException) RelNode(org.apache.calcite.rel.RelNode) RelOptRuleCall(org.apache.calcite.plan.RelOptRuleCall) DirectGroupScan(org.apache.drill.exec.store.direct.DirectGroupScan) RelOptRule(org.apache.calcite.plan.RelOptRule) PlannerSettings(org.apache.drill.exec.planner.physical.PlannerSettings) GroupScan(org.apache.drill.exec.physical.base.GroupScan) AnalyzeColumnUtils(org.apache.drill.exec.metastore.analyze.AnalyzeColumnUtils) Configuration(org.apache.hadoop.conf.Configuration) FormatSelection(org.apache.drill.exec.store.dfs.FormatSelection) LinkedHashMap(java.util.LinkedHashMap) DrillFileSystem(org.apache.drill.exec.store.dfs.DrillFileSystem) SchemaPath(org.apache.drill.common.expression.SchemaPath) FileSystem(org.apache.hadoop.fs.FileSystem) DrillFileSystem(org.apache.drill.exec.store.dfs.DrillFileSystem) List(java.util.List) Path(org.apache.hadoop.fs.Path) SchemaPath(org.apache.drill.common.expression.SchemaPath) DynamicPojoRecordReader(org.apache.drill.exec.store.pojo.DynamicPojoRecordReader) DirectGroupScan(org.apache.drill.exec.store.direct.DirectGroupScan) RowGroupMetadata(org.apache.drill.metastore.metadata.RowGroupMetadata) ParquetGroupScan(org.apache.drill.exec.store.parquet.ParquetGroupScan) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ScanStats(org.apache.drill.exec.physical.base.ScanStats)

Example 33 with IntFunction

use of java.util.function.IntFunction in project DrivenByMoss by git-moss.

the class HwSurfaceFactoryImpl method createLight.

/**
 * {@inheritDoc}
 */
@Override
public IHwLight createLight(final int surfaceID, final OutputID outputID, final IntSupplier supplier, final IntConsumer sendValueConsumer, final IntFunction<ColorEx> stateToColorFunction, final IHwButton button) {
    this.lightCounter++;
    final String id = createID(surfaceID, outputID == null ? "LIGHT" + this.lightCounter : outputID.name());
    final MultiStateHardwareLight hardwareLight = this.hardwareSurface.createMultiStateHardwareLight(id);
    final Supplier<InternalHardwareLightState> valueSupplier = () -> new EncodedColorLightState(supplier.getAsInt(), stateToColorFunction);
    final Consumer<InternalHardwareLightState> hardwareUpdater = state -> {
        final HardwareLightVisualState visualState = state == null ? null : state.getVisualState();
        final int encodedColorState = visualState == null ? 0 : supplier.getAsInt();
        sendValueConsumer.accept(encodedColorState);
    };
    final HwLightImpl lightImpl = new HwLightImpl(this.host, hardwareLight, valueSupplier, hardwareUpdater);
    if (button != null)
        button.addLight(lightImpl);
    return lightImpl;
}
Also used : IHwTextDisplay(de.mossgrabers.framework.controller.hardware.IHwTextDisplay) IHwButton(de.mossgrabers.framework.controller.hardware.IHwButton) HostImpl(de.mossgrabers.bitwig.framework.daw.HostImpl) Color(com.bitwig.extension.api.Color) IntConsumer(java.util.function.IntConsumer) IHwSurfaceFactory(de.mossgrabers.framework.controller.hardware.IHwSurfaceFactory) HardwareLightVisualState(com.bitwig.extension.controller.api.HardwareLightVisualState) OutputID(de.mossgrabers.framework.controller.OutputID) Supplier(java.util.function.Supplier) IHwPianoKeyboard(de.mossgrabers.framework.controller.hardware.IHwPianoKeyboard) RelativeEncoding(de.mossgrabers.framework.controller.valuechanger.RelativeEncoding) ButtonID(de.mossgrabers.framework.controller.ButtonID) ColorEx(de.mossgrabers.framework.controller.color.ColorEx) IntSupplier(java.util.function.IntSupplier) IntFunction(java.util.function.IntFunction) BitmapImpl(de.mossgrabers.bitwig.framework.graphics.BitmapImpl) IHwLight(de.mossgrabers.framework.controller.hardware.IHwLight) OperatingSystem(de.mossgrabers.framework.utils.OperatingSystem) MultiStateHardwareLight(com.bitwig.extension.controller.api.MultiStateHardwareLight) HardwareButton(com.bitwig.extension.controller.api.HardwareButton) ContinuousID(de.mossgrabers.framework.controller.ContinuousID) IHwFader(de.mossgrabers.framework.controller.hardware.IHwFader) Consumer(java.util.function.Consumer) IBitmap(de.mossgrabers.framework.graphics.IBitmap) IHwAbsoluteKnob(de.mossgrabers.framework.controller.hardware.IHwAbsoluteKnob) IHwGraphicsDisplay(de.mossgrabers.framework.controller.hardware.IHwGraphicsDisplay) IHwRelativeKnob(de.mossgrabers.framework.controller.hardware.IHwRelativeKnob) HardwareSurface(com.bitwig.extension.controller.api.HardwareSurface) InternalHardwareLightState(com.bitwig.extension.controller.api.InternalHardwareLightState) MultiStateHardwareLight(com.bitwig.extension.controller.api.MultiStateHardwareLight) InternalHardwareLightState(com.bitwig.extension.controller.api.InternalHardwareLightState) HardwareLightVisualState(com.bitwig.extension.controller.api.HardwareLightVisualState)

Aggregations

IntFunction (java.util.function.IntFunction)33 List (java.util.List)10 Collectors (java.util.stream.Collectors)10 Test (org.junit.Test)9 Arrays (java.util.Arrays)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 IntStream (java.util.stream.IntStream)7 LoggerFactory (org.slf4j.LoggerFactory)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Objects (java.util.Objects)5 Set (java.util.Set)5 Logger (org.slf4j.Logger)5 File (java.io.File)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Function (java.util.function.Function)4 Supplier (java.util.function.Supplier)4 BytesRef (org.apache.lucene.util.BytesRef)4