/// <summary> /// Applies a procedure to each element of the receiver, if any. /// Starts at index 0, moving rightwards. /// <summary> /// <param name="procedure"> the procedure to be appliedd Stops iteration if the procedure returns <i>false</i>, otherwise continuesd</param> /// <returns><i>false</i> if the procedure stopped before all elements where iterated over, <i>true</i> otherwised</returns> public virtual Boolean ForEach(DoubleProcedure procedure) { for (int i = 0; i < _size;) { if (!procedure(Get(i++))) { return(false); } } return(true); }
/// <summary> /// Constructs and returns a new <i>selection view</i> that is a matrix holding the cells matching the given condition. /// Applies the condition to each cell and takes only those cells where <tt>condition.apply(get(i))</tt> yields <tt>true</tt>. /// </summary> /// <param name="condition"> /// The condition to be matched. /// </param> /// <returns> /// The new view. /// </returns> public virtual DoubleMatrix1D ViewSelection(DoubleProcedure condition) { var matches = new IntArrayList(); for (int i = 0; i < Size; i++) { if (condition(this[i])) { matches.Add(i); } } return(ViewSelection(matches.ToArray())); }
/// <summary> /// Applies a procedure to each element of the receiver, if any. /// Iterates over the receiver in no particular order. /// </summary> /// <param name="procedure">the procedure to be appliedd Stops iteration if the procedure returns <i>false</i>, otherwise continuesd </param> /// <returns><i>false</i> if the procedure stopped before all elements where iterated over, <i>true</i> otherwise.</returns> public bool ForEach(DoubleProcedure procedure) { double[] theElements = buffer.ToArray(); int theSize = (int)Size; for (int i = 0; i < theSize;) { if (!procedure(theElements[i++])) { return(false); } } return(true); }
/// <summary> /// Applies a procedure to each element of the receiver, if any. /// Starts at index 0, moving rightwards. /// <summary> /// <param name="procedure"> the procedure to be appliedd Stops iteration if the procedure returns <i>false</i>, otherwise continuesd</param> /// <returns><i>false</i> if the procedure stopped before all elements where iterated over, <i>true</i> otherwised</returns> public override Boolean ForEach(DoubleProcedure procedure) { // overridden for performance only. double[] theElements = _elements; int theSize = Size; for (int i = 0; i < theSize;) { if (!procedure(theElements[i++])) { return(false); } } return(true); }
/// <summary> /// Applies a procedure to each element of the receiver, if any. /// Iterates over the receiver in no particular order. /// </summary> /// <param name="procedure">the procedure to be applied. Stops iteration if the procedure returns <tt>false</tt>, otherwise continues.</param> /// <returns><tt>false</tt> if the procedure stopped before all elements where iterated over, <tt>true</tt> otherwise. </returns> public virtual bool ForEach(DoubleProcedure procedure) { return(this.bufferSet.ForEach(procedure)); }