Package org.formulacompiler.compiler.internal.expressions

Examples of org.formulacompiler.compiler.internal.expressions.ArrayDescriptor


  @Override
  protected void addDynamicArgsToPartialFold( ExpressionNode _apply, Collection<ExpressionNode[]> _dynArgs )
  {
    final int eltCount = fold.eltCount();
    final ArrayDescriptor desc = new ArrayDescriptor( 1, _dynArgs.size(), 1 );
    final ExpressionNode[] vectors = new ExpressionNode[ eltCount ];
    ExpressionNode[] firstElts = _dynArgs.iterator().next();
    for (int i = 0; i < eltCount; i++) {
      vectors[ i ] = new ExpressionNodeForArrayReference( desc );
      vectors[ i ].setDataType( firstElts[ i ].getDataType() );
View Full Code Here


  }


  private Object evalIndex( ExpressionNodeForArrayReference _range, Object _rowIndex, Object _colIndex )
  {
    final ArrayDescriptor desc = _range.arrayDescriptor();
    final int iRow = valueToIntOrOne( _rowIndex ) - 1;
    final int iCol = valueToIntOrOne( _colIndex ) - 1;
    int iValue;
    if (iRow < 0 || iRow >= desc.numberOfRows())
      throw new FormulaException( "#VALUE/REF! because row out of range in INDEX" );
    if (iCol < 0 || iCol >= desc.numberOfColumns())
      throw new FormulaException( "#VALUE/REF! because column out of range in INDEX" );
    if (null != _rowIndex && null != _colIndex) {
      iValue = iRow * desc.numberOfColumns() + iCol;
    }
    else {
      iValue = iRow + iCol;
    }
    return ((ExpressionNodeForConstantValue) _range.argument( iValue )).value();
View Full Code Here

          elts.add( buildExpressionModelForLocalRange( next ) );
        }
      }

      final CellIndex from = range.getFrom();
      final ExpressionNode result = (shaped) ? new ExpressionNodeForArrayReference( new ArrayDescriptor(
          from.getSheetIndex(), from.getRowIndex(), from.getColumnIndex(), sheets, rows, cols ) )
          : new ExpressionNodeForSubstitution();
      result.arguments().addAll( elts );
      return result;
    }
View Full Code Here

      final CellIndex from = _range.getFrom();
      final CellIndex to = _range.getTo();
      final int sheets = to.getSheetIndex() - from.getSheetIndex() + 1;
      final int rows = to.getRowIndex() - from.getRowIndex() + 1;
      final int cols = to.getColumnIndex() - from.getColumnIndex() + 1;
      final ExpressionNode result = new ExpressionNodeForArrayReference( new ArrayDescriptor( from.getSheetIndex(),
          from.getRowIndex(), from.getColumnIndex(), sheets, rows, cols ) );
      buildExpressionModelsForLocalRangeCells( _range, result.arguments() );
      return result;
    }
