Translates @first @last @1 @-1 expressions into an actual array index.

    :param str array_path: Array path in XJ notation.
    :rtype: int
    :return: Array index.
10524
def _get_array_index(array_path):
    

    if not array_path.startswith('@'):
        raise XJPathError('Array index must start from @ symbol.')
    array_path = array_path[1:]
    if array_path == 'last':
        return -1
    if array_path == 'first':
        return 0
    if array_path.isdigit() or (array_path.startswith('-')
                                and array_path[1:].isdigit()):
        return int(array_path)
    else:
        raise XJPathError('Unknown index reference', (array_path,))
498312
def from_array(array):
        
        if array is None or not array:
            return None
        # end if
        assert_type_or_raise(array, dict, parameter_name="array")

        data = {}
        data['url'] = u(array.get('url'))
        data['has_custom_certificate'] = bool(array.get('has_custom_certificate'))
        data['pending_update_count'] = int(array.get('pending_update_count'))
        data['last_error_date'] = int(array.get('last_error_date')) if array.get('last_error_date') is not None else None
        data['last_error_message'] = u(array.get('last_error_message')) if array.get('last_error_message') is not None else None
        data['max_connections'] = int(array.get('max_connections')) if array.get('max_connections') is not None else None
        data['allowed_updates'] = WebhookInfo._builtin_from_array_list(required_type=unicode_type, value=array.get('allowed_updates'), list_level=1) if array.get('allowed_updates') is not None else None
        data['_raw'] = array
        return WebhookInfo(**data)
334867
function arrayIndexOf(arr, search, fromIndex, fromRight) {
  var length = arr.length, defaultFromIndex, index, increment;

  increment = fromRight ? -1 : 1;
  defaultFromIndex = fromRight ? length - 1 : 0;
  fromIndex = trunc(fromIndex);
  if (!fromIndex && fromIndex !== 0) {
    fromIndex = defaultFromIndex;
  }
  if (fromIndex < 0) {
    fromIndex = length + fromIndex;
  }
  if ((!fromRight && fromIndex < 0) || (fromRight && fromIndex >= length)) {
    fromIndex = defaultFromIndex;
  }

  index = fromIndex;

  while((fromRight && index >= 0) || (!fromRight && index < length)) {
    if (!(index in arr)) {
      return sparseIndexOf(arr, search, fromIndex, fromRight);
    }
    if (isArrayIndex(index) && arr[index] === search) {
      return index;
    }
    index += increment;
  }
  return -1;
}
851630
def array_to_indices_hash(array)
    array.inject({}) {|hash,e|  hash[hash.size] = e; hash }
  end
524214
def array_to_ranges(ar)
      prev = ar[0]

      ranges = ar.slice_before do |e|
        prev2 = prev
        prev = e
        prev2 + 1 != e
      end.map { |a| a[0]..a[-1] }

      ranges
    end
331671
def next(self) -> "ArrayEntry":
        
        try:
            newval, naft = self.after.pop()
        except IndexError:
            raise NonexistentInstance(self.json_pointer(), "next of last") from None
        return ArrayEntry(
            self.index + 1, self.before.cons(self.value), naft, newval,
            self.parinst, self.schema_node, self.timestamp)
1324590
def split(path)
      parts = []
      last_index = 0
      while index = path.index("/", last_index)
        if index == last_index
          parts << ""
        else
          parts << path[last_index...index]
        end
        last_index = index + 1
      end
      # and also get that last segment
      parts << path[last_index..-1]
      # it should begin with a blank segment from the leading "/"; kill that
      parts.shift
      parts
    end
1243504
def LastOf(*subcons):
    
    name = "seq"
    if isinstance(subcons[0], six.string_types):
        name = subcons[0]
        subcons = subcons[1:]
    return IndexingAdapter(Sequence(name, *subcons), -1)
1303117
def _first_and_last_element(arr):
    """"""
    if isinstance(arr, np.ndarray) or hasattr(arr, 'data'):
        # numpy array or sparse matrix with .data attribute
        data = arr.data if sparse.issparse(arr) else arr
        return data.flat[0], data.flat[-1]
    else:
        # Sparse matrices without .data attribute. Only dok_matrix at
        # the time of writing, in this case indexing is fast
        return arr[0, 0], arr[-1, -1]
892408
public static function getByPath($array, $path = self::PATH_ROOT)
    {
        $path = trim($path);
        if (! $path || $path == self::PATH_ROOT) {
            return $array;
        }
        // fix the path in case it was provided as `[item][subitem]`
        if (strpos($path, '[') === 0) {
            $path = preg_replace('/]/', '', ltrim($path, '['), 1);
        }

        list($container, $subpath) = self::getSelectorParts($path);
        if ($subpath === '') {
            return array_key_exists($container, $array) ? $array[$container] : null;
        }

        return array_key_exists($container, $array) ? self::getByPath($array[$container], $subpath) : null;
    }
