// Path: src/main/java/ro/hasna/ts/math/exception/ArrayLengthIsTooSmallException.java
// public class ArrayLengthIsTooSmallException extends NumberIsTooSmallException {
//     private static final long serialVersionUID = -2633584088507009304L;
// 
//     /**
//      * Construct the exception.
//      *
//      * @param wrong          Value that is smaller than the minimum.
//      * @param min            Minimum.
//      * @param boundIsAllowed Whether {@code min} is included in the allowed range.
//      */
//     public ArrayLengthIsTooSmallException(Number wrong, Number min, boolean boundIsAllowed) {
//         super(wrong, min, boundIsAllowed);
//     }
// 
//     /**
//      * Construct the exception with a specific context.
//      *
//      * @param specific       Specific context pattern.
//      * @param wrong          Value that is smaller than the minimum.
//      * @param min            Minimum.
//      * @param boundIsAllowed Whether {@code min} is included in the allowed range.
//      */
//     public ArrayLengthIsTooSmallException(Localizable specific, Number wrong, Number min, boolean boundIsAllowed) {
//         super(specific, wrong, min, boundIsAllowed);
//     }
// }
// 
// Path: src/main/java/ro/hasna/ts/math/exception/CancellationException.java
// public class CancellationException extends MathIllegalStateException {
//     private static final long serialVersionUID = 8488577710717564366L;
// 
//     public CancellationException() {
//         super(LocalizableMessages.OPERATION_WAS_CANCELLED);
//     }
// }
// 
// Path: src/main/java/ro/hasna/ts/math/representation/GenericTransformer.java
// public interface GenericTransformer<I, O> extends Serializable {
//     /**
//      * Transform the input vector from type I into type O.
//      *
//      * @param input the input vector
//      * @return the output vector
//      */
//     O transform(I input);
// }
// 
// Path: src/main/java/ro/hasna/ts/math/type/MatrixProfile.java
// @Data
// public class MatrixProfile implements Cloneable {
//     private final double[] profile;
//     private final int[] indexProfile;
// 
//     public MatrixProfile(double[] profile, int[] indexProfile) {
//         if (profile.length != indexProfile.length) {
//             throw new DimensionMismatchException(profile.length, indexProfile.length);
//         }
// 
//         this.profile = profile;
//         this.indexProfile = indexProfile;
//     }
// 
//     public MatrixProfile(int size) {
//         profile = new double[size];
//         indexProfile = new int[size];
//         for (int j = 0; j < size; j++) {
//             profile[j] = Double.POSITIVE_INFINITY;
//             indexProfile[j] = -1;
//         }
//     }
// 
//     @Override
//     public MatrixProfile clone() {
//         int size = profile.length;
//         MatrixProfile copy = new MatrixProfile(size);
//         for (int i = 0; i < size; i++) {
//             copy.profile[i] = profile[i];
//             copy.indexProfile[i] = indexProfile[i];
//         }
//         return copy;
//     }
// }


