package org.nd4j.linalg.indexing;

import com.google.common.base.Function;
import org.nd4j.linalg.api.complex.IComplexNDArray;
import org.nd4j.linalg.api.complex.IComplexNumber;
import org.nd4j.linalg.api.ndarray.INDArray;

/**
 * Boolean indexing
 * @author Adam Gibson
 */
public class BooleanIndexing {


    /**
     * Based on the matching elements
     * transform to based on condition to with function function
     * @param to the ndarray to transform
     * @param condition  the condition on transform
     * @param function the function to apply the transform to
     */
    public static void applyWhere(INDArray to,Condition condition,Function<Number,Number> function) {
        INDArray linear = to.linearView();
        for(int i = 0; i < linear.linearView().length(); i++) {
            if(condition.apply(linear.get(i))) {
                linear.putScalar(i,function.apply(linear.get(i)));
            }
        }
    }


    /**
     * Based on the matching elements
     * transform to based on condition to with function function
     * @param to the ndarray to transform
     * @param condition  the condition on transform
     * @param function the function to apply the transform to
     */
    public static void applyWhere(IComplexNDArray to,Condition condition,Function<IComplexNumber,IComplexNumber> function) {
        IComplexNDArray linear = to.linearView();
        for(int i = 0; i < linear.linearView().length(); i++) {
            if(condition.apply(linear.get(i))) {
                linear.putScalar(i,function.apply(linear.getComplex(i)));
            }
        }
    }



}

@@ -299,16 +299,1573 @@
 exing %7B%0A
+    /**%0A     * And%0A     * @param n%0A     * @param cond%0A     * @return%0A     */%0A    public static boolean and(IComplexNDArray n,Condition cond) %7B%0A        boolean ret = true;%0A        IComplexNDArray linear = n.linearView();%0A        for(int i = 0; i %3C linear.length(); i++) %7B%0A            ret = ret && cond.apply(linear.getComplex(i));%0A        %7D%0A%0A        return ret;%0A    %7D%0A%0A    /**%0A     * Or over the whole ndarray given some condition%0A     * @param n%0A     * @param cond%0A     * @return%0A     */%0A    public static boolean or(IComplexNDArray n,Condition cond) %7B%0A        boolean ret = true;%0A        IComplexNDArray linear = n.linearView();%0A        for(int i = 0; i %3C linear.length(); i++) %7B%0A            ret = ret %7C%7C cond.apply(linear.getComplex(i));%0A        %7D%0A%0A        return ret;%0A    %7D%0A%0A%0A    /**%0A     * And over the whole ndarray given some condition%0A     * @param n%0A     * @param cond%0A     * @return%0A     */%0A    public static boolean and(INDArray n,Condition cond) %7B%0A        boolean ret = true;%0A        INDArray linear = n.linearView();%0A        for(int i = 0; i %3C linear.length(); i++) %7B%0A            ret = ret && cond.apply(linear.get(i));%0A        %7D%0A%0A        return ret;%0A    %7D%0A%0A    /**%0A     * Or over the whole ndarray given some condition%0A     * @param n%0A     * @param cond%0A     * @return%0A     */%0A    public static boolean or(INDArray n,Condition cond) %7B%0A        boolean ret = true;%0A        INDArray linear = n.linearView();%0A        for(int i = 0; i %3C linear.length(); i++) %7B%0A            ret = ret %7C%7C cond.apply(linear.get(i));%0A        %7D%0A%0A        return ret;%0A    %7D
 %0A%0A    /*

add condition evaluation