View Full Code Here

  }


  private ExpressionNodeForArrayReference makeVertical( ExpressionNodeForArrayReference _vector )
  {
    final ArrayDescriptor desc = _vector.arrayDescriptor();
    assert desc.numberOfSheets() == 1;
    if (desc.numberOfRows() > 1) {
      assert desc.numberOfColumns() == 1;
      return _vector;
    }
    else {
      assert desc.numberOfRows() == 1;
      final ArrayDescriptor newDesc = new ArrayDescriptor( desc.origin(), new ArrayDescriptor.Point( 1, desc
          .numberOfColumns(), 1 ) );
      final ExpressionNodeForArrayReference newVector = new ExpressionNodeForArrayReference( newDesc );
      newVector.arguments().addAll( _vector.arguments() );
      return newVector;
    }
View Full Code Here

  private ExpressionNodeForArrayReference vectorsToMatrix( ExpressionNodeForArrayReference... _vectors )
  {
    final int rows = _vectors[ 0 ].arguments().size();
    final int cols = _vectors.length;
    final ArrayDescriptor desc = new ArrayDescriptor( 1, rows, cols );
    final ExpressionNodeForArrayReference result = new ExpressionNodeForArrayReference( desc );

    for (int row = 0; row < rows; row++)
      for (int col = 0; col < cols; col++)
        result.addArgument( _vectors[ col ].argument( row ) );
View Full Code Here

  {
    switch (_fun.getFunction()) {

      case CHITEST: {
        if (_fun.cardinality() < 6) {
          final ArrayDescriptor descX = ((ExpressionNodeForArrayReference) _fun.argument( 0 )).arrayDescriptor();
          final int colsX = descX.numberOfColumns();
          final int rowsX = descX.numberOfRows();
          final ArrayDescriptor descY = ((ExpressionNodeForArrayReference) _fun.argument( 1 )).arrayDescriptor();
          final int colsY = descY.numberOfColumns();
          final int rowsY = descY.numberOfRows();
          return fun( CHITEST, _fun.argument( 0 ), _fun.argument( 1 ), cst( colsX, DataType.NUMERIC ), cst( rowsX,
              DataType.NUMERIC ), cst( colsY, DataType.NUMERIC ), cst( rowsY, DataType.NUMERIC ) );
        }
        break;
      }
      case MDETERM: {
        if (_fun.cardinality() < 2) {
          final ArrayDescriptor desc = ((ExpressionNodeForArrayReference) _fun.argument( 0 )).arrayDescriptor();
          final int cols = desc.numberOfColumns();
          final int rows = desc.numberOfRows();
          if (cols != rows) {
            throw new CompilerException.UnsupportedExpression( "MDETERM called with non-square matrix" );
          }
          return fun( MDETERM, _fun.argument( 0 ), cst( cols, DataType.NUMERIC ) );
        }
View Full Code Here


  private ExpressionNode rewriteArrayLookup( ExpressionNodeForFunction _fun )
  {
    final ExpressionNodeForArrayReference array = (ExpressionNodeForArrayReference) _fun.argument( 1 );
    final ArrayDescriptor desc = array.arrayDescriptor();
    final int cols = desc.numberOfColumns();
    final int rows = desc.numberOfRows();
    final Function lookupFun;
    final int index;
    if (cols > rows) {
      lookupFun = HLOOKUP;
      index = rows;
View Full Code Here

      final String matchRefName = "x";
      final ExpressionNode matchRefNode = var( matchRefName );
      final ExpressionNode selectorNode = indexNode;
      final ExpressionNode defaultNode = err( "#VALUE/REF! because index is out of range in H/VLOOKUP" );

      final ArrayDescriptor desc = arrayNode.arrayDescriptor();
      final int nArrays = (fun == HLOOKUP) ? desc.numberOfRows() : desc.numberOfColumns();
      final ExpressionNodeForSwitchCase[] caseNodes = new ExpressionNodeForSwitchCase[ nArrays ];
      for (int iArray = 0; iArray < nArrays; iArray++) {
        final ExpressionNode valueArrayNode = getHVLookupSubArray( fun, arrayNode, iArray );
        final ExpressionNode lookupNode = fun( INDEX, valueArrayNode, matchRefNode );
        caseNodes[ iArray ] = new ExpressionNodeForSwitchCase( lookupNode, iArray + 1 );
View Full Code Here

    }
  }

  private ExpressionNode getHVLookupSubArray( Function _fun, ExpressionNodeForArrayReference _arrayNode, int _index )
  {
    final ArrayDescriptor desc = _arrayNode.arrayDescriptor();
    if (_fun == HLOOKUP) {
      final int cols = desc.numberOfColumns();
      return _arrayNode.subArray( _index, 1, 0, cols );
    }
    else {
      final int rows = desc.numberOfRows();
      return _arrayNode.subArray( 0, rows, _index, 1 );
    }
  }
View Full Code Here

TOP

Related Classes of org.formulacompiler.compiler.internal.expressions.ArrayDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.