{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Basic core" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This module contains all the basic functions we need in other modules of the fastai library (split with [`torch_core`](/torch_core.html#torch_core) that contains the ones requiring pytorch). Its documentation can easily be skipped at a first read, unless you want to know what a given function does." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [], "source": [ "from fastai.gen_doc.nbdoc import *\n", "from fastai.core import * " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Global constants" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`default_cpus = min(16, num_cpus())`
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Check functions" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/markdown": [ "ifnone[source]ifnone(`a`:`Any`, `b`:`Any`) → `Any`\n",
"\n",
"`a` if `a` is not None, otherwise `b`. "
],
"text/plain": [
"is_listy[source]is_listy(`x`:`Any`) → `bool`"
],
"text/plain": [
"is_tuple[source]is_tuple(`x`:`Any`) → `bool`"
],
"text/plain": [
"arrays_split[source]arrays_split(`mask`:`ndarray`, `arrs`:`NPArrayableList`) → `SplitArrayList`\n",
"\n",
"Given `arrs` is [a,b,...] and `mask`index - return[(a[mask],a[~mask]),(b[mask],b[~mask]),...]. "
],
"text/plain": [
"extract_kwargs[source]extract_kwargs(`names`:`StrList`, `kwargs`:`KWArgs`)\n",
"\n",
"Extract the keys in `names` from the `kwargs`. "
],
"text/plain": [
"get_chunk_length[source]get_chunk_length(`data`:`Union`\\[`Path`, `str`, `DataFrame`, `TextFileReader`\\], `chunksize`:`Optional`\\[`int`\\]=`None`) → `int`"
],
"text/plain": [
"get_total_length[source]get_total_length(`csv_name`:`PathOrStr`, `chunksize`:`int`) → `int`"
],
"text/plain": [
"idx_dict[source]idx_dict(`a`)"
],
"text/plain": [
"listify[source]listify(`p`:`OptListOrItem`=`None`, `q`:`OptListOrItem`=`None`)\n",
"\n",
"Make `p` same length as `q` "
],
"text/plain": [
"random_split[source]random_split(`valid_pct`:`float`, `arrs`:`NPArrayableList`) → `SplitArrayList`\n",
"\n",
"Randomly split `arrs` with `valid_pct` ratio. good for creating validation set. "
],
"text/plain": [
"series2cat[source]series2cat(`df`:`DataFrame`, `col_names`)\n",
"\n",
"Categorifies the columns `col_names` in `df`. "
],
"text/plain": [
"uniqueify[source]uniqueify(`x`:`Series`) → `List`\n",
"\n",
"Return unique values of `x` "
],
"text/plain": [
"download_url[source]download_url(`url`:`str`, `dest`:`str`, `overwrite`:`bool`=`False`, `pbar`:`ProgressBar`=`None`, `show_progress`=`True`)\n",
"\n",
"Download `url` to `dest` unless it exists and not `overwrite`. "
],
"text/plain": [
"find_classes[source]find_classes(`folder`:`Path`) → `FilePathList`\n",
"\n",
"List of label subdirectories in imagenet-style `folder`. "
],
"text/plain": [
"join_path[source]join_path(`fname`:`PathOrStr`, `path`:`PathOrStr`=`'.'`) → `Path`\n",
"\n",
"Return `Path(path)/Path(fname)`, `path` defaults to current dir. "
],
"text/plain": [
"join_paths[source]join_paths(`fnames`:`FilePathList`, `path`:`PathOrStr`=`'.'`) → `FilePathList`\n",
"\n",
"Join `path` to every file name in `fnames`. "
],
"text/plain": [
"loadtxt_str[source]loadtxt_str(`path`:`PathOrStr`) → `ndarray`\n",
"\n",
"Return `ndarray` of `str` of lines of text from `path`. "
],
"text/plain": [
"maybe_copy[source]maybe_copy(`old_fnames`:`Collection`\\[`PathOrStr`\\], `new_fnames`:`Collection`\\[`PathOrStr`\\])\n",
"\n",
"Copy the `old_fnames` to `new_fnames` location if `new_fnames` don't exist or are less recent. "
],
"text/plain": [
"class ItemBase[source]ItemBase()\n",
"\n",
"All transformable dataset items use this type. "
],
"text/plain": [
"camel2snake[source]camel2snake(`name`:`str`) → `str`"
],
"text/plain": [
"even_mults[source]even_mults(`start`:`float`, `stop`:`float`, `n`:`int`) → `ndarray`\n",
"\n",
"Build evenly stepped schedule from `start` to `stop` in `n` steps. "
],
"text/plain": [
"noop[source]noop(`x`)"
],
"text/plain": [
"num_cpus[source]num_cpus() → `int`\n",
"\n",
"Get number of cpus "
],
"text/plain": [
"partition[source]partition(`a`:`Collection`, `sz`:`int`) → `List`\\[`Collection`\\]\n",
"\n",
"Split iterables `a` in equal parts of size `sz` "
],
"text/plain": [
"partition_by_cores[source]partition_by_cores(`a`:`Collection`, `n_cpus`:`int`) → `List`\\[`Collection`\\]\n",
"\n",
"Split data in `a` equally among `n_cpus` cores "
],
"text/plain": [
"range_of[source]range_of(`x`)"
],
"text/plain": [
"to_int[source]to_int(`b`:`Any`) → `Union`\\[`int`, `List`\\[`int`\\]\\]\n",
"\n",
"Convert `b` to an int or list of ints (if [`is_listy`](/core.html#is_listy)); raises exception if not convertible "
],
"text/plain": [
"arange_of[source]arange_of(`x`)"
],
"text/plain": [
"