<commit_before>package com.lfscheidegger.jfacet.shade;

import com.google.common.collect.ImmutableList;
import com.lfscheidegger.jfacet.shade.expression.Expression;
import com.lfscheidegger.jfacet.shade.expression.evaluators.FunctionEvaluator;
import com.lfscheidegger.jfacet.shade.expression.FloatExp;
import com.lfscheidegger.jfacet.shade.expression.Vec2Exp;
import com.lfscheidegger.jfacet.shade.expression.Vec3Exp;
import com.lfscheidegger.jfacet.shade.expression.Vec4Exp;
import com.lfscheidegger.jfacet.shade.primitives.Vec2;
import com.lfscheidegger.jfacet.shade.primitives.Vec3;
import com.lfscheidegger.jfacet.shade.primitives.Vec4;

public class Math {

  public static FloatExp sqrt(FloatExp param) {
    return new FloatExp(ImmutableList.<Expression>of(param), new FunctionEvaluator<Float>(Type.FLOAT_T, "sqrt") {
          @Override
          public Float evaluate(Expression expression) {
            FloatExp parent = (FloatExp)expression.getParents().get(0);
            return (float)java.lang.Math.sqrt(parent.evaluate());
          }
        });
  }

  public static FloatExp sin(FloatExp param) {
    return new FloatExp(ImmutableList.<Expression>of(param), new FunctionEvaluator<Float>(Type.FLOAT_T, "sin") {
          @Override
          public Float evaluate(Expression expression) {
            FloatExp parent = (FloatExp)expression.getParents().get(0);
            return (float)java.lang.Math.sin(parent.evaluate());
          }
        });
  }

  public static FloatExp cos(FloatExp param) {
    return new FloatExp(ImmutableList.<Expression>of(param), new FunctionEvaluator<Float>(Type.FLOAT_T, "cos") {
          @Override
          public Float evaluate(Expression expression) {
            FloatExp parent = (FloatExp)expression.getParents().get(0);
            return (float)java.lang.Math.cos(parent.evaluate());
          }
        });
  }

  public static FloatExp radians(FloatExp param) {
    return param.mul((float)(java.lang.Math.PI / 180.0));
  }

  public static Vec2Exp normalize(Vec2Exp vec) {
    return new Vec2Exp(ImmutableList.<Expression>of(vec), new FunctionEvaluator<Vec2>(Type.VEC2_T, "normalize") {
          @Override
          public Vec2 evaluate(Expression expression) {
            Vec2Exp parent = (Vec2Exp)expression.getParents().get(0);
            float norm = (float)java.lang.Math.sqrt(
                parent.getX().evaluate() * parent.getX().evaluate() +
                    parent.getY().evaluate() * parent.getY().evaluate());
            return parent.evaluate().div(norm);
          }
        });
  }

  public static Vec3Exp normalize(Vec3Exp vec) {
    return new Vec3Exp(ImmutableList.<Expression>of(vec), new FunctionEvaluator<Vec3>(Type.VEC3_T, "normalize") {
          @Override
          public Vec3 evaluate(Expression expression) {
            Vec3Exp parent = (Vec3Exp)expression.getParents().get(0);
            float norm = (float)java.lang.Math.sqrt(
                parent.getX().evaluate() * parent.getX().evaluate() +
                parent.getY().evaluate() * parent.getY().evaluate() +
                parent.getZ().evaluate() * parent.getZ().evaluate());
            return parent.evaluate().div(norm);
          }
        });
  }

  public static Vec4Exp normalize(Vec4Exp vec) {
    return new Vec4Exp(ImmutableList.<Expression>of(vec), new FunctionEvaluator<Vec4>(Type.VEC4_T, "normalize") {
          @Override
          public Vec4 evaluate(Expression expression) {
            Vec4Exp parent = (Vec4Exp)expression.getParents().get(0);
            float norm = (float)java.lang.Math.sqrt(
                parent.getX().evaluate() * parent.getX().evaluate() +
                parent.getY().evaluate() * parent.getY().evaluate() +
                parent.getZ().evaluate() * parent.getZ().evaluate() +
                parent.getW().evaluate() * parent.getW().evaluate());
            return parent.evaluate().div(norm);
          }
        });
  }

