Beispiel #1
0
 /// <summary>
 /// Applies a procedure to each cell's value.
 /// Iterates downwards from <i>[Size-1]</i> to <i>[0]</i>,
 /// as demonstrated by this snippet:
 /// <pre>
 /// for (int i=Size; --i >=0;) {
 /// if (!procedure.apply(this[i])) return false;
 /// }
 /// return true;
 /// </pre>
 /// Note that an implementation may use more efficient techniques, but must not use any other order.
 /// </summary>
 /// <param name="procedure">a procedure object taking as argument the current cell's valued 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>
 private Boolean XforEach(Cern.Colt.Function.ObjectProcedure <Object> procedure)
 {
     for (int i = Size; --i >= 0;)
     {
         if (!procedure(this[i]))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #2
0
        /// <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 <i>condition.apply(get(i))</i> yields<i>true</i>.
        /// <p>
        /// <b>Example:</b>
        /// <br>
        /// <pre>
        /// // extract and view all cells with even value
        /// matrix = 0 1 2 3
        /// matrix.viewSelection(
        /// &nbsp;&nbsp;&nbsp;new ObjectProcedure()
        /// {
        /// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public Boolean apply(Object a) { return a % 2 == 0; }
        /// &nbsp;&nbsp;&nbsp;}
        /// );
        /// -->
        /// matrix ==  0 2
        /// </pre>
        /// For further examples, see the<a href="package-summary.html#FunctionObjects">package doc</a>.
        /// The returned view is backed by this matrix, so changes in the returned view are reflected in this matrix, and vice-versa.
        /// </summary>
        /// <param name="condition">The condition to be matched.</param>
        /// <returns>the new view.</returns>
        public virtual ObjectMatrix1D ViewSelection(Cern.Colt.Function.ObjectProcedure <Object> condition)
        {
            IntArrayList matches = new IntArrayList();

            for (int i = 0; i < Size; i++)
            {
                if (condition(this[i]))
                {
                    matches.Add(i);
                }
            }
            matches.TrimToSize();
            return(ViewSelection(matches.ToArray()));
        }
Beispiel #3
0
 /// <summary>
 /// Applies a procedure to each cell's value.
 /// Iterates downwards from <i>[Rows-1,Columns-1]</i> to <i>[0,0]</i>,
 /// as demonstrated by this snippet:
 /// <pre>
 /// for (int row=Rows; --row >=0;) {
 ///    for (int column=Columns; --column >= 0;) {
 ///        if (!procedure(getQuick(row,column))) return false;
 ///    }
 /// }
 /// return true;
 /// </pre>
 /// Note that an implementation may use more efficient techniques, but must not use any other order.
 /// </summary>
 /// <param name="procedure">a procedure object taking as argument the current cell's valued 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>
 private Boolean XforEach(Cern.Colt.Function.ObjectProcedure <Object> procedure)
 {
     for (int row = Rows; --row >= 0;)
     {
         for (int column = Columns; --column >= 0;)
         {
             if (!procedure(this[row, column]))
             {
                 return(false);
             }
         }
     }
     return(true);
 }