1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
//! A vector computation library
//!
//! # Contents
//!
//! - [About](#about)
//! - [Safety Guarantee](#safety-guarantee)
//! - [Versioning](#versioning)
//! - [Minimum Rust Version Compatibility Policy](#minimum-rust-version-compatibility-policy)
//! - [Source](#source)
//! - [Changes](#changes)
//! - [Issues](#issues)
//! - [Contributing](#contributing)
//! - [License](#license)
//! - [Getting Started](#getting-started)
//! - [Add Vectora to Your Project](#add-vectora-to-your-project)
//! - [Numeric Type Support](#numeric-type-support)
//! - [Initialization](#initialization)
//! - [Access and Assignment with Indexing](#access-and-assignment-with-indexing)
//! - [Slicing](#slicing)
//! - [Partial Equivalence Testing](#partial-equivalence-testing)
//! - [Iteration and Loops](#iteration-and-loops)
//! - [Vector Arithmetic](#vector-arithmetic)
//! - [Methods for Vector Operations](#methods-for-vector-operations)
//! - [Working with Rust Standard Library Types](#working-with-rust-standard-library-types)
//!
//!
//! # About
//!
//! Vectora is a library for n-dimensional vector computation with real and complex scalar types.
//! The main library entry point is the [`Vector`] struct. Please see the [Gettting Started guide](#getting-started)
//! for a detailed library overview with examples.
//!
//! # Safety Guarantee
//!
//! The current default distribution does not contain `unsafe` code blocks.
//!
//! # Versioning
//!
//! This project uses [semantic versioning](https://semver.org/) and is currently in a pre-v1.0 stage
//! of development. The public API should not be considered stable across release versions at this
//! time.
//!
//! # Minimum Rust Version Compatibility Policy
//!
//! This project parameterizes generics by constants and relies on the [constant generics feature support
//! that was stabilized in Rust v1.51](https://github.com/rust-lang/rust/pull/79135). The minimum
//! supported `rustc` version is believed to be v1.51.0.
//!
//! # Source
//!
//! The source files are available at <https://github.com/chrissimpkins/vectora>.
//!
//! # Changes
//!
//! Please see the [CHANGELOG.md](https://github.com/chrissimpkins/vectora/blob/main/CHANGELOG.md) document in the source repository.
//!
//! # Issues
//!
//! The [issue tracker](https://github.com/chrissimpkins/vectora/issues) is available on the GitHub repository.
//! Don't be shy. Please report any issues that you identify so that we can address them.
//!
//! # Contributing
//!
//! Contributions are welcomed. Developer documentation is available in the source
//! repository [README](https://github.com/chrissimpkins/vectora).
//!
//! Submit your source or documentation changes as a GitHub pull request on
//! the [source repository](https://github.com/chrissimpkins/vectora).
//!
//! # License
//!
//! Vectora is released under the [Apache License v2.0](https://github.com/chrissimpkins/vectora/blob/main/LICENSE.md).
//! Please review the full text of the license for details.
//!
//! # Getting Started
//!
//! See the [`Vector`] page for detailed API documentation of the main library
//! entry point.
//!
//! The following section provides an overview of common tasks and will get you up
//! and running with the library quickly.
//!
//! ## Add Vectora to Your Project
//!
//! Import the vectora library in the `[dependencies]` section
//! of your `Cargo.toml` file:
//!
//! ```toml
//! [dependencies]
//! vectora = "0.4.0"
//! ```
//!
//! The examples below assume the following [`Vector`] struct import in
//! your Rust source files:
//!
//! ```
//! use vectora::Vector;
//! ```
//!
//! ## Numeric Type Support
//!
//! This library supports computation with real and complex scalar number types.
//!
//! ### Integers
//!
//! Support is available for the following primitive integer data types:
//!
//! - [`i8`]
//! - [`i16`]
//! - [`i32`]
//! - [`i64`]
//! - [`i128`]
//! - [`u8`]
//! - [`u16`]
//! - [`u32`]
//! - [`u64`]
//! - [`u128`]
//! - [`usize`]
//! - [`isize`]
//!
//! **Note**: overflowing integer arithmetic uses the default
//! Rust standard library approach of panics in debug builds
//! and twos complement wrapping in release builds. You will not encounter
//! undefined behavior with either build type, but this approach
//! may not be what you want. Please consider this issue and understand
//! the library source implementations if your use case requires support
//! for integer overflows/underflows, and you prefer to handle it differently.
//!
//! ### Floating Point Numbers
//!
//! Support is available for the following primitive IEEE 754-2008 floating point types:
//!
//! - [`f32`]
//! - [`f64`]
//!
//! ### Complex Numbers
//!
//! A 2-[`Vector`] can be used **as a** complex number with real and imaginary
//! integer or floating point parts at indices 0 and 1.
//!
//! The [`Vector`] type also supports **collections of** complex numbers as
//! represented by the [`num::Complex`] type.
//!
//! **Note**: This guide will not provide detailed examples with [`num::Complex`] data in order to
//! remain as concise as possible. With the notable exception of some
//! floating point only [`Vector`] methods, most of the public API supports
//! the [`num::Complex`] type. These areas should be evident in the
//! [`Vector`] API descriptions and source trait bounds. [`num::Complex`] support
//! *should* be available when a general [`num::Num`] trait bound is used in
//! implementations. In these cases, you can replace the integer or floating point
//! numbers in the following examples with [`num::Complex`] types.
//!
//! ## Initialization
//!
//! A [`Vector`] can have mutable values, but it cannot grow in length. The
//! dimension length is fixed at instantiation, and all fields are *initialized*
//! at instantiation.
//!
//! ### Zero Vector
//!
//! Use the [`Vector::zero`] method to initialize a [`Vector`] with zero values
//! of the respective numeric type:
//!
//! ```
//! # use vectora::Vector;
//! let v_zero_int: Vector<i32, 3> = Vector::zero();
//! let v_zero_float: Vector<f64, 2> = Vector::zero();
//!
//! // Note: the following complex number example requires an import of the `num::Complex` type!
//! use num::Complex;
//!
//! let v_zero_complex: Vector<Complex<f64>, 2> = Vector::zero();
//! ```
//!
//! ### With Predefined Data in Other Types
//!
//! The recommended approach is to use [`Vector::from`] with an [`array`] of
//! ordered data when possible:
//!
//! ```
//! # use vectora::Vector;
//! // example three dimensional f64 Vector
//! let v: Vector<f64, 3> = Vector::from([1.0, 2.0, 3.0]);
//!
//! // example two dimensional i32 Vector
//! let v: Vector<i32, 2> = Vector::from([4, -5]);
//!
//! // with num crate Complex numbers
//! // Note: the following complex number example requires an import of the `num::Complex` type!
//! use num::Complex;
//!
//! let v: Vector<Complex<f64>, 2> = Vector::from([Complex::new(1.0, 2.0), Complex::new(3.0, 4.0)]);
//!
//! // with a library type alias
//! use vectora::types::vector::Vector3dF64;
//!
//! let v: Vector3dF64 = Vector::from([1.0, 2.0, 3.0]);
//! ```
//!
//! or use one of the alternate initialization approaches with data
//! in iterator, [`array`], [`slice`], or [`Vec`] types:
//!
//! ```
//! # use vectora::Vector;
//! // from an iterator over an array or Vec with collect
//! let v: Vector<i32, 3> = [1, 2, 3].into_iter().collect();
//! let v: Vector<f64, 2> = vec![1.0, 2.0].into_iter().collect();
//!
//! // from a slice with try_from
//! let arr = [1, 2, 3];
//! let vec = vec![1.0, 2.0, 3.0];
//! let v: Vector<i32, 3> = Vector::try_from(&arr[..]).unwrap();
//! let v: Vector<f64, 3> = Vector::try_from(&vec[..]).unwrap();
//!
//! // from a Vec with try_from
//! let vec = vec![1, 2, 3];
//! let v: Vector<i32, 3> = Vector::try_from(&vec).unwrap();
//! ```
//!
//! Please see the API docs for the approach to overflows and underflows with the
//! [`FromIterator`](types/vector/struct.Vector.html#impl-FromIterator<T>)
//! trait implementation that supports the `collect` approach.
//!
//! ## Access and Assignment with Indexing
//!
//! Use zero-based indices for access and assignment:
//!
//! ### Access
//!
//! ```
//! # use vectora::Vector;
//! let v1: Vector<f64, 3> = Vector::from([1.0, 2.0, 3.0]);
//!
//! let x = v1[0];
//! let y = v1[1];
//! let z = v1[2];
//! ```
//!
//! Attempts to access items beyond the length of the [`Vector`] panic:
//!
//! ```should_panic
//! # use vectora::Vector;
//! # let v1: Vector<f64, 3> = Vector::from([1.0, 2.0, 3.0]);
//! // panics!
//! let _ = v1[10];
//! ```
//!
//! ### Assignment
//!
//! ```
//! # use vectora::Vector;
//! let mut v1_m: Vector<f64, 3> = Vector::from([1.0, 2.0, 3.0]);
//!
//! v1_m[0] = 10.0;
//! v1_m[1] = 20.0;
//! v1_m[2] = 30.0;
//! ```
//!
//! Attempts to assign to items beyond the length of the [`Vector`] panic:
//!
//! ```should_panic
//! # use vectora::Vector;
//! # let mut v1_m: Vector<f64, 3> = Vector::from([1.0, 2.0, 3.0]);
//! // panics!
//! v1_m[10] = 100.0;
//! ```
//!
//! See the [`Vector::get`] and [`Vector::get_mut`] method documentation
//! for getters that perform bounds checks and do not panic.
//!
//! ## Slicing
//!
//! Coerce to a read-only [`slice`] of the [`Vector`]:
//!
//! ```
//! # use vectora::Vector;
//! let v = Vector::<i32, 3>::from([1, 2, 3]);
//! let v_slice = &v[0..2];
//!
//! assert_eq!(v_slice, [1, 2]);
//! ```
//!
//! ## Partial Equivalence Testing
//!
//! Partial equivalence relation support is available with the `==` operator
//! for integer, floating point, and [`num::Complex`] numeric types.
//!
//! ### Integer types
//!
//! [`Vector`] of real integer values:
//!
//! ```
//! # use vectora::Vector;
//! let v1: Vector<i32, 3> = Vector::from([10, 50, 100]);
//! let v2: Vector<i32, 3> = Vector::from([5*2, 25+25, 10_i32.pow(2)]);
//!
//! assert!(v1 == v2);
//! ```
//!
//! [`Vector`] of [`num::Complex`] numbers with integer real and imaginary parts:
//!
//! ```
//! # use vectora::Vector;
//! use num::Complex;
//!
//! let v1: Vector<Complex<i32>, 2> = Vector::from([Complex::new(1, 2), Complex::new(3, 4)]);
//! let v2: Vector<Complex<i32>, 2> = Vector::from([Complex::new(1, 2), Complex::new(3, 4)]);
//!
//! assert!(v1 == v2);
//! ```
//!
//! ### Float types
//!
//! We compare floating point types with the [approx](https://docs.rs/approx/latest/approx/)
//! crate relative epsilon equivalence relation implementation by default. This includes
//! fixed definitions of the epsilon and max relative difference values. See
//! [the section below](#custom-equivalence-relations-for-float-types) for customization
//! options with methods.
//!
//! Why a different strategy for floats?
//!
//! Some floating point numbers are not considered equivalent due to
//! floating point precision:
//!
//! ```should_panic
//! // panics!
//! assert!(0.15_f64 + 0.15_f64 == 0.1_f64 + 0.2_f64);
//! ```
//!
//! You likely want these floating point sums to compare as approximately equivalent.
//!
//! With the [`Vector`] type, they do.
//!
//! [`Vector`] of floating point values:
//!
//! ```
//! # use vectora::Vector;
//! let v1: Vector<f64, 1> = Vector::from([0.15 + 0.15]);
//! let v2: Vector<f64, 1> = Vector::from([0.1 + 0.2]);
//!
//! assert!(v1 == v2);
//! ```
//!
//! [`Vector`] of [`num::Complex`] numbers with floating point real and imaginary parts:
//!
//! ```
//! # use vectora::Vector;
//! use num::Complex;
//!
//! let v1: Vector<Complex<f64>, 2> = Vector::from([Complex::new(0.15 + 0.15, 2.0), Complex::new(3.0, 4.0)]);
//! let v2: Vector<Complex<f64>, 2> = Vector::from([Complex::new(0.1 + 0.2, 2.0), Complex::new(3.0, 4.0)]);
//!
//! assert!(v1 == v2);
//! ```
//!
//! `assert_eq!` and `assert_ne!` macro assertions use the same
//! partial equivalence approach, as you'll note throughout these docs.
//!
//! You can implement the same equivalence relation approach for float types that
//! are **not** contained in a [`Vector`] with the [approx crate](https://docs.rs/approx/latest/approx/)
//! `relative_eq!`, `relative_ne!`, `assert_relative_eq!`, and `assert_relative_ne!`
//! macros.
//!
//! ### Custom equivalence relations for floating point types
//!
//! The library also provides method support for absolute, relative, and units in last place (ULPs)
//! approximate floating point equivalence relations. These methods allow custom epsilon, max relative,
//! and max ULPs difference tolerances to define relations when float data are near and far apart. You
//! must call the method to use them. It is not possible to modify the default approach used in the
//! `==` operator overload.
//!
//! See the API documentation for [`Vector`] implementations of the `approx` crate `AbsDiffEq`, `RelativeEq`,
//! `UlpsEq` traits in the links below:
//!
//! #### Absolute difference equivalence relation
//!
//! The absolute difference equivalence relation approach supports custom epsilon tolerance definitions.
//!
//! - [`Vector::abs_diff_eq`](types/vector/struct.Vector.html#impl-AbsDiffEq<Vector<f32%2C%20N>>) (`f32`)
//! - [`Vector::abs_diff_eq`](types/vector/struct.Vector.html#impl-AbsDiffEq<Vector<f64%2C%20N>>) (`f64`)
//! - [`Vector::abs_diff_eq`](types/vector/struct.Vector.html#impl-AbsDiffEq<Vector<Complex<f32>%2C%20N>>) (`Complex<f32>`)
//! - [`Vector::abs_diff_eq`](types/vector/struct.Vector.html#impl-AbsDiffEq<Vector<Complex<f64>%2C%20N>>) (`Complex<f64>`)
//!
//! #### Relative difference equivalence relation
//!
//! The relative difference equivalence relation approach supports custom epsilon (data that are near)
//! and max relative difference (data that are far apart) tolerance definitions.
//!
//! - [`Vector::relative_eq`](types/vector/struct.Vector.html#impl-RelativeEq<Vector<f32%2C%20N>>) (`f32`)
//! - [`Vector::relative_eq`](types/vector/struct.Vector.html#impl-RelativeEq<Vector<f64%2C%20N>>) (`f64`)
//! - [`Vector::relative_eq`](types/vector/struct.Vector.html#impl-RelativeEq<Vector<Complex<f32>%2C%20N>>) (`Complex<f32>`)
//! - [`Vector::relative_eq`](types/vector/struct.Vector.html#impl-RelativeEq<Vector<Complex<f64>%2C%20N>>) (`Complex<f64>`)
//!
//! #### Units in Last Place (ULPs) difference equivalence relation
//!
//! The ULPs difference equivalence relation approach supports custom epsilon (data that are near)
//! and max ULPs difference (data that are far apart) tolerance definitions.
//!
//! - [`Vector::ulps_eq`](types/vector/struct.Vector.html#impl-UlpsEq<Vector<f32%2C%20N>>) (`f32`)
//! - [`Vector::ulps_eq`](types/vector/struct.Vector.html#impl-UlpsEq<Vector<f64%2C%20N>>) (`f64`)
//! - [`Vector::ulps_eq`](types/vector/struct.Vector.html#impl-UlpsEq<Vector<Complex<f32>%2C%20N>>) (`Complex<f32>`)
//! - [`Vector::ulps_eq`](types/vector/struct.Vector.html#impl-UlpsEq<Vector<Complex<f64>%2C%20N>>) (`Complex<f64>`)
//!
//! ## Iteration and Loops
//!
//! ### Over immutable scalar references
//!
//! ```
//! # use vectora::Vector;
//! let v: Vector<i32, 3> = Vector::from([-1, 2, 3]);
//! let mut iter = v.iter();
//!
//! assert_eq!(iter.next(), Some(&-1));
//! assert_eq!(iter.next(), Some(&2));
//! assert_eq!(iter.next(), Some(&3));
//! assert_eq!(iter.next(), None);
//! ```
//!
//! The syntax for a loop over this type:
//!
//! ```
//! # use vectora::Vector;
//! # let v: Vector<i32, 3> = Vector::from([-1, 2, 3]);
//! for x in &v {
//! // do things
//! }
//! ```
//!
//! ### Over mutable scalar references
//!
//! ```
//! # use vectora::Vector;
//! let mut v: Vector<i32, 3> = Vector::from([-1, 2, 3]);
//! let mut iter = v.iter_mut();
//!
//! assert_eq!(iter.next(), Some(&mut -1));
//! assert_eq!(iter.next(), Some(&mut 2));
//! assert_eq!(iter.next(), Some(&mut 3));
//! assert_eq!(iter.next(), None);
//! ```
//!
//! The syntax for a loop over this type:
//!
//! ```
//! # use vectora::Vector;
//! # let mut v: Vector<i32, 3> = Vector::from([-1, 2, 3]);
//! for x in &mut v {
//! // do things
//! }
//! ```
//!
//! ### Over mutable scalar values
//!
//! ```
//! # use vectora::Vector;
//! let v: Vector<i32, 3> = Vector::from([-1, 2, 3]);
//! let mut iter = v.into_iter();
//!
//! assert_eq!(iter.next(), Some(-1));
//! assert_eq!(iter.next(), Some(2));
//! assert_eq!(iter.next(), Some(3));
//! assert_eq!(iter.next(), None);
//! ```
//!
//! The syntax for a loop over this type:
//!
//! ```
//! # use vectora::Vector;
//! # let v: Vector<i32, 3> = Vector::from([-1, 2, 3]);
//! for x in v {
//! // do things
//! }
//! ```
//!
//! ## Vector Arithmetic
//!
//! Use operator overloads for vector arithmetic:
//!
//! ### Unary Negation
//!
//! The unary negation operator yields the additive inverse
//! [`Vector`]:
//!
//! ```
//! # use vectora::Vector;
//! let v: Vector<f64, 3> = Vector::from([1.0, 2.0, 3.0]);
//!
//! assert_eq!(-v, Vector::from([-1.0, -2.0, -3.0]));
//! assert_eq!(v + -v, Vector::<f64, 3>::zero());
//! ```
//!
//! ### Vector Addition
//!
//! ```
//! # use vectora::Vector;
//! let v1: Vector<f64, 3> = Vector::from([1.0, 2.0, 3.0]);
//! let v2: Vector<f64, 3> = Vector::from([4.0, 5.0, 6.0]);
//!
//! let v3 = v1 + v2;
//!
//! assert_eq!(v3, Vector::from([5.0, 7.0, 9.0]));
//! ```
//!
//! ### Vector Subtraction
//!
//! ```
//! # use vectora::Vector;
//! let v1: Vector<f64, 3> = Vector::from([1.0, 2.0, 3.0]);
//! let v2: Vector<f64, 3> = Vector::from([4.0, 5.0, 6.0]);
//!
//! let v3 = v2 - v1;
//!
//! assert_eq!(v3, Vector::from([3.0, 3.0, 3.0]));
//! ```
//!
//! ### Scalar Multiplication
//!
//! ```
//! # use vectora::Vector;
//! let v1: Vector<f64, 3> = Vector::from([1.0, 2.0, 3.0]);
//! let v2: Vector<f64, 3> = Vector::from([4.0, 5.0, 6.0]);
//!
//! let v3 = v1 * 10.0;
//! let v4 = v2 * -1.0;
//!
//! assert_eq!(v3, Vector::from([10.0, 20.0, 30.0]));
//! assert_eq!(v4, Vector::from([-4.0, -5.0, -6.0]));
//! ```
//!
//! #### Scalar multiplication with [`num::Complex`] numbers
//!
//! [`Vector`] of [`num::Complex`] types support multiplication with
//! real and complex numbers.
//!
//! ##### [`num::Complex`] * real
//!
//! ```
//! # use vectora::Vector;
//! use num::Complex;
//!
//! let v: Vector<Complex<i32>, 2> = Vector::from([Complex::new(1, 2), Complex::new(3, 4)]);
//!
//! assert_eq!(v * 10, Vector::<Complex<i32>, 2>::from([Complex::new(10, 20), Complex::new(30, 40)]));
//! ```
//!
//! ##### [`num::Complex`] * [`num::Complex`]
//!
//! ```
//! # use vectora::Vector;
//! use num::Complex;
//!
//! let v: Vector<Complex<f64>, 2> = Vector::from([Complex::new(3.0, 2.0), Complex::new(-3.0, -2.0)]);
//! let c: Complex<f64> = Complex::new(1.0, 7.0);
//!
//! assert_eq!(v * c, Vector::from([Complex::new(-11.0, 23.0), Complex::new(11.0, -23.0)]));
//! ```
//!
//! ## Methods for Vector Operations
//!
//! Method support is available for common vector calculations.
//! Examples of some frequently used operations are shown below:
//!
//! ### Dot product
//!
//! ```
//! # use vectora::Vector;
//! use approx::assert_relative_eq;
//!
//! let v1: Vector<f64, 3> = Vector::from([1.0, 2.0, 3.0]);
//! let v2: Vector<f64, 3> = Vector::from([4.0, 5.0, 6.0]);
//!
//! let dot_prod = v1.dot(&v2);
//!
//! assert_relative_eq!(dot_prod, 32.0);
//! ```
//!
//! [ [API docs](types/vector/struct.Vector.html#method.dot) ]
//!
//! ### Vector Magnitude
//!
//! ```
//! # use vectora::Vector;
//! use approx::assert_relative_eq;
//!
//! let v1: Vector<f64, 3> = Vector::from([1.0, 2.0, 3.0]);
//!
//! let m = v1.magnitude();
//!
//! assert_relative_eq!(m, 3.7416573867739413);
//! ```
//!
//! [ [API docs](types/vector/struct.Vector.html#method.magnitude) ]
//!
//! ### Vector Distance
//!
//! ```
//! # use vectora::Vector;
//! use approx::assert_relative_eq;
//!
//! let v1: Vector<f64, 2> = Vector::from([2.0, 2.0]);
//! let v2: Vector<f64, 2> = Vector::from([4.0, 4.0]);
//!
//! assert_relative_eq!(v1.distance(&v2), 8.0_f64.sqrt());
//! assert_relative_eq!(v1.distance(&v1), 0.0_f64);
//! ```
//!
//! [ [API docs](types/vector/struct.Vector.html#method.distance) ]
//!
//! ### Opposite Vector
//!
//! ```
//! # use vectora::Vector;
//! use approx::assert_relative_eq;
//!
//! let v: Vector<f64, 3> = Vector::from([2.0, 2.0, 2.0]);
//!
//! assert_eq!(v.opposite(), Vector::from([-2.0, -2.0, -2.0]));
//! assert_relative_eq!(v.opposite().magnitude(), v.magnitude());
//! ```
//!
//! [ [API docs](types/vector/struct.Vector.html#method.opposite) ]
//!
//! ### Normalization
//!
//! ```
//! # use vectora::Vector;
//! use approx::assert_relative_eq;
//!
//! let v1: Vector<f64, 3> = Vector::from([1.0, 2.0, 3.0]);
//!
//! let unit_vector = v1.normalize();
//!
//! assert_relative_eq!(unit_vector.magnitude(), 1.0);
//! ```
//!
//! [ [API docs](types/vector/struct.Vector.html#method.normalize) ]
//!
//! ### Linear Interpolation
//!
//!```
//! # use vectora::Vector;
//! let v1: Vector<f64, 3> = Vector::from([1.0, 2.0, 3.0]);
//! let v2: Vector<f64, 3> = Vector::from([4.0, 5.0, 6.0]);
//!
//! let v3 = v1.lerp(&v2, 0.5).unwrap();
//!
//! assert_eq!(v3, Vector::from([2.5, 3.5, 4.5]));
//!```
//!
//! [ [API docs](types/vector/struct.Vector.html#method.lerp) ]
//!
//! ### Closure Mapping
//!
//! ```
//! # use vectora::Vector;
//! let v1: Vector<f64, 3> = Vector::from([-1.0, 2.0, 3.0]);
//!
//! let v3 = v1.map_closure(|x| x.powi(2));
//!
//! assert_eq!(v3, Vector::from([1.0, 4.0, 9.0]));
//! ```
//!
//! [ [API docs](types/vector/struct.Vector.html#method.map_closure) ]
//!
//! ### Function Mapping
//!
//!```
//!# use vectora::Vector;
//! let v1: Vector<f64, 3> = Vector::from([-1.0, 2.0, 3.0]);
//!
//! fn square(x: f64) -> f64 {
//! x.powi(2)
//! }
//!
//! let v3 = v1.map_fn(square);
//!
//! assert_eq!(v3, Vector::from([1.0, 4.0, 9.0]));
//!```
//!
//! [ [API docs](types/vector/struct.Vector.html#method.map_fn) ]
//!
//! Many of these methods have mutable alternates that edit the [`Vector`] data
//! in place instead of allocating a new [`Vector`]. The mutable methods are
//! prefixed with `mut_*`.
//!
//! See the [`Vector` method implementations](types/vector/struct.Vector.html#implementations) docs
//! for the complete list of supported methods and additional examples.
//!
//! ## Working with Rust Standard Library Types
//!
//! Casts to commonly used Rust standard library data collection types are straightforward.
//! Note that some of these type casts support mutable [`Vector`] owned data references,
//! allowing you to use standard library type operations to change the [`Vector`] data.
//!
//! ### [`array`] Representations
//!
//! Immutable:
//!
//! ```
//! # use vectora::Vector;
//! let v: Vector<i32, 3> = Vector::from([-1, 2, 3]);
//!
//! assert_eq!(v.as_array(), &[-1, 2, 3]);
//! assert_eq!(v.to_array(), [-1, 2, 3]);
//! ```
//!
//! Mutable:
//!
//! ```
//! # use vectora::Vector;
//! let mut v: Vector<i32, 3> = Vector::from([-1, 2, 3]);
//!
//! let m_arr = v.as_mut_array();
//!
//! assert_eq!(m_arr, &mut [-1, 2, 3]);
//!
//! m_arr[0] = -10;
//!
//! assert_eq!(m_arr, &mut [-10, 2, 3]);
//! assert_eq!(v, Vector::from([-10, 2, 3]));
//! ```
//!
//! ### [`slice`] Representations
//!
//! Immutable:
//!
//! ```
//! # use vectora::Vector;
//! let v: Vector<i32, 3> = Vector::from([-1, 2, 3]);
//!
//! assert_eq!(v.as_slice(), &[-1, 2, 3][..]);
//! ```
//!
//! Mutable:
//!
//! ```
//! # use vectora::Vector;
//! let mut v: Vector<i32, 3> = Vector::from([-1, 2, 3]);
//!
//! let m_sli = v.as_mut_slice();
//!
//! assert_eq!(m_sli, &mut [-1, 2, 3][..]);
//!
//! m_sli[0] = -10;
//!
//! assert_eq!(m_sli, &mut [-10, 2, 3]);
//! assert_eq!(v, Vector::from([-10, 2, 3]));
//! ```
//!
//!
//! ### [`Vec`] Representations
//!
//! Casts to [`Vec`] always allocate a new [`Vec`] with copied data.
//!
//! ```
//! # use vectora::Vector;
//! let v: Vector<i32, 3> = Vector::from([-1, 2, 3]);
//!
//! assert_eq!(v.to_vec(), vec![-1, 2, 3]);
//! ```
//!
//! See the [Initialization](#initialization) section for documentation of
//! the syntax to instantiate a [`Vector`] from a standard library [`Vec`] type.
#![warn(missing_docs)]
#![deny(rustdoc::broken_intra_doc_links, unsafe_code)]
pub mod errors;
pub mod types;
pub use types::vector::Vector;