601726
function makePath(object, path, index) {
		index = index || 0;
		var obj;

		if (path.length > index + 1) {
			obj = object[path[index]];

			// we always want the last object in an array
			if (_.isArray(obj)) obj = _.last(obj);

			makePath(obj, path, index + 1);
		} else {
			obj = object[path[index]];

			if (!obj) {
				// object doesn't exist yet so make it
				object[path[index]] = {};
			} else {
				if (!_.isArray(obj)) {
					// object isn't an array yet so make an array with the object as the first element
					object[path[index]] = [obj];
				}

				// append the new object
				object[path[index]].push({});
			}
		}
	}
656549
def _single_array_element(data_obj, xj_path, array_path, create_dict_path):
    

    val_type, array_path = _clean_key_type(array_path)
    array_idx = _get_array_index(array_path)
    if data_obj and isinstance(data_obj, (list, tuple)):
        try:
            value = data_obj[array_idx]
            if val_type is not None and not isinstance(value, val_type):
                raise XJPathError('Index array "%s" of "%s" type does not '
                                  'match expected type "%s"' %
                                  (array_idx, type(value).__name__,
                                   val_type.__name__))

            if xj_path:
                return path_lookup(value, xj_path, create_dict_path)
            else:
                return value, True
        except IndexError:
            return None, False
    else:
        if val_type is not None:
            raise XJPathError('Expected the list element type, but "%s" found' %
                              type(data_obj).__name__)
        return None, False
274203
function cidArray (path) {
  if (path[path.length - 1] === '/') {
    path = path.substring(0, path.length - 1)
  }
  // skip /ipxs/ prefix
  if (path.match(/^\/ip[fn]s\//)) {
    path = path.substring(6)
  }
  // skip ipxs:// protocol
  if (path.match(/^ip[fn]s:\/\//)) {
    path = path.substring(7)
  }
  return path.split('/')
}
352735
def array_default_value(type_, values):
        
        if not isinstance(values, list):
            return Translator.default_value(type_, values)

        l = []
        for row in values:
            l.extend(Translator.array_default_value(type_, row))

        return l
1042991
public static void getTokens(List<String> list, String path) {
        int start = -1, length = path.length(), state = STATE_INITIAL;
        char ch;
        for (int index = 0; index < length; index++) {
            ch = path.charAt(index);
            switch (ch) {
                case '/':
                case '\\': {
                    switch (state) {
                        case STATE_INITIAL: {
                            // skip extra leading /
                            continue;
                        }
                        case STATE_MAYBE_CURRENT_PATH: {
                            // it's '.'
                            list.add(CURRENT_PATH);
                            state = STATE_INITIAL;
                            continue;
                        }
                        case STATE_MAYBE_REVERSE_PATH: {
                            // it's '..'
                            list.add(REVERSE_PATH);
                            state = STATE_INITIAL;
                            continue;
                        }
                        case STATE_NORMAL: {
                            // it's just a normal path segment
                            list.add(path.substring(start, index));
                            state = STATE_INITIAL;
                            continue;
                        }
                    }
                    continue;
                }
                case '.': {
                    switch (state) {
                        case STATE_INITIAL: {
                            // . is the first char; might be a special token
                            state = STATE_MAYBE_CURRENT_PATH;
                            start = index;
                            continue;
                        }
                        case STATE_MAYBE_CURRENT_PATH: {
                            // the second . in a row...
                            state = STATE_MAYBE_REVERSE_PATH;
                            continue;
                        }
                        case STATE_MAYBE_REVERSE_PATH: {
                            // the third . in a row, guess it's just a weird path name
                            state = STATE_NORMAL;
                            continue;
                        }
                    }
                    continue;
                }
                default: {
                    switch (state) {
                        case STATE_INITIAL: {
                            state = STATE_NORMAL;
                            start = index;
                            continue;
                        }
                        case STATE_MAYBE_CURRENT_PATH:
                        case STATE_MAYBE_REVERSE_PATH: {
                            state = STATE_NORMAL;
                        }
                    }
                }
            }
        }
        // handle the last token
        switch (state) {
            case STATE_INITIAL: {
                // trailing /
                break;
            }
            case STATE_MAYBE_CURRENT_PATH: {
                list.add(CURRENT_PATH);
                break;
            }
            case STATE_MAYBE_REVERSE_PATH: {
                list.add(REVERSE_PATH);
                break;
            }
            case STATE_NORMAL: {
                list.add(path.substring(start));
                break;
            }
        }
        return;
    }
118379
static function arrayGetByPath($array, $path) {
        list($container, $subpath) = self::getSelectorParts($path);
        if ($subpath === '') {
            return array_key_exists($container, $array) ? $array[$container] : null;
        }
        return array_key_exists($container, $array) ? self::arrayGetByPath($array[$container], $subpath) : null;
    }
625642
def csv_to_num_matrix(csv_file_path):
    
    mtx = []
    with open(csv_file_path) as csv_data_file:
        for row in csv_data_file:
            mtx.append([float(val) for val in row.split(',')])
    return mtx