  public static FloatExp dot(Vec2Exp left, Vec2Exp right) {
    return new FloatExp(ImmutableList.<Expression>of(left, right), new FunctionEvaluator<Float>(Type.FLOAT_T, "dot") {
      @Override
      public Float evaluate(Expression expression) {
        Vec2Exp left = (Vec2Exp)expression.getParents().get(0);
        Vec2Exp right = (Vec2Exp)expression.getParents().get(1);

        return left.evaluate().dot(right.evaluate());
      }
    });
  }

  public static FloatExp dot(Vec3Exp left, Vec3Exp right) {
    return new FloatExp(ImmutableList.<Expression>of(left, right), new FunctionEvaluator<Float>(Type.FLOAT_T, "dot") {
      @Override
      public Float evaluate(Expression expression) {
        Vec3Exp left = (Vec3Exp)expression.getParents().get(0);
        Vec3Exp right = (Vec3Exp)expression.getParents().get(1);

        return left.evaluate().dot(right.evaluate());
      }
    });
  }

  public static FloatExp dot(Vec4Exp left, Vec4Exp right) {
    return new FloatExp(ImmutableList.<Expression>of(left, right), new FunctionEvaluator<Float>(Type.FLOAT_T, "dot") {
      @Override
      public Float evaluate(Expression expression) {
        Vec4Exp left = (Vec4Exp)expression.getParents().get(0);
        Vec4Exp right = (Vec4Exp)expression.getParents().get(1);

        return left.evaluate().dot(right.evaluate());
      }
    });
  }

  public static Vec3Exp cross(Vec3Exp left, Vec3Exp right) {
    return new Vec3Exp(ImmutableList.<Expression>of(left, right), new FunctionEvaluator<Vec3>(Type.VEC3_T, "cross") {
      @Override
      public Vec3 evaluate(Expression expression) {
        Vec3Exp left = (Vec3Exp)expression.getParents().get(0);
        Vec3Exp right = (Vec3Exp)expression.getParents().get(1);
        return left.evaluate().cross(right.evaluate());
      }
    });
  }
}
<commit_msg>determinant, inverse, and transpose for expressions<commit_after>package com.lfscheidegger.jfacet.shade;

import com.google.common.collect.ImmutableList;
import com.lfscheidegger.jfacet.shade.expression.*;
import com.lfscheidegger.jfacet.shade.expression.evaluators.FunctionEvaluator;
import com.lfscheidegger.jfacet.shade.primitives.*;

public class Math {

  public static FloatExp sqrt(FloatExp param) {
    return new FloatExp(ImmutableList.<Expression>of(param), new FunctionEvaluator<Float>(Type.FLOAT_T, "sqrt") {
          @Override
          public Float evaluate(Expression expression) {
            FloatExp parent = (FloatExp)expression.getParents().get(0);
            return (float)java.lang.Math.sqrt(parent.evaluate());
          }
        });
  }

  public static FloatExp sin(FloatExp param) {
    return new FloatExp(ImmutableList.<Expression>of(param), new FunctionEvaluator<Float>(Type.FLOAT_T, "sin") {
          @Override
          public Float evaluate(Expression expression) {
            FloatExp parent = (FloatExp)expression.getParents().get(0);
            return (float)java.lang.Math.sin(parent.evaluate());
          }
        });
  }

  public static FloatExp cos(FloatExp param) {
    return new FloatExp(ImmutableList.<Expression>of(param), new FunctionEvaluator<Float>(Type.FLOAT_T, "cos") {
          @Override
          public Float evaluate(Expression expression) {
            FloatExp parent = (FloatExp)expression.getParents().get(0);
            return (float)java.lang.Math.cos(parent.evaluate());
          }
        });
  }

  public static FloatExp radians(FloatExp param) {
    return param.mul((float)(java.lang.Math.PI / 180.0));
  }

  public static Vec2Exp normalize(Vec2Exp vec) {
    return new Vec2Exp(ImmutableList.<Expression>of(vec), new FunctionEvaluator<Vec2>(Type.VEC2_T, "normalize") {
          @Override
          public Vec2 evaluate(Expression expression) {
            Vec2Exp parent = (Vec2Exp)expression.getParents().get(0);
            float norm = (float)java.lang.Math.sqrt(
                parent.getX().evaluate() * parent.getX().evaluate() +
                    parent.getY().evaluate() * parent.getY().evaluate());
            return parent.evaluate().div(norm);
          }
        });
  }

  public static Vec3Exp normalize(Vec3Exp vec) {
    return new Vec3Exp(ImmutableList.<Expression>of(vec), new FunctionEvaluator<Vec3>(Type.VEC3_T, "normalize") {
          @Override
          public Vec3 evaluate(Expression expression) {
            Vec3Exp parent = (Vec3Exp)expression.getParents().get(0);
            float norm = (float)java.lang.Math.sqrt(
                parent.getX().evaluate() * parent.getX().evaluate() +
                parent.getY().evaluate() * parent.getY().evaluate() +
                parent.getZ().evaluate() * parent.getZ().evaluate());
            return parent.evaluate().div(norm);
          }
        });
  }

  public static Vec4Exp normalize(Vec4Exp vec) {
    return new Vec4Exp(ImmutableList.<Expression>of(vec), new FunctionEvaluator<Vec4>(Type.VEC4_T, "normalize") {
          @Override
          public Vec4 evaluate(Expression expression) {
            Vec4Exp parent = (Vec4Exp)expression.getParents().get(0);
            float norm = (float)java.lang.Math.sqrt(
                parent.getX().evaluate() * parent.getX().evaluate() +
                parent.getY().evaluate() * parent.getY().evaluate() +
                parent.getZ().evaluate() * parent.getZ().evaluate() +
                parent.getW().evaluate() * parent.getW().evaluate());
            return parent.evaluate().div(norm);
          }
        });
  }

  public static FloatExp dot(Vec2Exp left, Vec2Exp right) {
    return new FloatExp(ImmutableList.<Expression>of(left, right), new FunctionEvaluator<Float>(Type.FLOAT_T, "dot") {
      @Override
      public Float evaluate(Expression expression) {
        Vec2Exp left = (Vec2Exp)expression.getParents().get(0);
        Vec2Exp right = (Vec2Exp)expression.getParents().get(1);

        return left.evaluate().dot(right.evaluate());
      }
    });
  }

  public static FloatExp dot(Vec3Exp left, Vec3Exp right) {
    return new FloatExp(ImmutableList.<Expression>of(left, right), new FunctionEvaluator<Float>(Type.FLOAT_T, "dot") {
      @Override
      public Float evaluate(Expression expression) {
        Vec3Exp left = (Vec3Exp)expression.getParents().get(0);
        Vec3Exp right = (Vec3Exp)expression.getParents().get(1);

        return left.evaluate().dot(right.evaluate());
      }
    });
  }

  public static FloatExp dot(Vec4Exp left, Vec4Exp right) {
    return new FloatExp(ImmutableList.<Expression>of(left, right), new FunctionEvaluator<Float>(Type.FLOAT_T, "dot") {
      @Override
      public Float evaluate(Expression expression) {
        Vec4Exp left = (Vec4Exp)expression.getParents().get(0);
        Vec4Exp right = (Vec4Exp)expression.getParents().get(1);

        return left.evaluate().dot(right.evaluate());
      }
    });
  }

  public static Vec3Exp cross(Vec3Exp left, Vec3Exp right) {
    return new Vec3Exp(ImmutableList.<Expression>of(left, right), new FunctionEvaluator<Vec3>(Type.VEC3_T, "cross") {
      @Override
      public Vec3 evaluate(Expression expression) {
        Vec3Exp left = (Vec3Exp)expression.getParents().get(0);
        Vec3Exp right = (Vec3Exp)expression.getParents().get(1);
        return left.evaluate().cross(right.evaluate());
      }
    });
  }

