{ "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": [ "has_arg
[source]has_arg
(`func`, `arg`) → `bool`"
],
"text/plain": [
"ifnone
[source]ifnone
(`a`:`Any`, `b`:`Any`) → `Any`\n",
"\n",
"`a` if `a` is not None, otherwise `b`. "
],
"text/plain": [
"is1d
[source]is1d
(`a`:`Collection`) → `bool`\n",
"\n",
"Returns True if a collection is one dimensional "
],
"text/plain": [
"is_listy
[source]is_listy
(`x`:`Any`) → `bool`"
],
"text/plain": [
"is_tuple
[source]is_tuple
(`x`:`Any`) → `bool`"
],
"text/plain": [
"try_int
[source]try_int
(`o`:`Any`) → `Any`\n",
"\n",
"Try to conver `o` to int, default to `o` if not possible. "
],
"text/plain": [
"arange_of
[source]arange_of
(`x`)"
],
"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": [
"df_names_to_idx
[source]df_names_to_idx
(`names`:`Union`\\[`int`, `Collection`\\[`int`\\], `str`, `StrList`\\], `df`:`DataFrame`)\n",
"\n",
"Return the column indexes of `names` in `df`. "
],
"text/plain": [
"extract_kwargs
[source]extract_kwargs
(`names`:`StrList`, `kwargs`:`KWArgs`)\n",
"\n",
"Extract the keys in `names` from the `kwargs`. "
],
"text/plain": [
"idx_dict
[source]idx_dict
(`a`)"
],
"text/plain": [
"index_row
[source]index_row
(`a`:`Collection`, `idxs`:`Collection`\\[`int`\\]) → `Any`\n",
"\n",
"Return the slice of `a` corresponding to `idxs`. "
],
"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": [
"range_of
[source]range_of
(`x`)"
],
"text/plain": [
"series2cat
[source]series2cat
(`df`:`DataFrame`, `col_names`)\n",
"\n",
"Categorifies the columns `col_names` in `df`. "
],
"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": [
"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`, `chunk_size`=`1048576`, `timeout`=`4`)\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": [
"save_texts
[source]save_texts
(`fname`:`PathOrStr`, `texts`:`StrList`)\n",
"\n",
"Save in `fname` the content of `texts`. "
],
"text/plain": [
"class
ItemBase
[source]ItemBase
(`data`:`Any`)"
],
"text/plain": [
"class
Category
[source]Category
(`data`, `obj`) :: [`ItemBase`](/core.html#ItemBase)"
],
"text/plain": [
"class
MultiCategory
[source]MultiCategory
(`data`, `obj`, `raw`) :: [`ItemBase`](/core.html#ItemBase)"
],
"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": [
"func_args
[source]func_args
(`func`) → `bool`\n",
"\n",
"Return the arguments of `func`. "
],
"text/plain": [
"noop
[source]noop
(`x`)"
],
"text/plain": [
"num_cpus
[source]num_cpus
() → `int`\n",
"\n",
"Get number of cpus "
],
"text/plain": [
"one_hot
[source]one_hot
(`x`:`Collection`\\[`int`\\], `c`:`int`)\n",
"\n",
"One-hot encode the target. "
],
"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": [
"show
[source]show
(`ax`:`Axes`, `kwargs`)"
],
"text/plain": [
"apply_tfms
[source]apply_tfms
(`tfms`:`Collection`, `kwargs`)"
],
"text/plain": [
"array
[source]array
(`a`, `args`, `kwargs`) → `ndarray`\n",
"\n",
"Same as `np.array` but also handles generators "
],
"text/plain": [
"