import org.apache.commons.math3.exception.NumberIsTooSmallException;
import org.apache.commons.math3.util.FastMath;
import ro.hasna.ts.math.exception.ArrayLengthIsTooSmallException;
import ro.hasna.ts.math.exception.CancellationException;
import ro.hasna.ts.math.representation.GenericTransformer;
import ro.hasna.ts.math.type.MatrixProfile;
import java.util.function.Predicate;
        for (int i = 0; i < profile.length; i++) {
            profile[i] = FastMath.sqrt(profile[i]);
        }
    }

    protected void updateMatrixProfileFromDistanceProfile(double[] distanceProfile, int i, int skip, int n, MatrixProfile mp, Predicate<MatrixProfile> callback) {
        for (int j = i + skip; j < n; j++) {
            // update horizontal line from upper triangle
            if (mp.getProfile()[j] > distanceProfile[j]) {
                mp.getProfile()[j] = distanceProfile[j];
                mp.getIndexProfile()[j] = i;
            }
            // update vertical line i from matrix profile
            if (mp.getProfile()[i] > distanceProfile[j]) {
                mp.getProfile()[i] = distanceProfile[j];
                mp.getIndexProfile()[i] = j;
            }
        }

        executeCallback(callback, mp);
    }

    protected void executeCallback(Predicate<MatrixProfile> callback, MatrixProfile mp) {
        if (callback == null) {
            return;
        }

        MatrixProfile clone = mp.clone();
        updateMatrixProfileWithSqrt(clone);
        if (!callback.test(clone)) {
// Path: src/main/java/ro/hasna/ts/math/exception/ArrayLengthIsTooSmallException.java
// public class ArrayLengthIsTooSmallException extends NumberIsTooSmallException {
//     private static final long serialVersionUID = -2633584088507009304L;
// 
//     /**
//      * Construct the exception.
//      *
//      * @param wrong          Value that is smaller than the minimum.
//      * @param min            Minimum.
//      * @param boundIsAllowed Whether {@code min} is included in the allowed range.
//      */
//     public ArrayLengthIsTooSmallException(Number wrong, Number min, boolean boundIsAllowed) {
//         super(wrong, min, boundIsAllowed);
//     }
// 
//     /**
//      * Construct the exception with a specific context.
//      *
//      * @param specific       Specific context pattern.
//      * @param wrong          Value that is smaller than the minimum.
//      * @param min            Minimum.
//      * @param boundIsAllowed Whether {@code min} is included in the allowed range.
//      */
//     public ArrayLengthIsTooSmallException(Localizable specific, Number wrong, Number min, boolean boundIsAllowed) {
//         super(specific, wrong, min, boundIsAllowed);
//     }
// }
// 
// Path: src/main/java/ro/hasna/ts/math/exception/CancellationException.java
// public class CancellationException extends MathIllegalStateException {
//     private static final long serialVersionUID = 8488577710717564366L;
// 
//     public CancellationException() {
//         super(LocalizableMessages.OPERATION_WAS_CANCELLED);
//     }
// }
// 
// Path: src/main/java/ro/hasna/ts/math/representation/GenericTransformer.java
// public interface GenericTransformer<I, O> extends Serializable {
//     /**
//      * Transform the input vector from type I into type O.
//      *
//      * @param input the input vector
//      * @return the output vector
//      */
//     O transform(I input);
// }
// 
// Path: src/main/java/ro/hasna/ts/math/type/MatrixProfile.java
// @Data
// public class MatrixProfile implements Cloneable {
//     private final double[] profile;
//     private final int[] indexProfile;
// 
//     public MatrixProfile(double[] profile, int[] indexProfile) {
//         if (profile.length != indexProfile.length) {
//             throw new DimensionMismatchException(profile.length, indexProfile.length);
//         }
// 
//         this.profile = profile;
//         this.indexProfile = indexProfile;
//     }
// 
//     public MatrixProfile(int size) {
//         profile = new double[size];
//         indexProfile = new int[size];
//         for (int j = 0; j < size; j++) {
//             profile[j] = Double.POSITIVE_INFINITY;
//             indexProfile[j] = -1;
//         }
//     }
// 
//     @Override
//     public MatrixProfile clone() {
//         int size = profile.length;
//         MatrixProfile copy = new MatrixProfile(size);
//         for (int i = 0; i < size; i++) {
//             copy.profile[i] = profile[i];
//             copy.indexProfile[i] = indexProfile[i];
//         }
//         return copy;
//     }
// }


// Path: src/main/java/ro/hasna/ts/math/representation/mp/SelfJoinAbstractMatrixProfileTransformer.java
import org.apache.commons.math3.exception.NumberIsTooSmallException;
import org.apache.commons.math3.util.FastMath;
import ro.hasna.ts.math.exception.ArrayLengthIsTooSmallException;
import ro.hasna.ts.math.exception.CancellationException;
import ro.hasna.ts.math.representation.GenericTransformer;
import ro.hasna.ts.math.type.MatrixProfile;
import java.util.function.Predicate;

        for (int i = 0; i < profile.length; i++) {
            profile[i] = FastMath.sqrt(profile[i]);
        }
    }

    protected void updateMatrixProfileFromDistanceProfile(double[] distanceProfile, int i, int skip, int n, MatrixProfile mp, Predicate<MatrixProfile> callback) {
        for (int j = i + skip; j < n; j++) {
            // update horizontal line from upper triangle
            if (mp.getProfile()[j] > distanceProfile[j]) {
                mp.getProfile()[j] = distanceProfile[j];
                mp.getIndexProfile()[j] = i;
            }
            // update vertical line i from matrix profile
            if (mp.getProfile()[i] > distanceProfile[j]) {
                mp.getProfile()[i] = distanceProfile[j];
                mp.getIndexProfile()[i] = j;
            }
        }

        executeCallback(callback, mp);
    }

    protected void executeCallback(Predicate<MatrixProfile> callback, MatrixProfile mp) {
        if (callback == null) {
            return;
        }

        MatrixProfile clone = mp.clone();
        updateMatrixProfileWithSqrt(clone);
        if (!callback.test(clone)) {
            throw new CancellationException();