diff --git a/Cargo.toml b/Cargo.toml index a086f0397..3d89a3617 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,24 @@ exclude = [ "arrayfire/*", ] +[features] +algorithm = [] +arithmetic = [] +blas = [] +data = [] +indexing = [] +graphics = [] +image = [] +lapack = [] +macros = [] +random = [] +signal = [] +sparse = [] +statistics = [] +vision = [] +default = ["algorithm", "arithmetic", "blas", "data", "indexing", "graphics", "image", "lapack", +"macros", "random", "signal", "sparse", "statistics", "vision"] + [dependencies] libc = "0.2.11" num = "0.1.32" diff --git a/src/arith/mod.rs b/src/arith/mod.rs index d5cf69573..cadd40cfd 100644 --- a/src/arith/mod.rs +++ b/src/arith/mod.rs @@ -195,7 +195,29 @@ binary_func!("Elementwise minimum operation of two Arrays", minof, af_minof); binary_func!("Elementwise maximum operation of two Arrays", maxof, af_maxof); binary_func!("Compute length of hypotenuse of two Arrays", hypot, af_hypot); +/// Type Trait to convert to an [Array](./struct.Array.html) +/// +/// Generic functions that overload the binary operations such as add, div, mul, rem, ge etc. are +/// bound by this trait to allow combinations of scalar values and Array objects as parameters +/// to those functions. +/// +/// Internally, Convertable trait is implemented by following types. +/// +/// - f32 +/// - f64 +/// - num::Complex\ +/// - num::Complex\ +/// - bool +/// - i32 +/// - u32 +/// - u8 +/// - i64 +/// - u64 +/// - i16 +/// - u16 +/// pub trait Convertable { + /// Get an Array from given type fn convert(&self) -> Array; } diff --git a/src/array.rs b/src/array.rs index 1b44b4937..e159ec359 100644 --- a/src/array.rs +++ b/src/array.rs @@ -8,7 +8,6 @@ use self::libc::{uint8_t, c_void, c_int, c_uint, c_longlong, c_char}; use std::ffi::CString; // Some unused functions from array.h in C-API of ArrayFire -// af_create_handle // af_copy_array // af_write_array // af_get_data_ref_count diff --git a/src/data/mod.rs b/src/data/mod.rs index 30326bbb7..c97cf636a 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -54,7 +54,29 @@ extern { fn af_replace_scalar(a: AfArray, cond: AfArray, b: c_double) -> c_int; } +/// Type Trait to generate a constant [Array](./struct.Array.html) of given size +/// +/// Internally, ConstGenerator trait is implemented by following types. +/// +/// - f32 +/// - f64 +/// - num::Complex\ +/// - num::Complex\ +/// - bool +/// - i32 +/// - u32 +/// - u8 +/// - i64 +/// - u64 +/// - i16 +/// - u16 +/// pub trait ConstGenerator { + /// Create an Array of `dims` size from scalar value `self`. + /// + /// # Parameters + /// + /// - `dims` are the dimensions of the output constant [Array](./struct.Array.html) fn generate(&self, dims: Dim4) -> Array; } diff --git a/src/index.rs b/src/index.rs index d3d9fd3ff..9d505f647 100644 --- a/src/index.rs +++ b/src/index.rs @@ -80,11 +80,19 @@ pub struct Indexer<'object> { marker: PhantomData<&'object ()>, } -// Trait that indicates that object can be used for indexing -// -// Any object to be able to be passed on to [./struct.Indexer.html#method.set_index] method -// should implement this trait with appropriate implementation +/// Trait bound indicating indexability +/// +/// Any object to be able to be passed on to [Indexer::set_index()](./struct.Indexer.html#method.set_index) method should implement this trait with appropriate implementation of `set` method. pub trait Indexable { + /// Set indexing object for a given dimension + /// + /// # Parameters + /// + /// - `idxr` is mutable reference to [Indexer](./struct.Indexer.html) object which will + /// be modified to set `self` indexable along `dim` dimension. + /// - `dim` is the dimension along which `self` indexable will be used for indexing. + /// - `is_batch` is only used if `self` is [Seq](./struct.Seq.html) to indicate if indexing + /// along `dim` is a batched operation. fn set(&self, idxr: &mut Indexer, dim: u32, is_batch: Option); } diff --git a/src/lib.rs b/src/lib.rs index 678f28432..106e7411c 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,50 +34,36 @@ #[macro_use] extern crate lazy_static; -pub use array::Array; -pub use array::{print, print_gen, eval_multiple, is_eval_manual, set_manual_eval}; +pub use array::*; mod array; -//pub use algorithm::{sum_nan, product_nan, sum_nan_all, product_nan_all}; -pub use algorithm::{sum, product, min, max, all_true, any_true, count, sum_nan, product_nan}; -pub use algorithm::{sum_all, product_all, min_all, max_all, sum_nan_all, product_nan_all}; -pub use algorithm::{all_true_all, any_true_all, count_all, imin, imax, imin_all, imax_all}; -pub use algorithm::{accum, locate, diff1, diff2, sort, sort_index, sort_by_key}; -pub use algorithm::{set_unique, set_union, set_intersect, scan, scan_by_key}; +#[cfg(feature="algorithm")] +pub use algorithm::*; +#[cfg(feature="algorithm")] mod algorithm; -pub use arith::{add, sub, div, mul, lt, gt, le, ge, eq, neq, and, or, minof, maxof, rem}; -pub use arith::{bitand, bitor, bitxor, shiftl, shiftr}; -pub use arith::{abs, sign, round, trunc, floor, ceil, modulo, sigmoid, clamp}; -pub use arith::{sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh}; -pub use arith::{atan2, cplx2, arg, cplx, real, imag, conjg, hypot}; -pub use arith::{sqrt, log, log1p, log10, log2, pow2, exp, expm1, erf, erfc, root, pow}; -pub use arith::{cbrt, factorial, tgamma, lgamma, iszero, isinf, isnan}; +#[cfg(feature="arithmetic")] +pub use arith::*; +#[cfg(feature="arithmetic")] mod arith; -pub use backend::{set_backend, get_backend_count, get_available_backends, get_active_backend}; +pub use backend::*; mod backend; -pub use blas::{matmul, dot, transpose, transpose_inplace}; +#[cfg(feature="blas")] +pub use blas::*; +#[cfg(feature="blas")] mod blas; -pub use data::{constant, range, iota, identity}; -pub use data::{diag_create, diag_extract, lower, upper}; -pub use data::{join, join_many, tile}; -pub use data::{reorder, shift, moddims, flat, flip}; -pub use data::{select, selectl, selectr, replace, replace_scalar}; -pub use data::{range_t, iota_t, identity_t, constant_t}; +#[cfg(feature="data")] +pub use data::*; +#[cfg(feature="data")] mod data; -pub use device::{get_version, get_revision, info, info_string, device_info, init, device_count, is_double_available, set_device, get_device}; -pub use device::{device_mem_info, print_mem_info, set_mem_step_size, get_mem_step_size, device_gc, sync}; +pub use device::*; mod device; -pub use defines::{DType, AfError, Backend, ColorMap, YCCStd, HomographyType}; -pub use defines::{InterpType, BorderType, MatchType, NormType}; -pub use defines::{Connectivity, ConvMode, ConvDomain, ColorSpace, MatProp}; -pub use defines::{MarkerType, MomentType, SparseFormat, BinaryOp, RandomEngineType}; -pub use defines::{PHILOX, THREEFRY, MERSENNE, DEFAULT_RANDOM_ENGINE, Scalar}; +pub use defines::*; mod defines; pub use dim4::Dim4; @@ -86,68 +72,62 @@ mod dim4; pub use error::{Callback, ErrorCallback, register_error_handler, handle_error_general}; mod error; -pub use index::{Indexer, index, row, rows, col, cols, slice, slices, - set_row, set_rows, set_col, set_cols, set_slice, set_slices, - lookup, assign_seq, index_gen, assign_gen}; +#[cfg(feature="indexing")] +pub use index::*; +#[cfg(feature="indexing")] mod index; pub use seq::Seq; mod seq; +#[cfg(feature="graphics")] pub use graphics::Window; +#[cfg(feature="graphics")] mod graphics; -pub use image::{gaussian_kernel, load_image, load_image_native, save_image, save_image_native}; -pub use image::{resize, transform, rotate, translate, scale, skew}; -pub use image::{dilate, dilate3, erode, erode3, minfilt, maxfilt}; -pub use image::{gradient, histogram, hist_equal, regions}; -pub use image::{gray2rgb, rgb2gray, hsv2rgb, rgb2hsv, color_space}; -pub use image::{bilateral, mean_shift, medfilt, sobel, medfilt1}; -pub use image::{unwrap, wrap, sat, rgb2ycbcr, ycbcr2rgb, is_imageio_available, transform_coords}; -pub use image::{moments, moments_all}; +#[cfg(feature="image")] +pub use image::*; +#[cfg(feature="image")] mod image; -pub use lapack::{svd, lu, qr, cholesky, solve, solve_lu, inverse, det, rank, norm}; -pub use lapack::{svd_inplace, lu_inplace, qr_inplace, cholesky_inplace, is_lapack_available}; +#[cfg(feature="lapack")] +pub use lapack::*; +#[cfg(feature="lapack")] mod lapack; + +#[cfg(feature="macros")] mod macros; mod num; -pub use random::RandomEngine; -pub use random::{set_seed, get_seed, randu, randn, random_uniform, random_normal}; -pub use random::{get_default_random_engine, set_default_random_engine_type}; +#[cfg(feature="random")] +pub use random::*; +#[cfg(feature="random")] mod random; -pub use signal::{approx1, approx2, set_fft_plan_cache_size}; -pub use signal::{fft, fft2, fft3, ifft, ifft2, ifft3}; -pub use signal::{fft_r2c, fft2_r2c, fft3_r2c, fft_c2r, fft2_c2r, fft3_c2r}; -pub use signal::{fft_inplace, fft2_inplace, fft3_inplace}; -pub use signal::{ifft_inplace, ifft2_inplace, ifft3_inplace}; -pub use signal::{convolve1, convolve2, convolve3, convolve2_sep}; -pub use signal::{fft_convolve1, fft_convolve2, fft_convolve3}; -pub use signal::{fir, iir}; +#[cfg(feature="signal")] +pub use signal::*; +#[cfg(feature="signal")] mod signal; -pub use sparse::{sparse, sparse_from_host, sparse_from_dense, sparse_convert_to}; -pub use sparse::{sparse_to_dense, sparse_get_info, sparse_get_values, sparse_get_nnz}; -pub use sparse::{sparse_get_row_indices, sparse_get_col_indices, sparse_get_format}; +#[cfg(feature="sparse")] +pub use sparse::*; +#[cfg(feature="sparse")] mod sparse; -pub use statistics::{mean, stdev, median, var, cov, corrcoef}; -pub use statistics::{mean_weighted, var_weighted}; -pub use statistics::{var_all, mean_all, stdev_all, median_all}; -pub use statistics::{mean_all_weighted, var_all_weighted}; +#[cfg(feature="statistics")] +pub use statistics::*; +#[cfg(feature="statistics")] mod statistics; pub use util::{HasAfEnum, get_size}; mod util; -pub use vision::Features; -pub use vision::{fast, harris, orb, hamming_matcher, nearest_neighbour, match_template, susan, dog}; -pub use vision::{homography}; +#[cfg(feature="vision")] +pub use vision::*; +#[cfg(feature="vision")] mod vision; -// headers that are not exposed through rust wrapper are as follows: +// headers that are not exposed through rust wrapper are given follows: // compatible.h // constants.h // complex.h diff --git a/tests/lib.rs b/tests/lib.rs index fa0ce65f2..11990e92a 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -1,4 +1,3 @@ -#[macro_use] extern crate arrayfire as af; use std::error::Error;