maxloc method

int maxloc(
  1. int start,
  2. int end, {
  3. int dim = 1,
})

Implementation

int maxloc(int start, int end, {int dim = 1}) {
  switch (T) {
    case const (double):
    case const (int):
      int loc = start;
      var value = this[start] as num;
      for (var i = start + 1; i <= end; i++) {
        if (value < (this[i] as num)) {
          value = this[i] as num;
          loc = i;
        }
      }
      return loc - start + 1;

    case const (Complex):
      int loc = start;
      Complex value = this[start] as Complex;
      for (var i = start + 1; i <= end; i++) {
        if (value < (this[i] as Complex)) {
          value = this[i] as Complex;
          loc = i;
        }
      }
      return loc - start + 1;

    case const (bool):
      for (var i = start; i <= end; i++) {
        if (this[start] as bool) return i - start + 1;
      }
      return 0;
    default:
      throw UnimplementedError();
  }
}