  public static FloatExp determinant(Mat2Exp mat) {
    return new FloatExp(ImmutableList.<Expression>of(mat), new FunctionEvaluator<Float>(Type.FLOAT_T, "determinant") {
      @Override
      public Float evaluate(Expression<Float> expression) {
        Mat2Exp parent = (Mat2Exp)expression.getParents().get(0);
        return parent.evaluate().determinant();
      }
    });
  }

  public static FloatExp determinant(Mat3Exp mat) {
    return new FloatExp(ImmutableList.<Expression>of(mat), new FunctionEvaluator<Float>(Type.FLOAT_T, "determinant") {
      @Override
      public Float evaluate(Expression<Float> expression) {
        Mat3Exp parent = (Mat3Exp)expression.getParents().get(0);
        return parent.evaluate().determinant();
      }
    });
  }

  public static FloatExp determinant(Mat4Exp mat) {
    return new FloatExp(ImmutableList.<Expression>of(mat), new FunctionEvaluator<Float>(Type.FLOAT_T, "determinant") {
      @Override
      public Float evaluate(Expression<Float> expression) {
        Mat4Exp parent = (Mat4Exp)expression.getParents().get(0);
        return parent.evaluate().determinant();
      }
    });
  }

  public static Mat2Exp inverse(Mat2Exp mat) {
    return new Mat2Exp(ImmutableList.<Expression>of(mat), new FunctionEvaluator<Mat2>(Type.MAT2_T, "inverse") {
      @Override
      public Mat2 evaluate(Expression<Mat2> expression) {
        Mat2Exp parent = (Mat2Exp)expression.getParents().get(0);
        return parent.evaluate().inverse();
      }
    });
  }

  public static Mat3Exp inverse(Mat3Exp mat) {
    return new Mat3Exp(ImmutableList.<Expression>of(mat), new FunctionEvaluator<Mat3>(Type.MAT3_T, "inverse") {
      @Override
      public Mat3 evaluate(Expression<Mat3> expression) {
        Mat3Exp parent = (Mat3Exp)expression.getParents().get(0);
        return parent.evaluate().inverse();
      }
    });
  }

  public static Mat4Exp inverse(Mat4Exp mat) {
    return new Mat4Exp(ImmutableList.<Expression>of(mat), new FunctionEvaluator<Mat4>(Type.MAT4_T, "inverse") {
      @Override
      public Mat4 evaluate(Expression<Mat4> expression) {
        Mat4Exp parent = (Mat4Exp)expression.getParents().get(0);
        return parent.evaluate().inverse();
      }
    });
  }
  public static Mat2Exp transpose(Mat2Exp mat) {
    return new Mat2Exp(ImmutableList.<Expression>of(mat), new FunctionEvaluator<Mat2>(Type.MAT2_T, "transpose") {
      @Override
      public Mat2 evaluate(Expression<Mat2> expression) {
        Mat2Exp parent = (Mat2Exp)expression.getParents().get(0);
        return parent.evaluate().transpose();
      }
    });
  }

  public static Mat3Exp transpose(Mat3Exp mat) {
    return new Mat3Exp(ImmutableList.<Expression>of(mat), new FunctionEvaluator<Mat3>(Type.MAT3_T, "transpose") {
      @Override
      public Mat3 evaluate(Expression<Mat3> expression) {
        Mat3Exp parent = (Mat3Exp)expression.getParents().get(0);
        return parent.evaluate().transpose();
      }
    });
  }

  public static Mat4Exp transpose(Mat4Exp mat) {
    return new Mat4Exp(ImmutableList.<Expression>of(mat), new FunctionEvaluator<Mat4>(Type.MAT4_T, "transpose") {
      @Override
      public Mat4 evaluate(Expression<Mat4> expression) {
        Mat4Exp parent = (Mat4Exp)expression.getParents().get(0);
        return parent.evaluate().transpose();
      }
    });
  }
}

{'fraction_non_alphanumeric': 0.13095728608707596, 'fraction_numerical': 0.015107814860596072, 'mean_word_length': 3.1301758366420875, 'pattern_counts': {'":': 0, '<': 70, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7140667', 'n_tokens_mistral': 4483, 'n_tokens_neox': 4281, 'n_words': 770}