All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.expleague.commons.math.TransC1 Maven / Gradle / Ivy

Go to download

Utilities including math, charsequence based text processing, sequences etc.

There is a newer version: 1.4.9
Show newest version
package com.expleague.commons.math;

import com.expleague.commons.math.vectors.Mx;
import com.expleague.commons.math.vectors.Vec;
import com.expleague.commons.math.vectors.impl.vectors.ArrayVec;
import com.expleague.commons.math.vectors.impl.mx.VecBasedMx;
import org.jetbrains.annotations.NotNull;

/**
 * User: solar
 * Date: 21.12.2010
 * Time: 22:07:07
 */
public interface TransC1 extends Trans {
  @NotNull
  Trans gradient();
  Vec gradientTo(Vec x, Vec to);
  Vec gradientRowTo(Vec x, Vec to, int index);
  Vec gradient(Vec x);

  abstract class Stub extends Trans.Stub implements TransC1 {
    @Override @NotNull
    public Trans gradient() {
      return new Trans.Stub() {
        @Override
        public Vec transTo(Vec argument, Vec to) {
          return gradientTo(argument, to);
        }

        @Override
        public final int xdim() {
          return TransC1.Stub.this.xdim();
        }

        @Override
        public final int ydim() {
          return xdim();
        }
      };
    }

    public Vec gradientTo(Vec x, Vec to) {
      final int ydim = ydim();
      if (ydim == 0)
        return gradientRowTo(x, to, 0);
      for (int i = 0; i < ydim; i++)
        gradientRowTo(x, ((Mx) to).row(i), i);
      return to;
    }

    @Override
    public Vec gradient(Vec x) {
      final Vec to;
      if (ydim() == 1)
        to = new ArrayVec(xdim());
      else
        to = new VecBasedMx(xdim(), new ArrayVec(x.dim() * ydim()));
      return gradientTo(x, to);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy