From ec1c37d09fee03e2739b3d732d7e6f8fa86b4824 Mon Sep 17 00:00:00 2001 From: Avi Weinstock Date: Thu, 5 Dec 2019 17:54:17 -0500 Subject: [PATCH] Add inlined_clone to Scalar, and relax bounds from `Scalar + Copy` to `Scalar + Clone` nearly everywhere. The various nalgebra-lapack FooScalars are still Copy because they make use of uninitialized memory. nalgebgra-glm Number still uses Copy because upstream `approx` requires it. --- examples/scalar_genericity.rs | 4 +- nalgebra-glm/src/common.rs | 6 +- nalgebra-glm/src/constructors.rs | 32 ++-- nalgebra-glm/src/gtc/bitfield.rs | 10 +- nalgebra-glm/src/gtc/integer.rs | 4 +- nalgebra-glm/src/gtc/matrix_access.rs | 8 +- nalgebra-glm/src/gtc/packing.rs | 6 +- nalgebra-glm/src/gtc/round.rs | 18 +-- nalgebra-glm/src/gtc/type_ptr.rs | 94 +++++------ nalgebra-glm/src/gtc/ulp.rs | 2 +- nalgebra-glm/src/integer.rs | 20 +-- nalgebra-glm/src/matrix.rs | 2 +- nalgebra-glm/src/packing.rs | 24 +-- nalgebra-glm/src/traits.rs | 4 +- nalgebra-lapack/src/cholesky.rs | 2 +- nalgebra-lapack/src/eigen.rs | 4 +- nalgebra-lapack/src/hessenberg.rs | 2 +- nalgebra-lapack/src/lu.rs | 2 +- nalgebra-lapack/src/qr.rs | 2 +- nalgebra-lapack/src/schur.rs | 4 +- nalgebra-lapack/src/svd.rs | 4 +- nalgebra-lapack/src/symmetric_eigen.rs | 4 +- src/base/allocator.rs | 12 +- src/base/array_storage.rs | 16 +- src/base/blas.rs | 110 ++++++------- src/base/cg.rs | 14 +- src/base/componentwise.rs | 16 +- src/base/construction.rs | 36 ++--- src/base/construction_slice.rs | 16 +- src/base/conversion.rs | 54 +++---- src/base/coordinates.rs | 6 +- src/base/default_allocator.rs | 20 +-- src/base/edition.rs | 46 +++--- src/base/indexing.rs | 18 +-- src/base/iter.rs | 40 ++--- src/base/matrix.rs | 192 +++++++++++------------ src/base/matrix_alga.rs | 28 ++-- src/base/matrix_slice.rs | 40 ++--- src/base/ops.rs | 92 +++++------ src/base/properties.rs | 2 +- src/base/scalar.rs | 14 +- src/base/statistics.rs | 15 +- src/base/storage.rs | 8 +- src/base/swizzle.rs | 4 +- src/base/vec_storage.rs | 20 +-- src/debug/random_orthogonal.rs | 2 +- src/debug/random_sdp.rs | 2 +- src/geometry/op_macros.rs | 8 +- src/geometry/perspective.rs | 2 +- src/geometry/point.rs | 26 +-- src/geometry/point_alga.rs | 10 +- src/geometry/point_construction.rs | 16 +- src/geometry/point_conversion.rs | 22 +-- src/geometry/point_coordinates.rs | 4 +- src/geometry/point_ops.rs | 18 +-- src/geometry/reflection.rs | 2 +- src/geometry/rotation.rs | 24 +-- src/geometry/rotation_construction.rs | 4 +- src/geometry/rotation_ops.rs | 2 +- src/geometry/swizzle.rs | 4 +- src/geometry/translation.rs | 28 ++-- src/geometry/translation_construction.rs | 10 +- src/geometry/translation_conversion.rs | 8 +- src/geometry/translation_coordinates.rs | 4 +- src/linalg/lu.rs | 8 +- src/linalg/permutation_sequence.rs | 8 +- src/sparse/cs_matrix.rs | 40 ++--- src/sparse/cs_matrix_conversion.rs | 10 +- src/sparse/cs_matrix_ops.rs | 30 ++-- 69 files changed, 692 insertions(+), 677 deletions(-) diff --git a/examples/scalar_genericity.rs b/examples/scalar_genericity.rs index 18b5c52a..c1d363f7 100644 --- a/examples/scalar_genericity.rs +++ b/examples/scalar_genericity.rs @@ -4,11 +4,11 @@ extern crate nalgebra as na; use alga::general::{RealField, RingCommutative}; use na::{Scalar, Vector3}; -fn print_vector(m: &Vector3) { +fn print_vector(m: &Vector3) { println!("{:?}", m) } -fn print_squared_norm(v: &Vector3) { +fn print_squared_norm(v: &Vector3) { // NOTE: alternatively, nalgebra already defines `v.squared_norm()`. let sqnorm = v.dot(v); println!("{:?}", sqnorm); diff --git a/nalgebra-glm/src/common.rs b/nalgebra-glm/src/common.rs index 5cebbc3d..42f26d30 100644 --- a/nalgebra-glm/src/common.rs +++ b/nalgebra-glm/src/common.rs @@ -297,13 +297,13 @@ where DefaultAllocator: Alloc { v.map(int_bits_to_float) } -//pub fn isinf(x: &TVec) -> TVec +//pub fn isinf(x: &TVec) -> TVec // where DefaultAllocator: Alloc { // unimplemented!() // //} // -//pub fn isnan(x: &TVec) -> TVec +//pub fn isnan(x: &TVec) -> TVec // where DefaultAllocator: Alloc { // unimplemented!() // @@ -504,7 +504,7 @@ where DefaultAllocator: Alloc { x.map(|x| x.round()) } -//pub fn roundEven(x: &TVec) -> TVec +//pub fn roundEven(x: &TVec) -> TVec // where DefaultAllocator: Alloc { // unimplemented!() //} diff --git a/nalgebra-glm/src/constructors.rs b/nalgebra-glm/src/constructors.rs index 93d06e45..020bbcb4 100644 --- a/nalgebra-glm/src/constructors.rs +++ b/nalgebra-glm/src/constructors.rs @@ -15,28 +15,28 @@ use crate::aliases::{TMat, Qua, TVec1, TVec2, TVec3, TVec4, TMat2, TMat2x3, TMat /// # use nalgebra_glm as glm; /// let v = glm::vec1(true); /// ``` -pub fn vec1(x: N) -> TVec1 { +pub fn vec1(x: N) -> TVec1 { TVec1::new(x) } /// Creates a new 2D vector. -pub fn vec2(x: N, y: N) -> TVec2 { +pub fn vec2(x: N, y: N) -> TVec2 { TVec2::new(x, y) } /// Creates a new 3D vector. -pub fn vec3(x: N, y: N, z: N) -> TVec3 { +pub fn vec3(x: N, y: N, z: N) -> TVec3 { TVec3::new(x, y, z) } /// Creates a new 4D vector. -pub fn vec4(x: N, y: N, z: N, w: N) -> TVec4 { +pub fn vec4(x: N, y: N, z: N, w: N) -> TVec4 { TVec4::new(x, y, z, w) } /// Create a new 2x2 matrix. -pub fn mat2(m11: N, m12: N, +pub fn mat2(m11: N, m12: N, m21: N, m22: N) -> TMat2 { TMat::::new( m11, m12, @@ -45,7 +45,7 @@ pub fn mat2(m11: N, m12: N, } /// Create a new 2x2 matrix. -pub fn mat2x2(m11: N, m12: N, +pub fn mat2x2(m11: N, m12: N, m21: N, m22: N) -> TMat2 { TMat::::new( m11, m12, @@ -54,7 +54,7 @@ pub fn mat2x2(m11: N, m12: N, } /// Create a new 2x3 matrix. -pub fn mat2x3(m11: N, m12: N, m13: N, +pub fn mat2x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> TMat2x3 { TMat::::new( m11, m12, m13, @@ -63,7 +63,7 @@ pub fn mat2x3(m11: N, m12: N, m13: N, } /// Create a new 2x4 matrix. -pub fn mat2x4(m11: N, m12: N, m13: N, m14: N, +pub fn mat2x4(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N) -> TMat2x4 { TMat::::new( m11, m12, m13, m14, @@ -72,7 +72,7 @@ pub fn mat2x4(m11: N, m12: N, m13: N, m14: N, } /// Create a new 3x3 matrix. -pub fn mat3(m11: N, m12: N, m13: N, +pub fn mat3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N) -> TMat3 { TMat::::new( @@ -83,7 +83,7 @@ pub fn mat3(m11: N, m12: N, m13: N, } /// Create a new 3x2 matrix. -pub fn mat3x2(m11: N, m12: N, +pub fn mat3x2(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> TMat3x2 { TMat::::new( @@ -94,7 +94,7 @@ pub fn mat3x2(m11: N, m12: N, } /// Create a new 3x3 matrix. -pub fn mat3x3(m11: N, m12: N, m13: N, +pub fn mat3x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N) -> TMat3 { TMat::::new( @@ -105,7 +105,7 @@ pub fn mat3x3(m11: N, m12: N, m13: N, } /// Create a new 3x4 matrix. -pub fn mat3x4(m11: N, m12: N, m13: N, m14: N, +pub fn mat3x4(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N, m31: N, m32: N, m33: N, m34: N) -> TMat3x4 { TMat::::new( @@ -116,7 +116,7 @@ pub fn mat3x4(m11: N, m12: N, m13: N, m14: N, } /// Create a new 4x2 matrix. -pub fn mat4x2(m11: N, m12: N, +pub fn mat4x2(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N, m41: N, m42: N) -> TMat4x2 { @@ -129,7 +129,7 @@ pub fn mat4x2(m11: N, m12: N, } /// Create a new 4x3 matrix. -pub fn mat4x3(m11: N, m12: N, m13: N, +pub fn mat4x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N, m41: N, m42: N, m43: N) -> TMat4x3 { @@ -142,7 +142,7 @@ pub fn mat4x3(m11: N, m12: N, m13: N, } /// Create a new 4x4 matrix. -pub fn mat4x4(m11: N, m12: N, m13: N, m14: N, +pub fn mat4x4(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N, m31: N, m32: N, m33: N, m34: N, m41: N, m42: N, m43: N, m44: N) -> TMat4 { @@ -155,7 +155,7 @@ pub fn mat4x4(m11: N, m12: N, m13: N, m14: N, } /// Create a new 4x4 matrix. -pub fn mat4(m11: N, m12: N, m13: N, m14: N, +pub fn mat4(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N, m31: N, m32: N, m33: N, m34: N, m41: N, m42: N, m43: N, m44: N) -> TMat4 { diff --git a/nalgebra-glm/src/gtc/bitfield.rs b/nalgebra-glm/src/gtc/bitfield.rs index 5e4f7063..81a1646f 100644 --- a/nalgebra-glm/src/gtc/bitfield.rs +++ b/nalgebra-glm/src/gtc/bitfield.rs @@ -19,7 +19,7 @@ pub fn bitfieldFillOne(Value: IU, FirstBit: i32, BitCount: i32) -> IU { unimplemented!() } -pub fn bitfieldFillOne2(Value: &TVec, FirstBit: i32, BitCount: i32) -> TVec +pub fn bitfieldFillOne2(Value: &TVec, FirstBit: i32, BitCount: i32) -> TVec where DefaultAllocator: Alloc { unimplemented!() } @@ -28,7 +28,7 @@ pub fn bitfieldFillZero(Value: IU, FirstBit: i32, BitCount: i32) -> IU { unimplemented!() } -pub fn bitfieldFillZero2(Value: &TVec, FirstBit: i32, BitCount: i32) -> TVec +pub fn bitfieldFillZero2(Value: &TVec, FirstBit: i32, BitCount: i32) -> TVec where DefaultAllocator: Alloc { unimplemented!() } @@ -113,7 +113,7 @@ pub fn bitfieldRotateLeft(In: IU, Shift: i32) -> IU { unimplemented!() } -pub fn bitfieldRotateLeft2(In: &TVec, Shift: i32) -> TVec +pub fn bitfieldRotateLeft2(In: &TVec, Shift: i32) -> TVec where DefaultAllocator: Alloc { unimplemented!() } @@ -122,7 +122,7 @@ pub fn bitfieldRotateRight(In: IU, Shift: i32) -> IU { unimplemented!() } -pub fn bitfieldRotateRight2(In: &TVec, Shift: i32) -> TVec +pub fn bitfieldRotateRight2(In: &TVec, Shift: i32) -> TVec where DefaultAllocator: Alloc { unimplemented!() } @@ -131,7 +131,7 @@ pub fn mask(Bits: IU) -> IU { unimplemented!() } -pub fn mask2(v: &TVec) -> TVec +pub fn mask2(v: &TVec) -> TVec where DefaultAllocator: Alloc { unimplemented!() } diff --git a/nalgebra-glm/src/gtc/integer.rs b/nalgebra-glm/src/gtc/integer.rs index 146b874c..d5965f38 100644 --- a/nalgebra-glm/src/gtc/integer.rs +++ b/nalgebra-glm/src/gtc/integer.rs @@ -3,7 +3,7 @@ //use crate::traits::{Alloc, Dimension}; //use crate::aliases::TVec; -//pub fn iround(x: &TVec) -> TVec +//pub fn iround(x: &TVec) -> TVec // where DefaultAllocator: Alloc { // x.map(|x| x.round()) //} @@ -12,7 +12,7 @@ // unimplemented!() //} // -//pub fn uround(x: &TVec) -> TVec +//pub fn uround(x: &TVec) -> TVec // where DefaultAllocator: Alloc { // unimplemented!() //} diff --git a/nalgebra-glm/src/gtc/matrix_access.rs b/nalgebra-glm/src/gtc/matrix_access.rs index 2f9bb5fa..bfc0199b 100644 --- a/nalgebra-glm/src/gtc/matrix_access.rs +++ b/nalgebra-glm/src/gtc/matrix_access.rs @@ -10,7 +10,7 @@ use crate::traits::{Alloc, Dimension}; /// * [`row`](fn.row.html) /// * [`set_column`](fn.set_column.html) /// * [`set_row`](fn.set_row.html) -pub fn column( +pub fn column( m: &TMat, index: usize, ) -> TVec @@ -27,7 +27,7 @@ where /// * [`column`](fn.column.html) /// * [`row`](fn.row.html) /// * [`set_row`](fn.set_row.html) -pub fn set_column( +pub fn set_column( m: &TMat, index: usize, x: &TVec, @@ -47,7 +47,7 @@ where /// * [`column`](fn.column.html) /// * [`set_column`](fn.set_column.html) /// * [`set_row`](fn.set_row.html) -pub fn row(m: &TMat, index: usize) -> TVec +pub fn row(m: &TMat, index: usize) -> TVec where DefaultAllocator: Alloc { m.row(index).into_owned().transpose() } @@ -59,7 +59,7 @@ where DefaultAllocator: Alloc { /// * [`column`](fn.column.html) /// * [`row`](fn.row.html) /// * [`set_column`](fn.set_column.html) -pub fn set_row( +pub fn set_row( m: &TMat, index: usize, x: &TVec, diff --git a/nalgebra-glm/src/gtc/packing.rs b/nalgebra-glm/src/gtc/packing.rs index 1306eca3..5d649538 100644 --- a/nalgebra-glm/src/gtc/packing.rs +++ b/nalgebra-glm/src/gtc/packing.rs @@ -49,7 +49,7 @@ pub fn packInt4x8(v: &I8Vec4) -> i32 { unimplemented!() } -pub fn packRGBM(rgb: &TVec3) -> TVec4 { +pub fn packRGBM(rgb: &TVec3) -> TVec4 { unimplemented!() } @@ -155,7 +155,7 @@ pub fn unpackF3x9_E1x5(p: i32) -> Vec3 { unimplemented!() } -pub fn unpackHalf(p: TVec) -> TVec +pub fn unpackHalf(p: TVec) -> TVec where DefaultAllocator: Alloc { unimplemented!() } @@ -192,7 +192,7 @@ pub fn unpackInt4x8(p: i32) -> I8Vec4 { unimplemented!() } -pub fn unpackRGBM(rgbm: &TVec4) -> TVec3 { +pub fn unpackRGBM(rgbm: &TVec4) -> TVec3 { unimplemented!() } diff --git a/nalgebra-glm/src/gtc/round.rs b/nalgebra-glm/src/gtc/round.rs index d1ca295b..21d3a21e 100644 --- a/nalgebra-glm/src/gtc/round.rs +++ b/nalgebra-glm/src/gtc/round.rs @@ -8,7 +8,7 @@ pub fn ceilMultiple(v: T, Multiple: T) -> T { unimplemented!() } -pub fn ceilMultiple2(v: &TVec, Multiple: &TVec) -> TVec +pub fn ceilMultiple2(v: &TVec, Multiple: &TVec) -> TVec where DefaultAllocator: Alloc { unimplemented!() } @@ -17,7 +17,7 @@ pub fn ceilPowerOfTwo(v: IU) -> IU { unimplemented!() } -pub fn ceilPowerOfTwo2(v: &TVec) -> TVec +pub fn ceilPowerOfTwo2(v: &TVec) -> TVec where DefaultAllocator: Alloc { unimplemented!() } @@ -26,7 +26,7 @@ pub fn floorMultiple(v: T, Multiple: T) -> T { unimplemented!() } -pub fn floorMultiple2(v: &TVec, Multiple: &TVec) -> TVec +pub fn floorMultiple2(v: &TVec, Multiple: &TVec) -> TVec where DefaultAllocator: Alloc { unimplemented!() } @@ -35,7 +35,7 @@ pub fn floorPowerOfTwo(v: IU) -> IU { unimplemented!() } -pub fn floorPowerOfTwo2(v: &TVec) -> TVec +pub fn floorPowerOfTwo2(v: &TVec) -> TVec where DefaultAllocator: Alloc { unimplemented!() } @@ -44,12 +44,12 @@ pub fn isMultiple(v: IU, Multiple: IU) -> bool { unimplemented!() } -pub fn isMultiple2(v: &TVec,Multiple: N) -> TVec +pub fn isMultiple2(v: &TVec,Multiple: N) -> TVec where DefaultAllocator: Alloc { unimplemented!() } -pub fn isMultiple3(v: &TVec, Multiple: &TVec) -> TVec +pub fn isMultiple3(v: &TVec, Multiple: &TVec) -> TVec where DefaultAllocator: Alloc { unimplemented!() } @@ -58,7 +58,7 @@ pub fn isPowerOfTwo2(v: IU) -> bool { unimplemented!() } -pub fn isPowerOfTwo(v: &TVec) -> TVec +pub fn isPowerOfTwo(v: &TVec) -> TVec where DefaultAllocator: Alloc { unimplemented!() } @@ -67,7 +67,7 @@ pub fn roundMultiple(v: T, Multiple: T) -> T { unimplemented!() } -pub fn roundMultiple2(v: &TVec, Multiple: &TVec) -> TVec +pub fn roundMultiple2(v: &TVec, Multiple: &TVec) -> TVec where DefaultAllocator: Alloc { unimplemented!() } @@ -76,7 +76,7 @@ pub fn roundPowerOfTwo(v: IU) -> IU { unimplemented!() } -pub fn roundPowerOfTwo2(v: &TVec) -> TVec +pub fn roundPowerOfTwo2(v: &TVec) -> TVec where DefaultAllocator: Alloc { unimplemented!() } diff --git a/nalgebra-glm/src/gtc/type_ptr.rs b/nalgebra-glm/src/gtc/type_ptr.rs index 92309e93..ad9e6f8f 100644 --- a/nalgebra-glm/src/gtc/type_ptr.rs +++ b/nalgebra-glm/src/gtc/type_ptr.rs @@ -7,62 +7,62 @@ use crate::aliases::{ use crate::traits::{Alloc, Dimension, Number}; /// Creates a 2x2 matrix from a slice arranged in column-major order. -pub fn make_mat2(ptr: &[N]) -> TMat2 { +pub fn make_mat2(ptr: &[N]) -> TMat2 { TMat2::from_column_slice(ptr) } /// Creates a 2x2 matrix from a slice arranged in column-major order. -pub fn make_mat2x2(ptr: &[N]) -> TMat2 { +pub fn make_mat2x2(ptr: &[N]) -> TMat2 { TMat2::from_column_slice(ptr) } /// Creates a 2x3 matrix from a slice arranged in column-major order. -pub fn make_mat2x3(ptr: &[N]) -> TMat2x3 { +pub fn make_mat2x3(ptr: &[N]) -> TMat2x3 { TMat2x3::from_column_slice(ptr) } /// Creates a 2x4 matrix from a slice arranged in column-major order. -pub fn make_mat2x4(ptr: &[N]) -> TMat2x4 { +pub fn make_mat2x4(ptr: &[N]) -> TMat2x4 { TMat2x4::from_column_slice(ptr) } /// Creates a 3 matrix from a slice arranged in column-major order. -pub fn make_mat3(ptr: &[N]) -> TMat3 { +pub fn make_mat3(ptr: &[N]) -> TMat3 { TMat3::from_column_slice(ptr) } /// Creates a 3x2 matrix from a slice arranged in column-major order. -pub fn make_mat3x2(ptr: &[N]) -> TMat3x2 { +pub fn make_mat3x2(ptr: &[N]) -> TMat3x2 { TMat3x2::from_column_slice(ptr) } /// Creates a 3x3 matrix from a slice arranged in column-major order. -pub fn make_mat3x3(ptr: &[N]) -> TMat3 { +pub fn make_mat3x3(ptr: &[N]) -> TMat3 { TMat3::from_column_slice(ptr) } /// Creates a 3x4 matrix from a slice arranged in column-major order. -pub fn make_mat3x4(ptr: &[N]) -> TMat3x4 { +pub fn make_mat3x4(ptr: &[N]) -> TMat3x4 { TMat3x4::from_column_slice(ptr) } /// Creates a 4x4 matrix from a slice arranged in column-major order. -pub fn make_mat4(ptr: &[N]) -> TMat4 { +pub fn make_mat4(ptr: &[N]) -> TMat4 { TMat4::from_column_slice(ptr) } /// Creates a 4x2 matrix from a slice arranged in column-major order. -pub fn make_mat4x2(ptr: &[N]) -> TMat4x2 { +pub fn make_mat4x2(ptr: &[N]) -> TMat4x2 { TMat4x2::from_column_slice(ptr) } /// Creates a 4x3 matrix from a slice arranged in column-major order. -pub fn make_mat4x3(ptr: &[N]) -> TMat4x3 { +pub fn make_mat4x3(ptr: &[N]) -> TMat4x3 { TMat4x3::from_column_slice(ptr) } /// Creates a 4x4 matrix from a slice arranged in column-major order. -pub fn make_mat4x4(ptr: &[N]) -> TMat4 { +pub fn make_mat4x4(ptr: &[N]) -> TMat4 { TMat4::from_column_slice(ptr) } @@ -75,8 +75,8 @@ pub fn mat2_to_mat3(m: &TMat2) -> TMat3 { } /// Converts a 3x3 matrix to a 2x2 matrix. -pub fn mat3_to_mat2(m: &TMat3) -> TMat2 { - TMat2::new(m.m11, m.m12, m.m21, m.m22) +pub fn mat3_to_mat2(m: &TMat3) -> TMat2 { + TMat2::new(m.m11.inlined_clone(), m.m12.inlined_clone(), m.m21.inlined_clone(), m.m22.inlined_clone()) } /// Converts a 3x3 matrix to a 4x4 matrix. @@ -90,9 +90,11 @@ pub fn mat3_to_mat4(m: &TMat3) -> TMat4 { } /// Converts a 4x4 matrix to a 3x3 matrix. -pub fn mat4_to_mat3(m: &TMat4) -> TMat3 { +pub fn mat4_to_mat3(m: &TMat4) -> TMat3 { TMat3::new( - m.m11, m.m12, m.m13, m.m21, m.m22, m.m23, m.m31, m.m32, m.m33, + m.m11.inlined_clone(), m.m12.inlined_clone(), m.m13.inlined_clone(), + m.m21.inlined_clone(), m.m22.inlined_clone(), m.m23.inlined_clone(), + m.m31.inlined_clone(), m.m32.inlined_clone(), m.m33.inlined_clone(), ) } @@ -107,8 +109,8 @@ pub fn mat2_to_mat4(m: &TMat2) -> TMat4 { } /// Converts a 4x4 matrix to a 2x2 matrix. -pub fn mat4_to_mat2(m: &TMat4) -> TMat2 { - TMat2::new(m.m11, m.m12, m.m21, m.m22) +pub fn mat4_to_mat2(m: &TMat4) -> TMat2 { + TMat2::new(m.m11.inlined_clone(), m.m12.inlined_clone(), m.m21.inlined_clone(), m.m22.inlined_clone()) } /// Creates a quaternion from a slice arranged as `[x, y, z, w]`. @@ -123,8 +125,8 @@ pub fn make_quat(ptr: &[N]) -> Qua { /// * [`make_vec2`](fn.make_vec2.html) /// * [`make_vec3`](fn.make_vec3.html) /// * [`make_vec4`](fn.make_vec4.html) -pub fn make_vec1(v: &TVec1) -> TVec1 { - *v +pub fn make_vec1(v: &TVec1) -> TVec1 { + v.clone() } /// Creates a 1D vector from another vector. @@ -137,8 +139,8 @@ pub fn make_vec1(v: &TVec1) -> TVec1 { /// * [`vec1_to_vec2`](fn.vec1_to_vec2.html) /// * [`vec1_to_vec3`](fn.vec1_to_vec3.html) /// * [`vec1_to_vec4`](fn.vec1_to_vec4.html) -pub fn vec2_to_vec1(v: &TVec2) -> TVec1 { - TVec1::new(v.x) +pub fn vec2_to_vec1(v: &TVec2) -> TVec1 { + TVec1::new(v.x.inlined_clone()) } /// Creates a 1D vector from another vector. @@ -151,8 +153,8 @@ pub fn vec2_to_vec1(v: &TVec2) -> TVec1 { /// * [`vec1_to_vec2`](fn.vec1_to_vec2.html) /// * [`vec1_to_vec3`](fn.vec1_to_vec3.html) /// * [`vec1_to_vec4`](fn.vec1_to_vec4.html) -pub fn vec3_to_vec1(v: &TVec3) -> TVec1 { - TVec1::new(v.x) +pub fn vec3_to_vec1(v: &TVec3) -> TVec1 { + TVec1::new(v.x.inlined_clone()) } /// Creates a 1D vector from another vector. @@ -165,8 +167,8 @@ pub fn vec3_to_vec1(v: &TVec3) -> TVec1 { /// * [`vec1_to_vec2`](fn.vec1_to_vec2.html) /// * [`vec1_to_vec3`](fn.vec1_to_vec3.html) /// * [`vec1_to_vec4`](fn.vec1_to_vec4.html) -pub fn vec4_to_vec1(v: &TVec4) -> TVec1 { - TVec1::new(v.x) +pub fn vec4_to_vec1(v: &TVec4) -> TVec1 { + TVec1::new(v.x.inlined_clone()) } /// Creates a 2D vector from another vector. @@ -182,7 +184,7 @@ pub fn vec4_to_vec1(v: &TVec4) -> TVec1 { /// * [`vec2_to_vec3`](fn.vec2_to_vec3.html) /// * [`vec2_to_vec4`](fn.vec2_to_vec4.html) pub fn vec1_to_vec2(v: &TVec1) -> TVec2 { - TVec2::new(v.x, N::zero()) + TVec2::new(v.x.inlined_clone(), N::zero()) } /// Creates a 2D vector from another vector. @@ -196,8 +198,8 @@ pub fn vec1_to_vec2(v: &TVec1) -> TVec2 { /// * [`vec2_to_vec2`](fn.vec2_to_vec2.html) /// * [`vec2_to_vec3`](fn.vec2_to_vec3.html) /// * [`vec2_to_vec4`](fn.vec2_to_vec4.html) -pub fn vec2_to_vec2(v: &TVec2) -> TVec2 { - *v +pub fn vec2_to_vec2(v: &TVec2) -> TVec2 { + v.clone() } /// Creates a 2D vector from another vector. @@ -210,8 +212,8 @@ pub fn vec2_to_vec2(v: &TVec2) -> TVec2 { /// * [`vec2_to_vec2`](fn.vec2_to_vec2.html) /// * [`vec2_to_vec3`](fn.vec2_to_vec3.html) /// * [`vec2_to_vec4`](fn.vec2_to_vec4.html) -pub fn vec3_to_vec2(v: &TVec3) -> TVec2 { - TVec2::new(v.x, v.y) +pub fn vec3_to_vec2(v: &TVec3) -> TVec2 { + TVec2::new(v.x.inlined_clone(), v.y.inlined_clone()) } /// Creates a 2D vector from another vector. @@ -224,8 +226,8 @@ pub fn vec3_to_vec2(v: &TVec3) -> TVec2 { /// * [`vec2_to_vec2`](fn.vec2_to_vec2.html) /// * [`vec2_to_vec3`](fn.vec2_to_vec3.html) /// * [`vec2_to_vec4`](fn.vec2_to_vec4.html) -pub fn vec4_to_vec2(v: &TVec4) -> TVec2 { - TVec2::new(v.x, v.y) +pub fn vec4_to_vec2(v: &TVec4) -> TVec2 { + TVec2::new(v.x.inlined_clone(), v.y.inlined_clone()) } /// Creates a 2D vector from a slice. @@ -235,7 +237,7 @@ pub fn vec4_to_vec2(v: &TVec4) -> TVec2 { /// * [`make_vec1`](fn.make_vec1.html) /// * [`make_vec3`](fn.make_vec3.html) /// * [`make_vec4`](fn.make_vec4.html) -pub fn make_vec2(ptr: &[N]) -> TVec2 { +pub fn make_vec2(ptr: &[N]) -> TVec2 { TVec2::from_column_slice(ptr) } @@ -251,7 +253,7 @@ pub fn make_vec2(ptr: &[N]) -> TVec2 { /// * [`vec1_to_vec2`](fn.vec1_to_vec2.html) /// * [`vec1_to_vec4`](fn.vec1_to_vec4.html) pub fn vec1_to_vec3(v: &TVec1) -> TVec3 { - TVec3::new(v.x, N::zero(), N::zero()) + TVec3::new(v.x.inlined_clone(), N::zero(), N::zero()) } /// Creates a 3D vector from another vector. @@ -267,7 +269,7 @@ pub fn vec1_to_vec3(v: &TVec1) -> TVec3 { /// * [`vec3_to_vec2`](fn.vec3_to_vec2.html) /// * [`vec3_to_vec4`](fn.vec3_to_vec4.html) pub fn vec2_to_vec3(v: &TVec2) -> TVec3 { - TVec3::new(v.x, v.y, N::zero()) + TVec3::new(v.x.inlined_clone(), v.y.inlined_clone(), N::zero()) } /// Creates a 3D vector from another vector. @@ -280,8 +282,8 @@ pub fn vec2_to_vec3(v: &TVec2) -> TVec3 { /// * [`vec3_to_vec1`](fn.vec3_to_vec1.html) /// * [`vec3_to_vec2`](fn.vec3_to_vec2.html) /// * [`vec3_to_vec4`](fn.vec3_to_vec4.html) -pub fn vec3_to_vec3(v: &TVec3) -> TVec3 { - *v +pub fn vec3_to_vec3(v: &TVec3) -> TVec3 { + v.clone() } /// Creates a 3D vector from another vector. @@ -294,8 +296,8 @@ pub fn vec3_to_vec3(v: &TVec3) -> TVec3 { /// * [`vec3_to_vec1`](fn.vec3_to_vec1.html) /// * [`vec3_to_vec2`](fn.vec3_to_vec2.html) /// * [`vec3_to_vec4`](fn.vec3_to_vec4.html) -pub fn vec4_to_vec3(v: &TVec4) -> TVec3 { - TVec3::new(v.x, v.y, v.z) +pub fn vec4_to_vec3(v: &TVec4) -> TVec3 { + TVec3::new(v.x.inlined_clone(), v.y.inlined_clone(), v.z.inlined_clone()) } /// Creates a 3D vector from another vector. @@ -305,7 +307,7 @@ pub fn vec4_to_vec3(v: &TVec4) -> TVec3 { /// * [`make_vec1`](fn.make_vec1.html) /// * [`make_vec2`](fn.make_vec2.html) /// * [`make_vec4`](fn.make_vec4.html) -pub fn make_vec3(ptr: &[N]) -> TVec3 { +pub fn make_vec3(ptr: &[N]) -> TVec3 { TVec3::from_column_slice(ptr) } @@ -367,8 +369,8 @@ pub fn vec3_to_vec4(v: &TVec3) -> TVec4 { /// * [`vec4_to_vec1`](fn.vec4_to_vec1.html) /// * [`vec4_to_vec2`](fn.vec4_to_vec2.html) /// * [`vec4_to_vec3`](fn.vec4_to_vec3.html) -pub fn vec4_to_vec4(v: &TVec4) -> TVec4 { - *v +pub fn vec4_to_vec4(v: &TVec4) -> TVec4 { + v.clone() } /// Creates a 4D vector from another vector. @@ -378,18 +380,18 @@ pub fn vec4_to_vec4(v: &TVec4) -> TVec4 { /// * [`make_vec1`](fn.make_vec1.html) /// * [`make_vec2`](fn.make_vec2.html) /// * [`make_vec3`](fn.make_vec3.html) -pub fn make_vec4(ptr: &[N]) -> TVec4 { +pub fn make_vec4(ptr: &[N]) -> TVec4 { TVec4::from_column_slice(ptr) } /// Converts a matrix or vector to a slice arranged in column-major order. -pub fn value_ptr(x: &TMat) -> &[N] +pub fn value_ptr(x: &TMat) -> &[N] where DefaultAllocator: Alloc { x.as_slice() } /// Converts a matrix or vector to a mutable slice arranged in column-major order. -pub fn value_ptr_mut(x: &mut TMat) -> &mut [N] +pub fn value_ptr_mut(x: &mut TMat) -> &mut [N] where DefaultAllocator: Alloc { x.as_mut_slice() } diff --git a/nalgebra-glm/src/gtc/ulp.rs b/nalgebra-glm/src/gtc/ulp.rs index 42ef2d05..07116b15 100644 --- a/nalgebra-glm/src/gtc/ulp.rs +++ b/nalgebra-glm/src/gtc/ulp.rs @@ -7,7 +7,7 @@ pub fn float_distance(x: T, y: T) -> u64 { unimplemented!() } -pub fn float_distance2(x: &TVec2, y: &TVec2) -> TVec { +pub fn float_distance2(x: &TVec2, y: &TVec2) -> TVec { unimplemented!() } diff --git a/nalgebra-glm/src/integer.rs b/nalgebra-glm/src/integer.rs index 3a2641e0..73cae447 100644 --- a/nalgebra-glm/src/integer.rs +++ b/nalgebra-glm/src/integer.rs @@ -7,22 +7,22 @@ pub fn bitCount(v: T) -> i32 { unimplemented!() } -pub fn bitCount2(v: &TVec) -> TVec +pub fn bitCount2(v: &TVec) -> TVec where DefaultAllocator: Alloc { unimplemented!() } -pub fn bitfieldExtract(Value: &TVec, Offset: i32, Bits: i32) -> TVec +pub fn bitfieldExtract(Value: &TVec, Offset: i32, Bits: i32) -> TVec where DefaultAllocator: Alloc { unimplemented!() } -pub fn bitfieldInsert(Base: &TVec, Insert: &TVec, Offset: i32, Bits: i32) -> TVec +pub fn bitfieldInsert(Base: &TVec, Insert: &TVec, Offset: i32, Bits: i32) -> TVec where DefaultAllocator: Alloc { unimplemented!() } -pub fn bitfieldReverse(v: &TVec) -> TVec +pub fn bitfieldReverse(v: &TVec) -> TVec where DefaultAllocator: Alloc { unimplemented!() } @@ -31,7 +31,7 @@ pub fn findLSB(x: IU) -> u32 { unimplemented!() } -pub fn findLSB2(v: &TVec) -> TVec +pub fn findLSB2(v: &TVec) -> TVec where DefaultAllocator: Alloc { unimplemented!() } @@ -40,27 +40,27 @@ pub fn findMSB(x: IU) -> i32 { unimplemented!() } -pub fn findMSB2(v: &TVec) -> TVec +pub fn findMSB2(v: &TVec) -> TVec where DefaultAllocator: Alloc { unimplemented!() } -pub fn imulExtended(x: &TVec, y: &TVec, msb: &TVec, lsb: &TVec) +pub fn imulExtended(x: &TVec, y: &TVec, msb: &TVec, lsb: &TVec) where DefaultAllocator: Alloc { unimplemented!() } -pub fn uaddCarry(x: &TVec, y: &TVec, carry: &TVec) -> TVec +pub fn uaddCarry(x: &TVec, y: &TVec, carry: &TVec) -> TVec where DefaultAllocator: Alloc { unimplemented!() } -pub fn umulExtended(x: &TVec, y: &TVec, msb: &TVec, lsb: &TVec) +pub fn umulExtended(x: &TVec, y: &TVec, msb: &TVec, lsb: &TVec) where DefaultAllocator: Alloc { unimplemented!() } -pub fn usubBorrow(x: &TVec, y: &TVec, borrow: &TVec) -> TVec +pub fn usubBorrow(x: &TVec, y: &TVec, borrow: &TVec) -> TVec where DefaultAllocator: Alloc { unimplemented!() } diff --git a/nalgebra-glm/src/matrix.rs b/nalgebra-glm/src/matrix.rs index e83687dc..c9c177b4 100644 --- a/nalgebra-glm/src/matrix.rs +++ b/nalgebra-glm/src/matrix.rs @@ -40,7 +40,7 @@ where } /// The transpose of the matrix `m`. -pub fn transpose(x: &TMat) -> TMat +pub fn transpose(x: &TMat) -> TMat where DefaultAllocator: Alloc { x.transpose() } diff --git a/nalgebra-glm/src/packing.rs b/nalgebra-glm/src/packing.rs index 641ad159..e0169cbe 100644 --- a/nalgebra-glm/src/packing.rs +++ b/nalgebra-glm/src/packing.rs @@ -3,50 +3,50 @@ use na::Scalar; use crate::aliases::{Vec2, Vec4, UVec2}; -pub fn packDouble2x32(v: &UVec2) -> f64 { +pub fn packDouble2x32(v: &UVec2) -> f64 { unimplemented!() } -pub fn packHalf2x16(v: &Vec2) -> u32 { +pub fn packHalf2x16(v: &Vec2) -> u32 { unimplemented!() } -pub fn packSnorm2x16(v: &Vec2) -> u32 { +pub fn packSnorm2x16(v: &Vec2) -> u32 { unimplemented!() } -pub fn packSnorm4x8(v: &Vec4) -> u32 { +pub fn packSnorm4x8(v: &Vec4) -> u32 { unimplemented!() } -pub fn packUnorm2x16(v: &Vec2) -> u32 { +pub fn packUnorm2x16(v: &Vec2) -> u32 { unimplemented!() } -pub fn packUnorm4x8(v: &Vec4) -> u32 { +pub fn packUnorm4x8(v: &Vec4) -> u32 { unimplemented!() } -pub fn unpackDouble2x32(v: f64) -> UVec2 { +pub fn unpackDouble2x32(v: f64) -> UVec2 { unimplemented!() } -pub fn unpackHalf2x16(v: u32) -> Vec2 { +pub fn unpackHalf2x16(v: u32) -> Vec2 { unimplemented!() } -pub fn unpackSnorm2x16(p: u32) -> Vec2 { +pub fn unpackSnorm2x16(p: u32) -> Vec2 { unimplemented!() } -pub fn unpackSnorm4x8(p: u32) -> Vec4 { +pub fn unpackSnorm4x8(p: u32) -> Vec4 { unimplemented!() } -pub fn unpackUnorm2x16(p: u32) -> Vec2 { +pub fn unpackUnorm2x16(p: u32) -> Vec2 { unimplemented!() } -pub fn unpackUnorm4x8(p: u32) -> Vec4 { +pub fn unpackUnorm4x8(p: u32) -> Vec4 { unimplemented!() } diff --git a/nalgebra-glm/src/traits.rs b/nalgebra-glm/src/traits.rs index ac3aa667..15efb72b 100644 --- a/nalgebra-glm/src/traits.rs +++ b/nalgebra-glm/src/traits.rs @@ -20,7 +20,7 @@ impl + Signed + Fr {} #[doc(hidden)] -pub trait Alloc: +pub trait Alloc: Allocator + Allocator + Allocator @@ -50,7 +50,7 @@ pub trait Alloc: { } -impl Alloc for T where T: Allocator +impl Alloc for T where T: Allocator + Allocator + Allocator + Allocator diff --git a/nalgebra-lapack/src/cholesky.rs b/nalgebra-lapack/src/cholesky.rs index 2014da76..7dce3a13 100644 --- a/nalgebra-lapack/src/cholesky.rs +++ b/nalgebra-lapack/src/cholesky.rs @@ -28,7 +28,7 @@ use lapack; )) )] #[derive(Clone, Debug)] -pub struct Cholesky +pub struct Cholesky where DefaultAllocator: Allocator { l: MatrixN, diff --git a/nalgebra-lapack/src/eigen.rs b/nalgebra-lapack/src/eigen.rs index 0db48fc1..c645e228 100644 --- a/nalgebra-lapack/src/eigen.rs +++ b/nalgebra-lapack/src/eigen.rs @@ -33,7 +33,7 @@ use lapack; )) )] #[derive(Clone, Debug)] -pub struct Eigen +pub struct Eigen where DefaultAllocator: Allocator + Allocator { /// The eigenvalues of the decomposed matrix. @@ -311,7 +311,7 @@ where DefaultAllocator: Allocator + Allocator */ /// Trait implemented by scalar type for which Lapack function exist to compute the /// eigendecomposition. -pub trait EigenScalar: Scalar + Copy { +pub trait EigenScalar: Scalar + Clone { #[allow(missing_docs)] fn xgeev( jobvl: u8, diff --git a/nalgebra-lapack/src/hessenberg.rs b/nalgebra-lapack/src/hessenberg.rs index 8048bfcc..92ec6cda 100644 --- a/nalgebra-lapack/src/hessenberg.rs +++ b/nalgebra-lapack/src/hessenberg.rs @@ -30,7 +30,7 @@ use lapack; )) )] #[derive(Clone, Debug)] -pub struct Hessenberg> +pub struct Hessenberg> where DefaultAllocator: Allocator + Allocator> { h: MatrixN, diff --git a/nalgebra-lapack/src/lu.rs b/nalgebra-lapack/src/lu.rs index b087aea7..a636a722 100644 --- a/nalgebra-lapack/src/lu.rs +++ b/nalgebra-lapack/src/lu.rs @@ -37,7 +37,7 @@ use lapack; )) )] #[derive(Clone, Debug)] -pub struct LU, C: Dim> +pub struct LU, C: Dim> where DefaultAllocator: Allocator> + Allocator { lu: MatrixMN, diff --git a/nalgebra-lapack/src/qr.rs b/nalgebra-lapack/src/qr.rs index 58a040d5..7aa10cb5 100644 --- a/nalgebra-lapack/src/qr.rs +++ b/nalgebra-lapack/src/qr.rs @@ -33,7 +33,7 @@ use lapack; )) )] #[derive(Clone, Debug)] -pub struct QR, C: Dim> +pub struct QR, C: Dim> where DefaultAllocator: Allocator + Allocator> { qr: MatrixMN, diff --git a/nalgebra-lapack/src/schur.rs b/nalgebra-lapack/src/schur.rs index e61a22ea..69d0a29a 100644 --- a/nalgebra-lapack/src/schur.rs +++ b/nalgebra-lapack/src/schur.rs @@ -33,7 +33,7 @@ use lapack; )) )] #[derive(Clone, Debug)] -pub struct Schur +pub struct Schur where DefaultAllocator: Allocator + Allocator { re: VectorN, @@ -162,7 +162,7 @@ where DefaultAllocator: Allocator + Allocator * */ /// Trait implemented by scalars for which Lapack implements the RealField Schur decomposition. -pub trait SchurScalar: Scalar + Copy { +pub trait SchurScalar: Scalar + Clone { #[allow(missing_docs)] fn xgees( jobvs: u8, diff --git a/nalgebra-lapack/src/svd.rs b/nalgebra-lapack/src/svd.rs index 1cd0d24b..ac77fba1 100644 --- a/nalgebra-lapack/src/svd.rs +++ b/nalgebra-lapack/src/svd.rs @@ -36,7 +36,7 @@ use lapack; )) )] #[derive(Clone, Debug)] -pub struct SVD, C: Dim> +pub struct SVD, C: Dim> where DefaultAllocator: Allocator + Allocator> + Allocator { /// The left-singular vectors `U` of this SVD. @@ -57,7 +57,7 @@ where /// Trait implemented by floats (`f32`, `f64`) and complex floats (`Complex`, `Complex`) /// supported by the Singular Value Decompotition. -pub trait SVDScalar, C: Dim>: Scalar + Copy +pub trait SVDScalar, C: Dim>: Scalar + Clone where DefaultAllocator: Allocator + Allocator + Allocator> diff --git a/nalgebra-lapack/src/symmetric_eigen.rs b/nalgebra-lapack/src/symmetric_eigen.rs index d50ee805..eccdf0f7 100644 --- a/nalgebra-lapack/src/symmetric_eigen.rs +++ b/nalgebra-lapack/src/symmetric_eigen.rs @@ -35,7 +35,7 @@ use lapack; )) )] #[derive(Clone, Debug)] -pub struct SymmetricEigen +pub struct SymmetricEigen where DefaultAllocator: Allocator + Allocator { /// The eigenvectors of the decomposed matrix. @@ -169,7 +169,7 @@ where DefaultAllocator: Allocator + Allocator */ /// Trait implemented by scalars for which Lapack implements the eigendecomposition of symmetric /// real matrices. -pub trait SymmetricEigenScalar: Scalar + Copy { +pub trait SymmetricEigenScalar: Scalar + Clone { #[allow(missing_docs)] fn xsyev( jobz: u8, diff --git a/src/base/allocator.rs b/src/base/allocator.rs index 246f3620..3625b059 100644 --- a/src/base/allocator.rs +++ b/src/base/allocator.rs @@ -16,7 +16,7 @@ use crate::base::{DefaultAllocator, Scalar}; /// /// Every allocator must be both static and dynamic. Though not all implementations may share the /// same `Buffer` type. -pub trait Allocator: Any + Sized { +pub trait Allocator: Any + Sized { /// The type of buffer this allocator can instanciate. type Buffer: ContiguousStorageMut + Clone; @@ -33,7 +33,7 @@ pub trait Allocator: Any + Sized { /// A matrix reallocator. Changes the size of the memory buffer that initially contains (RFrom × /// CFrom) elements to a smaller or larger size (RTo, CTo). -pub trait Reallocator: +pub trait Reallocator: Allocator + Allocator { /// Reallocates a buffer of shape `(RTo, CTo)`, possibly reusing a previously allocated buffer @@ -65,7 +65,7 @@ where R2: Dim, C1: Dim, C2: Dim, - N: Scalar + Copy, + N: Scalar + Clone, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { } @@ -76,7 +76,7 @@ where R2: Dim, C1: Dim, C2: Dim, - N: Scalar + Copy, + N: Scalar + Clone, DefaultAllocator: Allocator + Allocator, SameShapeC>, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, {} @@ -88,7 +88,7 @@ pub trait SameShapeVectorAllocator: where R1: Dim, R2: Dim, - N: Scalar + Copy, + N: Scalar + Clone, ShapeConstraint: SameNumberOfRows, { } @@ -97,7 +97,7 @@ impl SameShapeVectorAllocator for DefaultAllocator where R1: Dim, R2: Dim, - N: Scalar + Copy, + N: Scalar + Clone, DefaultAllocator: Allocator + Allocator>, ShapeConstraint: SameNumberOfRows, {} diff --git a/src/base/array_storage.rs b/src/base/array_storage.rs index 17247356..ccddcce6 100644 --- a/src/base/array_storage.rs +++ b/src/base/array_storage.rs @@ -154,7 +154,7 @@ where unsafe impl Storage for ArrayStorage where - N: Scalar + Copy, + N: Scalar + Clone, R: DimName, C: DimName, R::Value: Mul, @@ -206,7 +206,7 @@ where unsafe impl StorageMut for ArrayStorage where - N: Scalar + Copy, + N: Scalar + Clone, R: DimName, C: DimName, R::Value: Mul, @@ -226,7 +226,7 @@ where unsafe impl ContiguousStorage for ArrayStorage where - N: Scalar + Copy, + N: Scalar + Clone, R: DimName, C: DimName, R::Value: Mul, @@ -236,7 +236,7 @@ where unsafe impl ContiguousStorageMut for ArrayStorage where - N: Scalar + Copy, + N: Scalar + Clone, R: DimName, C: DimName, R::Value: Mul, @@ -253,7 +253,7 @@ where #[cfg(feature = "serde-serialize")] impl Serialize for ArrayStorage where - N: Scalar + Copy + Serialize, + N: Scalar + Clone + Serialize, R: DimName, C: DimName, R::Value: Mul, @@ -274,7 +274,7 @@ where #[cfg(feature = "serde-serialize")] impl<'a, N, R, C> Deserialize<'a> for ArrayStorage where - N: Scalar + Copy + Deserialize<'a>, + N: Scalar + Clone + Deserialize<'a>, R: DimName, C: DimName, R::Value: Mul, @@ -295,7 +295,7 @@ struct ArrayStorageVisitor { #[cfg(feature = "serde-serialize")] impl ArrayStorageVisitor where - N: Scalar + Copy, + N: Scalar + Clone, R: DimName, C: DimName, R::Value: Mul, @@ -312,7 +312,7 @@ where #[cfg(feature = "serde-serialize")] impl<'a, N, R, C> Visitor<'a> for ArrayStorageVisitor where - N: Scalar + Copy + Deserialize<'a>, + N: Scalar + Clone + Deserialize<'a>, R: DimName, C: DimName, R::Value: Mul, diff --git a/src/base/blas.rs b/src/base/blas.rs index a999b6eb..5cdc52dc 100644 --- a/src/base/blas.rs +++ b/src/base/blas.rs @@ -48,7 +48,7 @@ impl> Vector { } } -impl> Vector { +impl> Vector { /// Computes the index and value of the vector component with the largest value. /// /// # Examples: @@ -74,7 +74,7 @@ impl> Vector { } } - (the_i, *the_max) + (the_i, the_max.inlined_clone()) } /// Computes the index of the vector component with the largest value. @@ -145,7 +145,7 @@ impl> Vector { } } - (the_i, *the_min) + (the_i, the_min.inlined_clone()) } /// Computes the index of the vector component with the smallest value. @@ -230,7 +230,7 @@ impl> Matrix { } -impl> Matrix { +impl> Matrix { /// Computes the index of the matrix component with the largest absolute value. /// /// # Examples: @@ -264,7 +264,7 @@ impl } impl> Matrix -where N: Scalar + Copy + Zero + ClosedAdd + ClosedMul +where N: Scalar + Clone + Zero + ClosedAdd + ClosedMul { #[inline(always)] fn dotx(&self, rhs: &Matrix, conjugate: impl Fn(N) -> N) -> N @@ -281,27 +281,27 @@ where N: Scalar + Copy + Zero + ClosedAdd + ClosedMul // because the `for` loop below won't be very efficient on those. if (R::is::() || R2::is::()) && (C::is::() || C2::is::()) { unsafe { - let a = conjugate(*self.get_unchecked((0, 0))) * *rhs.get_unchecked((0, 0)); - let b = conjugate(*self.get_unchecked((1, 0))) * *rhs.get_unchecked((1, 0)); + let a = conjugate(self.get_unchecked((0, 0)).inlined_clone()) * rhs.get_unchecked((0, 0)).inlined_clone(); + let b = conjugate(self.get_unchecked((1, 0)).inlined_clone()) * rhs.get_unchecked((1, 0)).inlined_clone(); return a + b; } } if (R::is::() || R2::is::()) && (C::is::() || C2::is::()) { unsafe { - let a = conjugate(*self.get_unchecked((0, 0))) * *rhs.get_unchecked((0, 0)); - let b = conjugate(*self.get_unchecked((1, 0))) * *rhs.get_unchecked((1, 0)); - let c = conjugate(*self.get_unchecked((2, 0))) * *rhs.get_unchecked((2, 0)); + let a = conjugate(self.get_unchecked((0, 0)).inlined_clone()) * rhs.get_unchecked((0, 0)).inlined_clone(); + let b = conjugate(self.get_unchecked((1, 0)).inlined_clone()) * rhs.get_unchecked((1, 0)).inlined_clone(); + let c = conjugate(self.get_unchecked((2, 0)).inlined_clone()) * rhs.get_unchecked((2, 0)).inlined_clone(); return a + b + c; } } if (R::is::() || R2::is::()) && (C::is::() || C2::is::()) { unsafe { - let mut a = conjugate(*self.get_unchecked((0, 0))) * *rhs.get_unchecked((0, 0)); - let mut b = conjugate(*self.get_unchecked((1, 0))) * *rhs.get_unchecked((1, 0)); - let c = conjugate(*self.get_unchecked((2, 0))) * *rhs.get_unchecked((2, 0)); - let d = conjugate(*self.get_unchecked((3, 0))) * *rhs.get_unchecked((3, 0)); + let mut a = conjugate(self.get_unchecked((0, 0)).inlined_clone()) * rhs.get_unchecked((0, 0)).inlined_clone(); + let mut b = conjugate(self.get_unchecked((1, 0)).inlined_clone()) * rhs.get_unchecked((1, 0)).inlined_clone(); + let c = conjugate(self.get_unchecked((2, 0)).inlined_clone()) * rhs.get_unchecked((2, 0)).inlined_clone(); + let d = conjugate(self.get_unchecked((3, 0)).inlined_clone()) * rhs.get_unchecked((3, 0)).inlined_clone(); a += c; b += d; @@ -341,14 +341,14 @@ where N: Scalar + Copy + Zero + ClosedAdd + ClosedMul acc7 = N::zero(); while self.nrows() - i >= 8 { - acc0 += unsafe { conjugate(*self.get_unchecked((i + 0, j))) * *rhs.get_unchecked((i + 0, j)) }; - acc1 += unsafe { conjugate(*self.get_unchecked((i + 1, j))) * *rhs.get_unchecked((i + 1, j)) }; - acc2 += unsafe { conjugate(*self.get_unchecked((i + 2, j))) * *rhs.get_unchecked((i + 2, j)) }; - acc3 += unsafe { conjugate(*self.get_unchecked((i + 3, j))) * *rhs.get_unchecked((i + 3, j)) }; - acc4 += unsafe { conjugate(*self.get_unchecked((i + 4, j))) * *rhs.get_unchecked((i + 4, j)) }; - acc5 += unsafe { conjugate(*self.get_unchecked((i + 5, j))) * *rhs.get_unchecked((i + 5, j)) }; - acc6 += unsafe { conjugate(*self.get_unchecked((i + 6, j))) * *rhs.get_unchecked((i + 6, j)) }; - acc7 += unsafe { conjugate(*self.get_unchecked((i + 7, j))) * *rhs.get_unchecked((i + 7, j)) }; + acc0 += unsafe { conjugate(self.get_unchecked((i + 0, j)).inlined_clone()) * rhs.get_unchecked((i + 0, j)).inlined_clone() }; + acc1 += unsafe { conjugate(self.get_unchecked((i + 1, j)).inlined_clone()) * rhs.get_unchecked((i + 1, j)).inlined_clone() }; + acc2 += unsafe { conjugate(self.get_unchecked((i + 2, j)).inlined_clone()) * rhs.get_unchecked((i + 2, j)).inlined_clone() }; + acc3 += unsafe { conjugate(self.get_unchecked((i + 3, j)).inlined_clone()) * rhs.get_unchecked((i + 3, j)).inlined_clone() }; + acc4 += unsafe { conjugate(self.get_unchecked((i + 4, j)).inlined_clone()) * rhs.get_unchecked((i + 4, j)).inlined_clone() }; + acc5 += unsafe { conjugate(self.get_unchecked((i + 5, j)).inlined_clone()) * rhs.get_unchecked((i + 5, j)).inlined_clone() }; + acc6 += unsafe { conjugate(self.get_unchecked((i + 6, j)).inlined_clone()) * rhs.get_unchecked((i + 6, j)).inlined_clone() }; + acc7 += unsafe { conjugate(self.get_unchecked((i + 7, j)).inlined_clone()) * rhs.get_unchecked((i + 7, j)).inlined_clone() }; i += 8; } @@ -358,7 +358,7 @@ where N: Scalar + Copy + Zero + ClosedAdd + ClosedMul res += acc3 + acc7; for k in i..self.nrows() { - res += unsafe { conjugate(*self.get_unchecked((k, j))) * *rhs.get_unchecked((k, j)) } + res += unsafe { conjugate(self.get_unchecked((k, j)).inlined_clone()) * rhs.get_unchecked((k, j)).inlined_clone() } } } @@ -460,7 +460,7 @@ where N: Scalar + Copy + Zero + ClosedAdd + ClosedMul for j in 0..self.nrows() { for i in 0..self.ncols() { - res += unsafe { *self.get_unchecked((j, i)) * *rhs.get_unchecked((i, j)) } + res += unsafe { self.get_unchecked((j, i)).inlined_clone() * rhs.get_unchecked((i, j)).inlined_clone() } } } @@ -469,27 +469,27 @@ where N: Scalar + Copy + Zero + ClosedAdd + ClosedMul } fn array_axcpy(y: &mut [N], a: N, x: &[N], c: N, beta: N, stride1: usize, stride2: usize, len: usize) -where N: Scalar + Copy + Zero + ClosedAdd + ClosedMul { +where N: Scalar + Clone + Zero + ClosedAdd + ClosedMul { for i in 0..len { unsafe { let y = y.get_unchecked_mut(i * stride1); - *y = a * *x.get_unchecked(i * stride2) * c + beta * *y; + *y = a.inlined_clone() * x.get_unchecked(i * stride2).inlined_clone() * c.inlined_clone() + beta.inlined_clone() * y.inlined_clone(); } } } fn array_axc(y: &mut [N], a: N, x: &[N], c: N, stride1: usize, stride2: usize, len: usize) -where N: Scalar + Copy + Zero + ClosedAdd + ClosedMul { +where N: Scalar + Clone + Zero + ClosedAdd + ClosedMul { for i in 0..len { unsafe { - *y.get_unchecked_mut(i * stride1) = a * *x.get_unchecked(i * stride2) * c; + *y.get_unchecked_mut(i * stride1) = a.inlined_clone() * x.get_unchecked(i * stride2).inlined_clone() * c.inlined_clone(); } } } impl Vector where - N: Scalar + Copy + Zero + ClosedAdd + ClosedMul, + N: Scalar + Clone + Zero + ClosedAdd + ClosedMul, S: StorageMut, { /// Computes `self = a * x * c + b * self`. @@ -602,14 +602,14 @@ where // FIXME: avoid bound checks. let col2 = a.column(0); - let val = unsafe { *x.vget_unchecked(0) }; - self.axcpy(alpha, &col2, val, beta); + let val = unsafe { x.vget_unchecked(0).inlined_clone() }; + self.axcpy(alpha.inlined_clone(), &col2, val, beta); for j in 1..ncols2 { let col2 = a.column(j); - let val = unsafe { *x.vget_unchecked(j) }; + let val = unsafe { x.vget_unchecked(j).inlined_clone() }; - self.axcpy(alpha, &col2, val, N::one()); + self.axcpy(alpha.inlined_clone(), &col2, val, N::one()); } } @@ -647,9 +647,9 @@ where // FIXME: avoid bound checks. let col2 = a.column(0); - let val = unsafe { *x.vget_unchecked(0) }; - self.axpy(alpha * val, &col2, beta); - self[0] += alpha * dot(&a.slice_range(1.., 0), &x.rows_range(1..)); + let val = unsafe { x.vget_unchecked(0).inlined_clone() }; + self.axpy(alpha.inlined_clone() * val, &col2, beta); + self[0] += alpha.inlined_clone() * dot(&a.slice_range(1.., 0), &x.rows_range(1..)); for j in 1..dim2 { let col2 = a.column(j); @@ -657,11 +657,11 @@ where let val; unsafe { - val = *x.vget_unchecked(j); - *self.vget_unchecked_mut(j) += alpha * dot; + val = x.vget_unchecked(j).inlined_clone(); + *self.vget_unchecked_mut(j) += alpha.inlined_clone() * dot; } self.rows_range_mut(j + 1..) - .axpy(alpha * val, &col2.rows_range(j + 1..), N::one()); + .axpy(alpha.inlined_clone() * val, &col2.rows_range(j + 1..), N::one()); } } @@ -804,12 +804,12 @@ where if beta.is_zero() { for j in 0..ncols2 { let val = unsafe { self.vget_unchecked_mut(j) }; - *val = alpha * dot(&a.column(j), x) + *val = alpha.inlined_clone() * dot(&a.column(j), x) } } else { for j in 0..ncols2 { let val = unsafe { self.vget_unchecked_mut(j) }; - *val = alpha * dot(&a.column(j), x) + beta * *val; + *val = alpha.inlined_clone() * dot(&a.column(j), x) + beta.inlined_clone() * val.inlined_clone(); } } } @@ -886,7 +886,7 @@ where } impl> Matrix -where N: Scalar + Copy + Zero + ClosedAdd + ClosedMul +where N: Scalar + Clone + Zero + ClosedAdd + ClosedMul { #[inline(always)] fn gerx( @@ -913,8 +913,8 @@ where N: Scalar + Copy + Zero + ClosedAdd + ClosedMul for j in 0..ncols1 { // FIXME: avoid bound checks. - let val = unsafe { conjugate(*y.vget_unchecked(j)) }; - self.column_mut(j).axpy(alpha * val, x, beta); + let val = unsafe { conjugate(y.vget_unchecked(j).inlined_clone()) }; + self.column_mut(j).axpy(alpha.inlined_clone() * val, x, beta.inlined_clone()); } } @@ -1128,7 +1128,7 @@ where N: Scalar + Copy + Zero + ClosedAdd + ClosedMul for j1 in 0..ncols1 { // FIXME: avoid bound checks. - self.column_mut(j1).gemv(alpha, a, &b.column(j1), beta); + self.column_mut(j1).gemv(alpha.inlined_clone(), a, &b.column(j1), beta.inlined_clone()); } } @@ -1185,7 +1185,7 @@ where N: Scalar + Copy + Zero + ClosedAdd + ClosedMul for j1 in 0..ncols1 { // FIXME: avoid bound checks. - self.column_mut(j1).gemv_tr(alpha, a, &b.column(j1), beta); + self.column_mut(j1).gemv_tr(alpha.inlined_clone(), a, &b.column(j1), beta.inlined_clone()); } } @@ -1249,7 +1249,7 @@ where N: Scalar + Copy + Zero + ClosedAdd + ClosedMul } impl> Matrix -where N: Scalar + Copy + Zero + ClosedAdd + ClosedMul +where N: Scalar + Clone + Zero + ClosedAdd + ClosedMul { #[inline(always)] fn xxgerx( @@ -1276,13 +1276,13 @@ where N: Scalar + Copy + Zero + ClosedAdd + ClosedMul assert!(dim1 == dim2 && dim1 == dim3, "ger: dimensions mismatch."); for j in 0..dim1 { - let val = unsafe { conjugate(*y.vget_unchecked(j)) }; + let val = unsafe { conjugate(y.vget_unchecked(j).inlined_clone()) }; let subdim = Dynamic::new(dim1 - j); // FIXME: avoid bound checks. self.generic_slice_mut((j, j), (subdim, U1)).axpy( - alpha * val, + alpha.inlined_clone() * val, &x.rows_range(j..), - beta, + beta.inlined_clone(), ); } } @@ -1396,7 +1396,7 @@ where N: Scalar + Copy + Zero + ClosedAdd + ClosedMul } impl> SquareMatrix -where N: Scalar + Copy + Zero + One + ClosedAdd + ClosedMul +where N: Scalar + Clone + Zero + One + ClosedAdd + ClosedMul { /// Computes the quadratic form `self = alpha * lhs * mid * lhs.transpose() + beta * self`. /// @@ -1442,11 +1442,11 @@ where N: Scalar + Copy + Zero + One + ClosedAdd + ClosedMul ShapeConstraint: DimEq + DimEq + DimEq + DimEq, { work.gemv(N::one(), lhs, &mid.column(0), N::zero()); - self.ger(alpha, work, &lhs.column(0), beta); + self.ger(alpha.inlined_clone(), work, &lhs.column(0), beta); for j in 1..mid.ncols() { work.gemv(N::one(), lhs, &mid.column(j), N::zero()); - self.ger(alpha, work, &lhs.column(j), N::one()); + self.ger(alpha.inlined_clone(), work, &lhs.column(j), N::one()); } } @@ -1534,11 +1534,11 @@ where N: Scalar + Copy + Zero + One + ClosedAdd + ClosedMul DimEq + DimEq + DimEq + AreMultipliable, { work.gemv(N::one(), mid, &rhs.column(0), N::zero()); - self.column_mut(0).gemv_tr(alpha, &rhs, work, beta); + self.column_mut(0).gemv_tr(alpha.inlined_clone(), &rhs, work, beta.inlined_clone()); for j in 1..rhs.ncols() { work.gemv(N::one(), mid, &rhs.column(j), N::zero()); - self.column_mut(j).gemv_tr(alpha, &rhs, work, beta); + self.column_mut(j).gemv_tr(alpha.inlined_clone(), &rhs, work, beta.inlined_clone()); } } diff --git a/src/base/cg.rs b/src/base/cg.rs index 5908c111..262ffecf 100644 --- a/src/base/cg.rs +++ b/src/base/cg.rs @@ -23,7 +23,7 @@ use alga::linear::Transformation; impl MatrixN where - N: Scalar + Copy + Ring, + N: Scalar + Clone + Ring, DefaultAllocator: Allocator, { /// Creates a new homogeneous matrix that applies the same scaling factor on each dimension. @@ -44,7 +44,7 @@ where { let mut res = Self::one(); for i in 0..scaling.len() { - res[(i, i)] = scaling[i]; + res[(i, i)] = scaling[i].inlined_clone(); } res @@ -153,7 +153,7 @@ impl Matrix4 { } } -impl> SquareMatrix { +impl> SquareMatrix { /// Computes the transformation equal to `self` followed by an uniform scaling factor. #[inline] pub fn append_scaling(&self, scaling: N) -> MatrixN @@ -240,7 +240,7 @@ impl> SquareMatrix> SquareMatrix { +impl> SquareMatrix { /// Computes in-place the transformation equal to `self` followed by an uniform scaling factor. #[inline] pub fn append_scaling_mut(&mut self, scaling: N) @@ -266,7 +266,7 @@ impl> SquareMatrix(i); - to_scale *= scaling[i]; + to_scale *= scaling[i].inlined_clone(); } } @@ -281,7 +281,7 @@ impl> SquareMatrix(i); - to_scale *= scaling[i]; + to_scale *= scaling[i].inlined_clone(); } } @@ -294,7 +294,7 @@ impl> SquareMatrix = MatrixSum; -impl> Matrix { +impl> Matrix { /// Computes the component-wise absolute value. /// /// # Example @@ -45,7 +45,7 @@ impl> Matrix { macro_rules! component_binop_impl( ($($binop: ident, $binop_mut: ident, $binop_assign: ident, $cmpy: ident, $Trait: ident . $op: ident . $op_assign: ident, $desc:expr, $desc_cmpy:expr, $desc_mut:expr);* $(;)*) => {$( - impl> Matrix { + impl> Matrix { #[doc = $desc] #[inline] pub fn $binop(&self, rhs: &Matrix) -> MatrixComponentOp @@ -61,7 +61,7 @@ macro_rules! component_binop_impl( for j in 0 .. res.ncols() { for i in 0 .. res.nrows() { unsafe { - res.get_unchecked_mut((i, j)).$op_assign(*rhs.get_unchecked((i, j))); + res.get_unchecked_mut((i, j)).$op_assign(rhs.get_unchecked((i, j)).inlined_clone()); } } } @@ -70,7 +70,7 @@ macro_rules! component_binop_impl( } } - impl> Matrix { + impl> Matrix { // componentwise binop plus Y. #[doc = $desc_cmpy] #[inline] @@ -89,7 +89,7 @@ macro_rules! component_binop_impl( for j in 0 .. self.ncols() { for i in 0 .. self.nrows() { unsafe { - let res = alpha * a.get_unchecked((i, j)).$op(*b.get_unchecked((i, j))); + let res = alpha.inlined_clone() * a.get_unchecked((i, j)).inlined_clone().$op(b.get_unchecked((i, j)).inlined_clone()); *self.get_unchecked_mut((i, j)) = res; } } @@ -99,8 +99,8 @@ macro_rules! component_binop_impl( for j in 0 .. self.ncols() { for i in 0 .. self.nrows() { unsafe { - let res = alpha * a.get_unchecked((i, j)).$op(*b.get_unchecked((i, j))); - *self.get_unchecked_mut((i, j)) = beta * *self.get_unchecked((i, j)) + res; + let res = alpha.inlined_clone() * a.get_unchecked((i, j)).inlined_clone().$op(b.get_unchecked((i, j)).inlined_clone()); + *self.get_unchecked_mut((i, j)) = beta.inlined_clone() * self.get_unchecked((i, j)).inlined_clone() + res; } } } @@ -121,7 +121,7 @@ macro_rules! component_binop_impl( for j in 0 .. self.ncols() { for i in 0 .. self.nrows() { unsafe { - self.get_unchecked_mut((i, j)).$op_assign(*rhs.get_unchecked((i, j))); + self.get_unchecked_mut((i, j)).$op_assign(rhs.get_unchecked((i, j)).inlined_clone()); } } } diff --git a/src/base/construction.rs b/src/base/construction.rs index d7f1fef8..6925351d 100644 --- a/src/base/construction.rs +++ b/src/base/construction.rs @@ -27,7 +27,7 @@ use crate::base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Scalar, Unit, Vec * Generic constructors. * */ -impl MatrixMN +impl MatrixMN where DefaultAllocator: Allocator { /// Creates a new uninitialized matrix. If the matrix has a compile-time dimension, this panics @@ -84,7 +84,7 @@ where DefaultAllocator: Allocator for i in 0..nrows.value() { for j in 0..ncols.value() { - unsafe { *res.get_unchecked_mut((i, j)) = *iter.next().unwrap() } + unsafe { *res.get_unchecked_mut((i, j)) = iter.next().unwrap().inlined_clone() } } } @@ -134,7 +134,7 @@ where DefaultAllocator: Allocator let mut res = Self::zeros_generic(nrows, ncols); for i in 0..crate::min(nrows.value(), ncols.value()) { - unsafe { *res.get_unchecked_mut((i, i)) = elt } + unsafe { *res.get_unchecked_mut((i, i)) = elt.inlined_clone() } } res @@ -154,7 +154,7 @@ where DefaultAllocator: Allocator ); for (i, elt) in elts.iter().enumerate() { - unsafe { *res.get_unchecked_mut((i, i)) = *elt } + unsafe { *res.get_unchecked_mut((i, i)) = elt.inlined_clone() } } res @@ -196,7 +196,7 @@ where DefaultAllocator: Allocator // FIXME: optimize that. Self::from_fn_generic(R::from_usize(nrows), C::from_usize(ncols), |i, j| { - rows[i][(0, j)] + rows[i][(0, j)].inlined_clone() }) } @@ -236,7 +236,7 @@ where DefaultAllocator: Allocator // FIXME: optimize that. Self::from_fn_generic(R::from_usize(nrows), C::from_usize(ncols), |i, j| { - columns[j][i] + columns[j][i].inlined_clone() }) } @@ -286,7 +286,7 @@ where DefaultAllocator: Allocator impl MatrixN where - N: Scalar + Copy, + N: Scalar + Clone, DefaultAllocator: Allocator, { /// Creates a square matrix with its diagonal set to `diag` and all other entries set to 0. @@ -315,7 +315,7 @@ where for i in 0..diag.len() { unsafe { - *res.get_unchecked_mut((i, i)) = *diag.vget_unchecked(i); + *res.get_unchecked_mut((i, i)) = diag.vget_unchecked(i).inlined_clone(); } } @@ -330,7 +330,7 @@ where */ macro_rules! impl_constructors( ($($Dims: ty),*; $(=> $DimIdent: ident: $DimBound: ident),*; $($gargs: expr),*; $($args: ident),*) => { - impl MatrixMN + impl MatrixMN where DefaultAllocator: Allocator { /// Creates a new uninitialized matrix or vector. @@ -559,7 +559,7 @@ macro_rules! impl_constructors( } } - impl MatrixMN + impl MatrixMN where DefaultAllocator: Allocator, Standard: Distribution { @@ -603,7 +603,7 @@ impl_constructors!(Dynamic, Dynamic; */ macro_rules! impl_constructors_from_data( ($data: ident; $($Dims: ty),*; $(=> $DimIdent: ident: $DimBound: ident),*; $($gargs: expr),*; $($args: ident),*) => { - impl MatrixMN + impl MatrixMN where DefaultAllocator: Allocator { /// Creates a matrix with its elements filled with the components provided by a slice /// in row-major order. @@ -721,7 +721,7 @@ impl_constructors_from_data!(data; Dynamic, Dynamic; */ impl Zero for MatrixMN where - N: Scalar + Copy + Zero + ClosedAdd, + N: Scalar + Clone + Zero + ClosedAdd, DefaultAllocator: Allocator, { #[inline] @@ -737,7 +737,7 @@ where impl One for MatrixN where - N: Scalar + Copy + Zero + One + ClosedMul + ClosedAdd, + N: Scalar + Clone + Zero + One + ClosedMul + ClosedAdd, DefaultAllocator: Allocator, { #[inline] @@ -748,7 +748,7 @@ where impl Bounded for MatrixMN where - N: Scalar + Copy + Bounded, + N: Scalar + Clone + Bounded, DefaultAllocator: Allocator, { #[inline] @@ -762,7 +762,7 @@ where } } -impl Distribution> for Standard +impl Distribution> for Standard where DefaultAllocator: Allocator, Standard: Distribution, @@ -781,7 +781,7 @@ impl Arbitrary for MatrixMN where R: Dim, C: Dim, - N: Scalar + Copy + Arbitrary + Send, + N: Scalar + Clone + Arbitrary + Send, DefaultAllocator: Allocator, Owned: Clone + Send, { @@ -822,7 +822,7 @@ where macro_rules! componentwise_constructors_impl( ($($R: ty, $C: ty, $($args: ident:($irow: expr,$icol: expr)),*);* $(;)*) => {$( impl MatrixMN - where N: Scalar + Copy, + where N: Scalar + Clone, DefaultAllocator: Allocator { /// Initializes this matrix from its components. #[inline] @@ -990,7 +990,7 @@ componentwise_constructors_impl!( */ impl VectorN where - N: Scalar + Copy + Zero + One, + N: Scalar + Clone + Zero + One, DefaultAllocator: Allocator, { /// The column vector with a 1 as its first component, and zero elsewhere. diff --git a/src/base/construction_slice.rs b/src/base/construction_slice.rs index 029abc69..0e1d28f8 100644 --- a/src/base/construction_slice.rs +++ b/src/base/construction_slice.rs @@ -8,7 +8,7 @@ use num_rational::Ratio; * Slice constructors. * */ -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, RStride: Dim, CStride: Dim> +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, RStride: Dim, CStride: Dim> MatrixSliceMN<'a, N, R, C, RStride, CStride> { /// Creates, without bound-checking, a matrix slice from an array and with dimensions and strides specified by generic types instances. @@ -61,7 +61,7 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim, RStride: Dim, CStride: Dim> } } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, RStride: Dim, CStride: Dim> +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, RStride: Dim, CStride: Dim> MatrixSliceMutMN<'a, N, R, C, RStride, CStride> { /// Creates, without bound-checking, a mutable matrix slice from an array and with dimensions and strides specified by generic types instances. @@ -133,7 +133,7 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim, RStride: Dim, CStride: Dim> } } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim> MatrixSliceMN<'a, N, R, C> { +impl<'a, N: Scalar + Clone, R: Dim, C: Dim> MatrixSliceMN<'a, N, R, C> { /// Creates, without bound-checking, a matrix slice from an array and with dimensions specified by generic types instances. /// /// This method is unsafe because the input data array is not checked to contain enough elements. @@ -159,7 +159,7 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim> MatrixSliceMN<'a, N, R, C> { } } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim> MatrixSliceMutMN<'a, N, R, C> { +impl<'a, N: Scalar + Clone, R: Dim, C: Dim> MatrixSliceMutMN<'a, N, R, C> { /// Creates, without bound-checking, a mutable matrix slice from an array and with dimensions specified by generic types instances. /// /// This method is unsafe because the input data array is not checked to contain enough elements. @@ -187,7 +187,7 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim> MatrixSliceMutMN<'a, N, R, C> { macro_rules! impl_constructors( ($($Dims: ty),*; $(=> $DimIdent: ident: $DimBound: ident),*; $($gargs: expr),*; $($args: ident),*) => { - impl<'a, N: Scalar + Copy, $($DimIdent: $DimBound),*> MatrixSliceMN<'a, N, $($Dims),*> { + impl<'a, N: Scalar + Clone, $($DimIdent: $DimBound),*> MatrixSliceMN<'a, N, $($Dims),*> { /// Creates a new matrix slice from the given data array. /// /// Panics if `data` does not contain enough elements. @@ -203,7 +203,7 @@ macro_rules! impl_constructors( } } - impl<'a, N: Scalar + Copy, $($DimIdent: $DimBound, )*> MatrixSliceMN<'a, N, $($Dims,)* Dynamic, Dynamic> { + impl<'a, N: Scalar + Clone, $($DimIdent: $DimBound, )*> MatrixSliceMN<'a, N, $($Dims,)* Dynamic, Dynamic> { /// Creates a new matrix slice with the specified strides from the given data array. /// /// Panics if `data` does not contain enough elements. @@ -244,7 +244,7 @@ impl_constructors!(Dynamic, Dynamic; macro_rules! impl_constructors_mut( ($($Dims: ty),*; $(=> $DimIdent: ident: $DimBound: ident),*; $($gargs: expr),*; $($args: ident),*) => { - impl<'a, N: Scalar + Copy, $($DimIdent: $DimBound),*> MatrixSliceMutMN<'a, N, $($Dims),*> { + impl<'a, N: Scalar + Clone, $($DimIdent: $DimBound),*> MatrixSliceMutMN<'a, N, $($Dims),*> { /// Creates a new mutable matrix slice from the given data array. /// /// Panics if `data` does not contain enough elements. @@ -260,7 +260,7 @@ macro_rules! impl_constructors_mut( } } - impl<'a, N: Scalar + Copy, $($DimIdent: $DimBound, )*> MatrixSliceMutMN<'a, N, $($Dims,)* Dynamic, Dynamic> { + impl<'a, N: Scalar + Clone, $($DimIdent: $DimBound, )*> MatrixSliceMutMN<'a, N, $($Dims,)* Dynamic, Dynamic> { /// Creates a new mutable matrix slice with the specified strides from the given data array. /// /// Panics if `data` does not contain enough elements. diff --git a/src/base/conversion.rs b/src/base/conversion.rs index 883f3fb8..4b937556 100644 --- a/src/base/conversion.rs +++ b/src/base/conversion.rs @@ -31,8 +31,8 @@ where C1: Dim, R2: Dim, C2: Dim, - N1: Scalar + Copy, - N2: Scalar + Copy + SupersetOf, + N1: Scalar + Clone, + N2: Scalar + Clone + SupersetOf, DefaultAllocator: Allocator + Allocator + SameShapeAllocator, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, @@ -75,7 +75,7 @@ where } } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: Storage> IntoIterator for &'a Matrix { +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: Storage> IntoIterator for &'a Matrix { type Item = &'a N; type IntoIter = MatrixIter<'a, N, R, C, S>; @@ -85,7 +85,7 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: Storage> IntoIterator for } } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: StorageMut> IntoIterator +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: StorageMut> IntoIterator for &'a mut Matrix { type Item = &'a mut N; @@ -100,7 +100,7 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: StorageMut> IntoIterator macro_rules! impl_from_into_asref_1D( ($(($NRows: ident, $NCols: ident) => $SZ: expr);* $(;)*) => {$( impl From<[N; $SZ]> for MatrixMN - where N: Scalar + Copy, + where N: Scalar + Clone, DefaultAllocator: Allocator { #[inline] fn from(arr: [N; $SZ]) -> Self { @@ -114,7 +114,7 @@ macro_rules! impl_from_into_asref_1D( } impl Into<[N; $SZ]> for Matrix - where N: Scalar + Copy, + where N: Scalar + Clone, S: ContiguousStorage { #[inline] fn into(self) -> [N; $SZ] { @@ -128,7 +128,7 @@ macro_rules! impl_from_into_asref_1D( } impl AsRef<[N; $SZ]> for Matrix - where N: Scalar + Copy, + where N: Scalar + Clone, S: ContiguousStorage { #[inline] fn as_ref(&self) -> &[N; $SZ] { @@ -139,7 +139,7 @@ macro_rules! impl_from_into_asref_1D( } impl AsMut<[N; $SZ]> for Matrix - where N: Scalar + Copy, + where N: Scalar + Clone, S: ContiguousStorageMut { #[inline] fn as_mut(&mut self) -> &mut [N; $SZ] { @@ -168,7 +168,7 @@ impl_from_into_asref_1D!( macro_rules! impl_from_into_asref_2D( ($(($NRows: ty, $NCols: ty) => ($SZRows: expr, $SZCols: expr));* $(;)*) => {$( - impl From<[[N; $SZRows]; $SZCols]> for MatrixMN + impl From<[[N; $SZRows]; $SZCols]> for MatrixMN where DefaultAllocator: Allocator { #[inline] fn from(arr: [[N; $SZRows]; $SZCols]) -> Self { @@ -181,7 +181,7 @@ macro_rules! impl_from_into_asref_2D( } } - impl Into<[[N; $SZRows]; $SZCols]> for Matrix + impl Into<[[N; $SZRows]; $SZCols]> for Matrix where S: ContiguousStorage { #[inline] fn into(self) -> [[N; $SZRows]; $SZCols] { @@ -194,7 +194,7 @@ macro_rules! impl_from_into_asref_2D( } } - impl AsRef<[[N; $SZRows]; $SZCols]> for Matrix + impl AsRef<[[N; $SZRows]; $SZCols]> for Matrix where S: ContiguousStorage { #[inline] fn as_ref(&self) -> &[[N; $SZRows]; $SZCols] { @@ -204,7 +204,7 @@ macro_rules! impl_from_into_asref_2D( } } - impl AsMut<[[N; $SZRows]; $SZCols]> for Matrix + impl AsMut<[[N; $SZRows]; $SZCols]> for Matrix where S: ContiguousStorageMut { #[inline] fn as_mut(&mut self) -> &mut [[N; $SZRows]; $SZCols] { @@ -229,7 +229,7 @@ impl_from_into_asref_2D!( macro_rules! impl_from_into_mint_1D( ($($NRows: ident => $VT:ident [$SZ: expr]);* $(;)*) => {$( impl From> for MatrixMN - where N: Scalar + Copy, + where N: Scalar + Clone, DefaultAllocator: Allocator { #[inline] fn from(v: mint::$VT) -> Self { @@ -243,7 +243,7 @@ macro_rules! impl_from_into_mint_1D( } impl Into> for Matrix - where N: Scalar + Copy, + where N: Scalar + Clone, S: ContiguousStorage { #[inline] fn into(self) -> mint::$VT { @@ -257,7 +257,7 @@ macro_rules! impl_from_into_mint_1D( } impl AsRef> for Matrix - where N: Scalar + Copy, + where N: Scalar + Clone, S: ContiguousStorage { #[inline] fn as_ref(&self) -> &mint::$VT { @@ -268,7 +268,7 @@ macro_rules! impl_from_into_mint_1D( } impl AsMut> for Matrix - where N: Scalar + Copy, + where N: Scalar + Clone, S: ContiguousStorageMut { #[inline] fn as_mut(&mut self) -> &mut mint::$VT { @@ -292,7 +292,7 @@ impl_from_into_mint_1D!( macro_rules! impl_from_into_mint_2D( ($(($NRows: ty, $NCols: ty) => $MV:ident{ $($component:ident),* }[$SZRows: expr]);* $(;)*) => {$( impl From> for MatrixMN - where N: Scalar + Copy, + where N: Scalar + Clone, DefaultAllocator: Allocator { #[inline] fn from(m: mint::$MV) -> Self { @@ -310,7 +310,7 @@ macro_rules! impl_from_into_mint_2D( } impl Into> for MatrixMN - where N: Scalar + Copy, + where N: Scalar + Clone, DefaultAllocator: Allocator { #[inline] fn into(self) -> mint::$MV { @@ -342,7 +342,7 @@ impl_from_into_mint_2D!( impl<'a, N, R, C, RStride, CStride> From> for Matrix> where - N: Scalar + Copy, + N: Scalar + Clone, R: DimName, C: DimName, RStride: Dim, @@ -359,7 +359,7 @@ where impl<'a, N, C, RStride, CStride> From> for Matrix> where - N: Scalar + Copy, + N: Scalar + Clone, C: Dim, RStride: Dim, CStride: Dim, @@ -373,7 +373,7 @@ where impl<'a, N, R, RStride, CStride> From> for Matrix> where - N: Scalar + Copy, + N: Scalar + Clone, R: DimName, RStride: Dim, CStride: Dim, @@ -386,7 +386,7 @@ where impl<'a, N, R, C, RStride, CStride> From> for Matrix> where - N: Scalar + Copy, + N: Scalar + Clone, R: DimName, C: DimName, RStride: Dim, @@ -403,7 +403,7 @@ where impl<'a, N, C, RStride, CStride> From> for Matrix> where - N: Scalar + Copy, + N: Scalar + Clone, C: Dim, RStride: Dim, CStride: Dim, @@ -417,7 +417,7 @@ where impl<'a, N, R, RStride, CStride> From> for Matrix> where - N: Scalar + Copy, + N: Scalar + Clone, R: DimName, RStride: Dim, CStride: Dim, @@ -430,7 +430,7 @@ where impl<'a, N, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a Matrix> for MatrixSlice<'a, N, RSlice, CSlice, RStride, CStride> where - N: Scalar + Copy, + N: Scalar + Clone, R: Dim, C: Dim, RSlice: Dim, @@ -463,7 +463,7 @@ for MatrixSlice<'a, N, RSlice, CSlice, RStride, CStride> impl<'a, N, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix> for MatrixSlice<'a, N, RSlice, CSlice, RStride, CStride> where - N: Scalar + Copy, + N: Scalar + Clone, R: Dim, C: Dim, RSlice: Dim, @@ -496,7 +496,7 @@ for MatrixSlice<'a, N, RSlice, CSlice, RStride, CStride> impl<'a, N, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix> for MatrixSliceMut<'a, N, RSlice, CSlice, RStride, CStride> where - N: Scalar + Copy, + N: Scalar + Clone, R: Dim, C: Dim, RSlice: Dim, diff --git a/src/base/coordinates.rs b/src/base/coordinates.rs index 38c7edac..ee6ccf91 100644 --- a/src/base/coordinates.rs +++ b/src/base/coordinates.rs @@ -24,7 +24,7 @@ macro_rules! coords_impl( #[repr(C)] #[derive(Eq, PartialEq, Clone, Hash, Debug, Copy)] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] - pub struct $T { + pub struct $T { $(pub $comps: N),* } } @@ -32,7 +32,7 @@ macro_rules! coords_impl( macro_rules! deref_impl( ($R: ty, $C: ty; $Target: ident) => { - impl Deref for Matrix + impl Deref for Matrix where S: ContiguousStorage { type Target = $Target; @@ -42,7 +42,7 @@ macro_rules! deref_impl( } } - impl DerefMut for Matrix + impl DerefMut for Matrix where S: ContiguousStorageMut { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { diff --git a/src/base/default_allocator.rs b/src/base/default_allocator.rs index ee6786c5..4413de27 100644 --- a/src/base/default_allocator.rs +++ b/src/base/default_allocator.rs @@ -36,7 +36,7 @@ pub struct DefaultAllocator; // Static - Static impl Allocator for DefaultAllocator where - N: Scalar + Copy, + N: Scalar + Clone, R: DimName, C: DimName, R::Value: Mul, @@ -76,7 +76,7 @@ where // Dynamic - Static // Dynamic - Dynamic #[cfg(any(feature = "std", feature = "alloc"))] -impl Allocator for DefaultAllocator { +impl Allocator for DefaultAllocator { type Buffer = VecStorage; #[inline] @@ -107,7 +107,7 @@ impl Allocator for DefaultAllocator { // Static - Dynamic #[cfg(any(feature = "std", feature = "alloc"))] -impl Allocator for DefaultAllocator { +impl Allocator for DefaultAllocator { type Buffer = VecStorage; #[inline] @@ -142,7 +142,7 @@ impl Allocator for DefaultAllocator * */ // Anything -> Static × Static -impl Reallocator for DefaultAllocator +impl Reallocator for DefaultAllocator where RFrom: Dim, CFrom: Dim, @@ -173,7 +173,7 @@ where // Static × Static -> Dynamic × Any #[cfg(any(feature = "std", feature = "alloc"))] -impl Reallocator for DefaultAllocator +impl Reallocator for DefaultAllocator where RFrom: DimName, CFrom: DimName, @@ -202,7 +202,7 @@ where // Static × Static -> Static × Dynamic #[cfg(any(feature = "std", feature = "alloc"))] -impl Reallocator for DefaultAllocator +impl Reallocator for DefaultAllocator where RFrom: DimName, CFrom: DimName, @@ -231,7 +231,7 @@ where // All conversion from a dynamic buffer to a dynamic buffer. #[cfg(any(feature = "std", feature = "alloc"))] -impl Reallocator +impl Reallocator for DefaultAllocator { #[inline] @@ -247,7 +247,7 @@ impl Reallocator Reallocator +impl Reallocator for DefaultAllocator { #[inline] @@ -263,7 +263,7 @@ impl Reallocator Reallocator +impl Reallocator for DefaultAllocator { #[inline] @@ -279,7 +279,7 @@ impl Reallocator Reallocator +impl Reallocator for DefaultAllocator { #[inline] diff --git a/src/base/edition.rs b/src/base/edition.rs index cc4d4295..19937e3f 100644 --- a/src/base/edition.rs +++ b/src/base/edition.rs @@ -18,7 +18,7 @@ use crate::base::storage::{Storage, StorageMut}; use crate::base::DMatrix; use crate::base::{DefaultAllocator, Matrix, MatrixMN, RowVector, Scalar, Vector}; -impl> Matrix { +impl> Matrix { /// Extracts the upper triangular part of this matrix (including the diagonal). #[inline] pub fn upper_triangle(&self) -> MatrixMN @@ -64,7 +64,7 @@ impl> Matrix> Matrix> Matrix { +impl> Matrix { /// Sets all the elements of this matrix to `val`. #[inline] pub fn fill(&mut self, val: N) { for e in self.iter_mut() { - *e = val + *e = val.inlined_clone() } } @@ -116,7 +116,7 @@ impl> Matrix> Matrix> Matrix> Matrix> Matrix> Matrix> Matrix> Matrix { +impl> Matrix { /// Copies the upper-triangle of this matrix to its lower-triangular part. /// /// This makes the matrix symmetric. Panics if the matrix is not square. @@ -264,7 +264,7 @@ impl> Matrix { for j in 0..dim { for i in j + 1..dim { unsafe { - *self.get_unchecked_mut((i, j)) = *self.get_unchecked((j, i)); + *self.get_unchecked_mut((i, j)) = self.get_unchecked((j, i)).inlined_clone(); } } } @@ -279,7 +279,7 @@ impl> Matrix { for j in 1..self.ncols() { for i in 0..j { unsafe { - *self.get_unchecked_mut((i, j)) = *self.get_unchecked((j, i)); + *self.get_unchecked_mut((i, j)) = self.get_unchecked((j, i)).inlined_clone(); } } } @@ -291,7 +291,7 @@ impl> Matrix { * FIXME: specialize all the following for slices. * */ -impl> Matrix { +impl> Matrix { /* * * Column removal. @@ -783,7 +783,7 @@ impl> Matrix { } if new_ncols.value() > ncols { - res.columns_range_mut(ncols..).fill(val); + res.columns_range_mut(ncols..).fill(val.inlined_clone()); } if new_nrows.value() > nrows { @@ -797,7 +797,7 @@ impl> Matrix { } #[cfg(any(feature = "std", feature = "alloc"))] -impl DMatrix { +impl DMatrix { /// Resizes this matrix in-place. /// /// The values are copied such that `self[(i, j)] == result[(i, j)]`. If the result has more @@ -814,7 +814,7 @@ impl DMatrix { } #[cfg(any(feature = "std", feature = "alloc"))] -impl MatrixMN +impl MatrixMN where DefaultAllocator: Allocator { /// Changes the number of rows of this matrix in-place. @@ -835,7 +835,7 @@ where DefaultAllocator: Allocator } #[cfg(any(feature = "std", feature = "alloc"))] -impl MatrixMN +impl MatrixMN where DefaultAllocator: Allocator { /// Changes the number of column of this matrix in-place. @@ -855,7 +855,7 @@ where DefaultAllocator: Allocator } } -unsafe fn compress_rows( +unsafe fn compress_rows( data: &mut [N], nrows: usize, ncols: usize, @@ -895,7 +895,7 @@ unsafe fn compress_rows( // Moves entries of a matrix buffer to make place for `ninsert` emty rows starting at the `i-th` row index. // The `data` buffer is assumed to contained at least `(nrows + ninsert) * ncols` elements. -unsafe fn extend_rows( +unsafe fn extend_rows( data: &mut [N], nrows: usize, ncols: usize, @@ -938,7 +938,7 @@ unsafe fn extend_rows( #[cfg(any(feature = "std", feature = "alloc"))] impl Extend for Matrix where - N: Scalar + Copy, + N: Scalar + Clone, R: Dim, S: Extend, { @@ -986,7 +986,7 @@ where #[cfg(any(feature = "std", feature = "alloc"))] impl Extend for Matrix where - N: Scalar + Copy, + N: Scalar + Clone, S: Extend, { /// Extend the number of rows of a `Vector` with elements @@ -1007,7 +1007,7 @@ where #[cfg(any(feature = "std", feature = "alloc"))] impl Extend> for Matrix where - N: Scalar + Copy, + N: Scalar + Clone, R: Dim, S: Extend>, RV: Dim, diff --git a/src/base/indexing.rs b/src/base/indexing.rs index 8ce52454..35b4a9ff 100644 --- a/src/base/indexing.rs +++ b/src/base/indexing.rs @@ -267,7 +267,7 @@ fn dimrange_rangetoinclusive_usize() { } /// A helper trait used for indexing operations. -pub trait MatrixIndex<'a, N: Scalar + Copy, R: Dim, C: Dim, S: Storage>: Sized { +pub trait MatrixIndex<'a, N: Scalar + Clone, R: Dim, C: Dim, S: Storage>: Sized { /// The output type returned by methods. type Output : 'a; @@ -303,7 +303,7 @@ pub trait MatrixIndex<'a, N: Scalar + Copy, R: Dim, C: Dim, S: Storage> } /// A helper trait used for indexing operations. -pub trait MatrixIndexMut<'a, N: Scalar + Copy, R: Dim, C: Dim, S: StorageMut>: MatrixIndex<'a, N, R, C, S> { +pub trait MatrixIndexMut<'a, N: Scalar + Clone, R: Dim, C: Dim, S: StorageMut>: MatrixIndex<'a, N, R, C, S> { /// The output type returned by methods. type OutputMut : 'a; @@ -432,7 +432,7 @@ pub trait MatrixIndexMut<'a, N: Scalar + Copy, R: Dim, C: Dim, S: StorageMut> Matrix +impl> Matrix { /// Produces a view of the data at the given index, or /// `None` if the index is out of bounds. @@ -502,7 +502,7 @@ impl> Matrix impl<'a, N, R, C, S> MatrixIndex<'a, N, R, C, S> for usize where - N: Scalar + Copy, + N: Scalar + Clone, R: Dim, C: Dim, S: Storage @@ -524,7 +524,7 @@ where impl<'a, N, R, C, S> MatrixIndexMut<'a, N, R, C, S> for usize where - N: Scalar + Copy, + N: Scalar + Clone, R: Dim, C: Dim, S: StorageMut @@ -544,7 +544,7 @@ where impl<'a, N, R, C, S> MatrixIndex<'a, N, R, C, S> for (usize, usize) where - N: Scalar + Copy, + N: Scalar + Clone, R: Dim, C: Dim, S: Storage @@ -569,7 +569,7 @@ where impl<'a, N, R, C, S> MatrixIndexMut<'a, N, R, C, S> for (usize, usize) where - N: Scalar + Copy, + N: Scalar + Clone, R: Dim, C: Dim, S: StorageMut @@ -607,7 +607,7 @@ macro_rules! impl_index_pair { { impl<'a, N, $R, $C, S, $($RTyP : $RTyPB,)* $($CTyP : $CTyPB),*> MatrixIndex<'a, N, $R, $C, S> for ($RIdx, $CIdx) where - N: Scalar + Copy, + N: Scalar + Clone, $R: Dim, $C: Dim, S: Storage, @@ -643,7 +643,7 @@ macro_rules! impl_index_pair { impl<'a, N, $R, $C, S, $($RTyP : $RTyPB,)* $($CTyP : $CTyPB),*> MatrixIndexMut<'a, N, $R, $C, S> for ($RIdx, $CIdx) where - N: Scalar + Copy, + N: Scalar + Clone, $R: Dim, $C: Dim, S: StorageMut, diff --git a/src/base/iter.rs b/src/base/iter.rs index 63e61178..1032cd2a 100644 --- a/src/base/iter.rs +++ b/src/base/iter.rs @@ -10,7 +10,7 @@ use crate::base::{Scalar, Matrix, MatrixSlice, MatrixSliceMut}; macro_rules! iterator { (struct $Name:ident for $Storage:ident.$ptr: ident -> $Ptr:ty, $Ref:ty, $SRef: ty) => { /// An iterator through a dense matrix with arbitrary strides matrix. - pub struct $Name<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + $Storage> { + pub struct $Name<'a, N: Scalar + Clone, R: Dim, C: Dim, S: 'a + $Storage> { ptr: $Ptr, inner_ptr: $Ptr, inner_end: $Ptr, @@ -21,7 +21,7 @@ macro_rules! iterator { // FIXME: we need to specialize for the case where the matrix storage is owned (in which // case the iterator is trivial because it does not have any stride). - impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + $Storage> $Name<'a, N, R, C, S> { + impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: 'a + $Storage> $Name<'a, N, R, C, S> { /// Creates a new iterator for the given matrix storage. pub fn new(storage: $SRef) -> $Name<'a, N, R, C, S> { let shape = storage.shape(); @@ -58,7 +58,7 @@ macro_rules! iterator { } } - impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + $Storage> Iterator + impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: 'a + $Storage> Iterator for $Name<'a, N, R, C, S> { type Item = $Ref; @@ -111,7 +111,7 @@ macro_rules! iterator { } } - impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + $Storage> ExactSizeIterator + impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: 'a + $Storage> ExactSizeIterator for $Name<'a, N, R, C, S> { #[inline] @@ -133,12 +133,12 @@ iterator!(struct MatrixIterMut for StorageMut.ptr_mut -> *mut N, &'a mut N, &'a */ #[derive(Clone)] /// An iterator through the rows of a matrix. -pub struct RowIter<'a, N: Scalar + Copy, R: Dim, C: Dim, S: Storage> { +pub struct RowIter<'a, N: Scalar + Clone, R: Dim, C: Dim, S: Storage> { mat: &'a Matrix, curr: usize } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + Storage> RowIter<'a, N, R, C, S> { +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: 'a + Storage> RowIter<'a, N, R, C, S> { pub(crate) fn new(mat: &'a Matrix) -> Self { RowIter { mat, curr: 0 @@ -147,7 +147,7 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + Storage> RowIter<'a, } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + Storage> Iterator for RowIter<'a, N, R, C, S> { +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: 'a + Storage> Iterator for RowIter<'a, N, R, C, S> { type Item = MatrixSlice<'a, N, U1, C, S::RStride, S::CStride>; #[inline] @@ -172,7 +172,7 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + Storage> Iterator fo } } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIterator for RowIter<'a, N, R, C, S> { +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIterator for RowIter<'a, N, R, C, S> { #[inline] fn len(&self) -> usize { self.mat.nrows() - self.curr @@ -181,13 +181,13 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIt /// An iterator through the mutable rows of a matrix. -pub struct RowIterMut<'a, N: Scalar + Copy, R: Dim, C: Dim, S: StorageMut> { +pub struct RowIterMut<'a, N: Scalar + Clone, R: Dim, C: Dim, S: StorageMut> { mat: *mut Matrix, curr: usize, phantom: PhantomData<&'a mut Matrix> } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + StorageMut> RowIterMut<'a, N, R, C, S> { +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: 'a + StorageMut> RowIterMut<'a, N, R, C, S> { pub(crate) fn new(mat: &'a mut Matrix) -> Self { RowIterMut { mat, @@ -204,7 +204,7 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + StorageMut> RowIterM } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + StorageMut> Iterator for RowIterMut<'a, N, R, C, S> { +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: 'a + StorageMut> Iterator for RowIterMut<'a, N, R, C, S> { type Item = MatrixSliceMut<'a, N, U1, C, S::RStride, S::CStride>; #[inline] @@ -229,7 +229,7 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + StorageMut> Iterator } } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + StorageMut> ExactSizeIterator for RowIterMut<'a, N, R, C, S> { +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: 'a + StorageMut> ExactSizeIterator for RowIterMut<'a, N, R, C, S> { #[inline] fn len(&self) -> usize { self.nrows() - self.curr @@ -244,12 +244,12 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + StorageMut> ExactSiz */ #[derive(Clone)] /// An iterator through the columns of a matrix. -pub struct ColumnIter<'a, N: Scalar + Copy, R: Dim, C: Dim, S: Storage> { +pub struct ColumnIter<'a, N: Scalar + Clone, R: Dim, C: Dim, S: Storage> { mat: &'a Matrix, curr: usize } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + Storage> ColumnIter<'a, N, R, C, S> { +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: 'a + Storage> ColumnIter<'a, N, R, C, S> { pub(crate) fn new(mat: &'a Matrix) -> Self { ColumnIter { mat, curr: 0 @@ -258,7 +258,7 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + Storage> ColumnIter< } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + Storage> Iterator for ColumnIter<'a, N, R, C, S> { +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: 'a + Storage> Iterator for ColumnIter<'a, N, R, C, S> { type Item = MatrixSlice<'a, N, R, U1, S::RStride, S::CStride>; #[inline] @@ -283,7 +283,7 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + Storage> Iterator fo } } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIterator for ColumnIter<'a, N, R, C, S> { +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIterator for ColumnIter<'a, N, R, C, S> { #[inline] fn len(&self) -> usize { self.mat.ncols() - self.curr @@ -292,13 +292,13 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIt /// An iterator through the mutable columns of a matrix. -pub struct ColumnIterMut<'a, N: Scalar + Copy, R: Dim, C: Dim, S: StorageMut> { +pub struct ColumnIterMut<'a, N: Scalar + Clone, R: Dim, C: Dim, S: StorageMut> { mat: *mut Matrix, curr: usize, phantom: PhantomData<&'a mut Matrix> } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + StorageMut> ColumnIterMut<'a, N, R, C, S> { +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: 'a + StorageMut> ColumnIterMut<'a, N, R, C, S> { pub(crate) fn new(mat: &'a mut Matrix) -> Self { ColumnIterMut { mat, @@ -315,7 +315,7 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + StorageMut> ColumnIt } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + StorageMut> Iterator for ColumnIterMut<'a, N, R, C, S> { +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: 'a + StorageMut> Iterator for ColumnIterMut<'a, N, R, C, S> { type Item = MatrixSliceMut<'a, N, R, U1, S::RStride, S::CStride>; #[inline] @@ -340,7 +340,7 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + StorageMut> Iterator } } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: 'a + StorageMut> ExactSizeIterator for ColumnIterMut<'a, N, R, C, S> { +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, S: 'a + StorageMut> ExactSizeIterator for ColumnIterMut<'a, N, R, C, S> { #[inline] fn len(&self) -> usize { self.ncols() - self.curr diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 08c22cbb..7682f955 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -73,7 +73,7 @@ pub type MatrixCross = /// some concrete types for `N` and a compatible data storage type `S`). #[repr(C)] #[derive(Clone, Copy)] -pub struct Matrix { +pub struct Matrix { /// The data storage that contains all the matrix components and informations about its number /// of rows and column (if needed). pub data: S, @@ -81,7 +81,7 @@ pub struct Matrix { _phantoms: PhantomData<(N, R, C)>, } -impl fmt::Debug for Matrix { +impl fmt::Debug for Matrix { fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { formatter .debug_struct("Matrix") @@ -93,7 +93,7 @@ impl fmt::Debug for Matrix Serialize for Matrix where - N: Scalar + Copy, + N: Scalar + Clone, R: Dim, C: Dim, S: Serialize, @@ -107,7 +107,7 @@ where #[cfg(feature = "serde-serialize")] impl<'de, N, R, C, S> Deserialize<'de> for Matrix where - N: Scalar + Copy, + N: Scalar + Clone, R: Dim, C: Dim, S: Deserialize<'de>, @@ -122,7 +122,7 @@ where } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for Matrix { +impl Abomonation for Matrix { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.data.entomb(writer) } @@ -136,7 +136,7 @@ impl Abomonation for Matrix Matrix { +impl Matrix { /// Creates a new matrix with the given data without statically checking that the matrix /// dimension matches the storage dimension. #[inline] @@ -148,7 +148,7 @@ impl Matrix { } } -impl> Matrix { +impl> Matrix { /// Creates a new matrix with the given data. #[inline] pub fn from_data(data: S) -> Self { @@ -403,7 +403,7 @@ impl> Matrix { for j in 0..res.ncols() { for i in 0..res.nrows() { unsafe { - *res.get_unchecked_mut((i, j)) = *self.get_unchecked((i, j)); + *res.get_unchecked_mut((i, j)) = self.get_unchecked((i, j)).inlined_clone(); } } } @@ -413,7 +413,7 @@ impl> Matrix { /// Returns a matrix containing the result of `f` applied to each of its entries. #[inline] - pub fn map N2>(&self, mut f: F) -> MatrixMN + pub fn map N2>(&self, mut f: F) -> MatrixMN where DefaultAllocator: Allocator { let (nrows, ncols) = self.data.shape(); @@ -422,7 +422,7 @@ impl> Matrix { for j in 0..ncols.value() { for i in 0..nrows.value() { unsafe { - let a = *self.data.get_unchecked(i, j); + let a = self.data.get_unchecked(i, j).inlined_clone(); *res.data.get_unchecked_mut(i, j) = f(a) } } @@ -434,7 +434,7 @@ impl> Matrix { /// Returns a matrix containing the result of `f` applied to each of its entries. Unlike `map`, /// `f` also gets passed the row and column index, i.e. `f(row, col, value)`. #[inline] - pub fn map_with_location N2>( + pub fn map_with_location N2>( &self, mut f: F, ) -> MatrixMN @@ -448,7 +448,7 @@ impl> Matrix { for j in 0..ncols.value() { for i in 0..nrows.value() { unsafe { - let a = *self.data.get_unchecked(i, j); + let a = self.data.get_unchecked(i, j).inlined_clone(); *res.data.get_unchecked_mut(i, j) = f(i, j, a) } } @@ -462,8 +462,8 @@ impl> Matrix { #[inline] pub fn zip_map(&self, rhs: &Matrix, mut f: F) -> MatrixMN where - N2: Scalar + Copy, - N3: Scalar + Copy, + N2: Scalar + Clone, + N3: Scalar + Clone, S2: Storage, F: FnMut(N, N2) -> N3, DefaultAllocator: Allocator, @@ -480,8 +480,8 @@ impl> Matrix { for j in 0..ncols.value() { for i in 0..nrows.value() { unsafe { - let a = *self.data.get_unchecked(i, j); - let b = *rhs.data.get_unchecked(i, j); + let a = self.data.get_unchecked(i, j).inlined_clone(); + let b = rhs.data.get_unchecked(i, j).inlined_clone(); *res.data.get_unchecked_mut(i, j) = f(a, b) } } @@ -500,9 +500,9 @@ impl> Matrix { mut f: F, ) -> MatrixMN where - N2: Scalar + Copy, - N3: Scalar + Copy, - N4: Scalar + Copy, + N2: Scalar + Clone, + N3: Scalar + Clone, + N4: Scalar + Clone, S2: Storage, S3: Storage, F: FnMut(N, N2, N3) -> N4, @@ -521,9 +521,9 @@ impl> Matrix { for j in 0..ncols.value() { for i in 0..nrows.value() { unsafe { - let a = *self.data.get_unchecked(i, j); - let b = *b.data.get_unchecked(i, j); - let c = *c.data.get_unchecked(i, j); + let a = self.data.get_unchecked(i, j).inlined_clone(); + let b = b.data.get_unchecked(i, j).inlined_clone(); + let c = c.data.get_unchecked(i, j).inlined_clone(); *res.data.get_unchecked_mut(i, j) = f(a, b, c) } } @@ -542,7 +542,7 @@ impl> Matrix { for j in 0..ncols.value() { for i in 0..nrows.value() { unsafe { - let a = *self.data.get_unchecked(i, j); + let a = self.data.get_unchecked(i, j).inlined_clone(); res = f(res, a) } } @@ -555,7 +555,7 @@ impl> Matrix { #[inline] pub fn zip_fold(&self, rhs: &Matrix, init: Acc, mut f: impl FnMut(Acc, N, N2) -> Acc) -> Acc where - N2: Scalar + Copy, + N2: Scalar + Clone, R2: Dim, C2: Dim, S2: Storage, @@ -573,8 +573,8 @@ impl> Matrix { for j in 0..ncols.value() { for i in 0..nrows.value() { unsafe { - let a = *self.data.get_unchecked(i, j); - let b = *rhs.data.get_unchecked(i, j); + let a = self.data.get_unchecked(i, j).inlined_clone(); + let b = rhs.data.get_unchecked(i, j).inlined_clone(); res = f(res, a, b) } } @@ -602,7 +602,7 @@ impl> Matrix { for i in 0..nrows { for j in 0..ncols { unsafe { - *out.get_unchecked_mut((j, i)) = *self.get_unchecked((i, j)); + *out.get_unchecked_mut((j, i)) = self.get_unchecked((i, j)).inlined_clone(); } } } @@ -623,7 +623,7 @@ impl> Matrix { } } -impl> Matrix { +impl> Matrix { /// Mutably iterates through this matrix coordinates. #[inline] pub fn iter_mut(&mut self) -> MatrixIterMut { @@ -717,7 +717,7 @@ impl> Matrix> Matrix> Matrix> Matrix> Matrix(&mut self, rhs: &Matrix, mut f: impl FnMut(N, N2) -> N) - where N2: Scalar + Copy, + where N2: Scalar + Clone, R2: Dim, C2: Dim, S2: Storage, @@ -813,8 +813,8 @@ impl> Matrix> Matrix(&mut self, b: &Matrix, c: &Matrix, mut f: impl FnMut(N, N2, N3) -> N) - where N2: Scalar + Copy, + where N2: Scalar + Clone, R2: Dim, C2: Dim, S2: Storage, - N3: Scalar + Copy, + N3: Scalar + Clone, R3: Dim, C3: Dim, S3: Storage, @@ -850,16 +850,16 @@ impl> Matrix> Vector { +impl> Vector { /// Gets a reference to the i-th element of this column vector without bound checking. #[inline] pub unsafe fn vget_unchecked(&self, i: usize) -> &N { @@ -869,7 +869,7 @@ impl> Vector { } } -impl> Vector { +impl> Vector { /// Gets a mutable reference to the i-th element of this column vector without bound checking. #[inline] pub unsafe fn vget_unchecked_mut(&mut self, i: usize) -> &mut N { @@ -879,7 +879,7 @@ impl> Vector { } } -impl> Matrix { +impl> Matrix { /// Extracts a slice containing the entire matrix entries ordered column-by-columns. #[inline] pub fn as_slice(&self) -> &[N] { @@ -887,7 +887,7 @@ impl> Matrix> Matrix { +impl> Matrix { /// Extracts a mutable slice containing the entire matrix entries ordered column-by-columns. #[inline] pub fn as_mut_slice(&mut self) -> &mut [N] { @@ -895,7 +895,7 @@ impl> Matrix< } } -impl> Matrix { +impl> Matrix { /// Transposes the square matrix `self` in-place. pub fn transpose_mut(&mut self) { assert!( @@ -1052,7 +1052,7 @@ impl> Matrix { } } -impl> SquareMatrix { +impl> SquareMatrix { /// The diagonal of this matrix. #[inline] pub fn diagonal(&self) -> VectorN @@ -1064,7 +1064,7 @@ impl> SquareMatrix { /// /// This is a more efficient version of `self.diagonal().map(f)` since this /// allocates only once. - pub fn map_diagonal(&self, mut f: impl FnMut(N) -> N2) -> VectorN + pub fn map_diagonal(&self, mut f: impl FnMut(N) -> N2) -> VectorN where DefaultAllocator: Allocator { assert!( self.is_square(), @@ -1076,7 +1076,7 @@ impl> SquareMatrix { for i in 0..dim.value() { unsafe { - *res.vget_unchecked_mut(i) = f(*self.get_unchecked((i, i))); + *res.vget_unchecked_mut(i) = f(self.get_unchecked((i, i)).inlined_clone()); } } @@ -1096,7 +1096,7 @@ impl> SquareMatrix { let mut res = N::zero(); for i in 0..dim.value() { - res += unsafe { *self.get_unchecked((i, i)) }; + res += unsafe { self.get_unchecked((i, i)).inlined_clone() }; } res @@ -1128,7 +1128,7 @@ impl> SquareMatrix { } } -impl + IsNotStaticOne, S: Storage> Matrix { +impl + IsNotStaticOne, S: Storage> Matrix { /// Yields the homogeneous matrix for this matrix, i.e., appending an additional dimension and /// and setting the diagonal element to `1`. @@ -1144,7 +1144,7 @@ impl + IsNotStaticOne, S: Storage, S: Storage> Vector { +impl, S: Storage> Vector { /// Computes the coordinates in projective space of this vector, i.e., appends a `0` to its /// coordinates. #[inline] @@ -1170,7 +1170,7 @@ impl, S: Storage> Vector { } } -impl, S: Storage> Vector { +impl, S: Storage> Vector { /// Constructs a new vector of higher dimension by appending `element` to the end of `self`. #[inline] pub fn push(&self, element: N) -> VectorN> @@ -1188,7 +1188,7 @@ impl, S: Storage> Vector { impl AbsDiffEq for Matrix where - N: Scalar + Copy + AbsDiffEq, + N: Scalar + Clone + AbsDiffEq, S: Storage, N::Epsilon: Copy, { @@ -1209,7 +1209,7 @@ where impl RelativeEq for Matrix where - N: Scalar + Copy + RelativeEq, + N: Scalar + Clone + RelativeEq, S: Storage, N::Epsilon: Copy, { @@ -1232,7 +1232,7 @@ where impl UlpsEq for Matrix where - N: Scalar + Copy + UlpsEq, + N: Scalar + Clone + UlpsEq, S: Storage, N::Epsilon: Copy, { @@ -1252,7 +1252,7 @@ where impl PartialOrd for Matrix where - N: Scalar + Copy + PartialOrd, + N: Scalar + Clone + PartialOrd, S: Storage, { #[inline] @@ -1340,13 +1340,13 @@ where impl Eq for Matrix where - N: Scalar + Copy + Eq, + N: Scalar + Clone + Eq, S: Storage, {} impl PartialEq for Matrix where - N: Scalar + Copy, + N: Scalar + Clone, S: Storage, { #[inline] @@ -1363,13 +1363,13 @@ macro_rules! impl_fmt { ($trait: path, $fmt_str_without_precision: expr, $fmt_str_with_precision: expr) => { impl $trait for Matrix where - N: Scalar + Copy + $trait, + N: Scalar + Clone + $trait, S: Storage, DefaultAllocator: Allocator, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { #[cfg(feature = "std")] - fn val_width(val: N, f: &mut fmt::Formatter) -> usize { + fn val_width(val: &N, f: &mut fmt::Formatter) -> usize { match f.precision() { Some(precision) => format!($fmt_str_with_precision, val, precision).chars().count(), None => format!($fmt_str_without_precision, val).chars().count(), @@ -1377,7 +1377,7 @@ macro_rules! impl_fmt { } #[cfg(not(feature = "std"))] - fn val_width(_: N, _: &mut fmt::Formatter) -> usize { + fn val_width(_: &N, _: &mut fmt::Formatter) -> usize { 4 } @@ -1393,7 +1393,7 @@ macro_rules! impl_fmt { for i in 0..nrows { for j in 0..ncols { - lengths[(i, j)] = val_width(self[(i, j)], f); + lengths[(i, j)] = val_width(&self[(i, j)], f); max_length = crate::max(max_length, lengths[(i, j)]); } } @@ -1454,7 +1454,7 @@ fn lower_exp() { ") } -impl> Matrix { +impl> Matrix { /// The perpendicular product between two 2D column vectors, i.e. `a.x * b.y - a.y * b.x`. #[inline] pub fn perp(&self, b: &Matrix) -> N @@ -1470,8 +1470,8 @@ impl> Matrix> Matrix::from_usize(1); let mut res = Matrix::new_uninitialized_generic(nrows, ncols); - let ax = *self.get_unchecked((0, 0)); - let ay = *self.get_unchecked((1, 0)); - let az = *self.get_unchecked((2, 0)); + let ax = self.get_unchecked((0, 0)); + let ay = self.get_unchecked((1, 0)); + let az = self.get_unchecked((2, 0)); - let bx = *b.get_unchecked((0, 0)); - let by = *b.get_unchecked((1, 0)); - let bz = *b.get_unchecked((2, 0)); + let bx = b.get_unchecked((0, 0)); + let by = b.get_unchecked((1, 0)); + let bz = b.get_unchecked((2, 0)); - *res.get_unchecked_mut((0, 0)) = ay * bz - az * by; - *res.get_unchecked_mut((1, 0)) = az * bx - ax * bz; - *res.get_unchecked_mut((2, 0)) = ax * by - ay * bx; + *res.get_unchecked_mut((0, 0)) = ay.inlined_clone() * bz.inlined_clone() - az.inlined_clone() * by.inlined_clone(); + *res.get_unchecked_mut((1, 0)) = az.inlined_clone() * bx.inlined_clone() - ax.inlined_clone() * bz.inlined_clone(); + *res.get_unchecked_mut((2, 0)) = ax.inlined_clone() * by.inlined_clone() - ay.inlined_clone() * bx.inlined_clone(); res } @@ -1527,17 +1527,17 @@ impl> Matrix::from_usize(3); let mut res = Matrix::new_uninitialized_generic(nrows, ncols); - let ax = *self.get_unchecked((0, 0)); - let ay = *self.get_unchecked((0, 1)); - let az = *self.get_unchecked((0, 2)); + let ax = self.get_unchecked((0, 0)); + let ay = self.get_unchecked((0, 1)); + let az = self.get_unchecked((0, 2)); - let bx = *b.get_unchecked((0, 0)); - let by = *b.get_unchecked((0, 1)); - let bz = *b.get_unchecked((0, 2)); + let bx = b.get_unchecked((0, 0)); + let by = b.get_unchecked((0, 1)); + let bz = b.get_unchecked((0, 2)); - *res.get_unchecked_mut((0, 0)) = ay * bz - az * by; - *res.get_unchecked_mut((0, 1)) = az * bx - ax * bz; - *res.get_unchecked_mut((0, 2)) = ax * by - ay * bx; + *res.get_unchecked_mut((0, 0)) = ay.inlined_clone() * bz.inlined_clone() - az.inlined_clone() * by.inlined_clone(); + *res.get_unchecked_mut((0, 1)) = az.inlined_clone() * bx.inlined_clone() - ax.inlined_clone() * bz.inlined_clone(); + *res.get_unchecked_mut((0, 2)) = ax.inlined_clone() * by.inlined_clone() - ay.inlined_clone() * bx.inlined_clone(); res } @@ -1545,7 +1545,7 @@ impl> Matrix> Vector +impl> Vector where DefaultAllocator: Allocator { /// Computes the matrix `M` such that for all vector `v` we have `M * v == self.cross(&v)`. @@ -1553,13 +1553,13 @@ where DefaultAllocator: Allocator pub fn cross_matrix(&self) -> MatrixN { MatrixN::::new( N::zero(), - -self[2], - self[1], - self[2], + -self[2].inlined_clone(), + self[1].inlined_clone(), + self[2].inlined_clone(), N::zero(), - -self[0], - -self[1], - self[0], + -self[0].inlined_clone(), + -self[1].inlined_clone(), + self[0].inlined_clone(), N::zero(), ) } @@ -1593,7 +1593,7 @@ impl> Matrix { } } -impl> +impl> Vector { /// Returns `self * (1.0 - t) + rhs * t`, i.e., the linear blend of the vectors x and y using the scalar value a. @@ -1611,7 +1611,7 @@ impl>(&self, rhs: &Vector, t: N) -> VectorN where DefaultAllocator: Allocator { let mut res = self.clone_owned(); - res.axpy(t, rhs, N::one() - t); + res.axpy(t.inlined_clone(), rhs, N::one() - t); res } } @@ -1683,7 +1683,7 @@ impl> Unit> { impl AbsDiffEq for Unit> where - N: Scalar + Copy + AbsDiffEq, + N: Scalar + Clone + AbsDiffEq, S: Storage, N::Epsilon: Copy, { @@ -1702,7 +1702,7 @@ where impl RelativeEq for Unit> where - N: Scalar + Copy + RelativeEq, + N: Scalar + Clone + RelativeEq, S: Storage, N::Epsilon: Copy, { @@ -1726,7 +1726,7 @@ where impl UlpsEq for Unit> where - N: Scalar + Copy + UlpsEq, + N: Scalar + Clone + UlpsEq, S: Storage, N::Epsilon: Copy, { @@ -1743,7 +1743,7 @@ where impl Hash for Matrix where - N: Scalar + Copy + Hash, + N: Scalar + Clone + Hash, R: Dim, C: Dim, S: Storage, diff --git a/src/base/matrix_alga.rs b/src/base/matrix_alga.rs index 330c5f94..b275ce2e 100644 --- a/src/base/matrix_alga.rs +++ b/src/base/matrix_alga.rs @@ -25,7 +25,7 @@ use crate::base::{DefaultAllocator, MatrixMN, MatrixN, Scalar}; */ impl Identity for MatrixMN where - N: Scalar + Copy + Zero, + N: Scalar + Clone + Zero, DefaultAllocator: Allocator, { #[inline] @@ -36,7 +36,7 @@ where impl AbstractMagma for MatrixMN where - N: Scalar + Copy + ClosedAdd, + N: Scalar + Clone + ClosedAdd, DefaultAllocator: Allocator, { #[inline] @@ -47,7 +47,7 @@ where impl TwoSidedInverse for MatrixMN where - N: Scalar + Copy + ClosedNeg, + N: Scalar + Clone + ClosedNeg, DefaultAllocator: Allocator, { #[inline] @@ -64,7 +64,7 @@ where macro_rules! inherit_additive_structure( ($($marker: ident<$operator: ident> $(+ $bounds: ident)*),* $(,)*) => {$( impl $marker<$operator> for MatrixMN - where N: Scalar + Copy + $marker<$operator> $(+ $bounds)*, + where N: Scalar + Clone + $marker<$operator> $(+ $bounds)*, DefaultAllocator: Allocator { } )*} ); @@ -80,7 +80,7 @@ inherit_additive_structure!( impl AbstractModule for MatrixMN where - N: Scalar + Copy + RingCommutative, + N: Scalar + Clone + RingCommutative, DefaultAllocator: Allocator, { type AbstractRing = N; @@ -93,7 +93,7 @@ where impl Module for MatrixMN where - N: Scalar + Copy + RingCommutative, + N: Scalar + Clone + RingCommutative, DefaultAllocator: Allocator, { type Ring = N; @@ -101,7 +101,7 @@ where impl VectorSpace for MatrixMN where - N: Scalar + Copy + Field, + N: Scalar + Clone + Field, DefaultAllocator: Allocator, { type Field = N; @@ -109,7 +109,7 @@ where impl FiniteDimVectorSpace for MatrixMN where - N: Scalar + Copy + Field, + N: Scalar + Clone + Field, DefaultAllocator: Allocator, { #[inline] @@ -329,7 +329,7 @@ where DefaultAllocator: Allocator */ impl Identity for MatrixN where - N: Scalar + Copy + Zero + One, + N: Scalar + Clone + Zero + One, DefaultAllocator: Allocator, { #[inline] @@ -340,7 +340,7 @@ where impl AbstractMagma for MatrixN where - N: Scalar + Copy + Zero + One + ClosedAdd + ClosedMul, + N: Scalar + Clone + Zero + One + ClosedAdd + ClosedMul, DefaultAllocator: Allocator, { #[inline] @@ -352,7 +352,7 @@ where macro_rules! impl_multiplicative_structure( ($($marker: ident<$operator: ident> $(+ $bounds: ident)*),* $(,)*) => {$( impl $marker<$operator> for MatrixN - where N: Scalar + Copy + Zero + One + ClosedAdd + ClosedMul + $marker<$operator> $(+ $bounds)*, + where N: Scalar + Clone + Zero + One + ClosedAdd + ClosedMul + $marker<$operator> $(+ $bounds)*, DefaultAllocator: Allocator { } )*} ); @@ -369,7 +369,7 @@ impl_multiplicative_structure!( */ impl MeetSemilattice for MatrixMN where - N: Scalar + Copy + MeetSemilattice, + N: Scalar + Clone + MeetSemilattice, DefaultAllocator: Allocator, { #[inline] @@ -380,7 +380,7 @@ where impl JoinSemilattice for MatrixMN where - N: Scalar + Copy + JoinSemilattice, + N: Scalar + Clone + JoinSemilattice, DefaultAllocator: Allocator, { #[inline] @@ -391,7 +391,7 @@ where impl Lattice for MatrixMN where - N: Scalar + Copy + Lattice, + N: Scalar + Clone + Lattice, DefaultAllocator: Allocator, { #[inline] diff --git a/src/base/matrix_slice.rs b/src/base/matrix_slice.rs index 43131680..1ab3d487 100644 --- a/src/base/matrix_slice.rs +++ b/src/base/matrix_slice.rs @@ -13,22 +13,22 @@ macro_rules! slice_storage_impl( ($doc: expr; $Storage: ident as $SRef: ty; $T: ident.$get_addr: ident ($Ptr: ty as $Ref: ty)) => { #[doc = $doc] #[derive(Debug)] - pub struct $T<'a, N: Scalar + Copy, R: Dim, C: Dim, RStride: Dim, CStride: Dim> { + pub struct $T<'a, N: Scalar + Clone, R: Dim, C: Dim, RStride: Dim, CStride: Dim> { ptr: $Ptr, shape: (R, C), strides: (RStride, CStride), _phantoms: PhantomData<$Ref>, } - unsafe impl<'a, N: Scalar + Copy + Send, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Send + unsafe impl<'a, N: Scalar + Clone + Send, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Send for $T<'a, N, R, C, RStride, CStride> {} - unsafe impl<'a, N: Scalar + Copy + Sync, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Sync + unsafe impl<'a, N: Scalar + Clone + Sync, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Sync for $T<'a, N, R, C, RStride, CStride> {} - impl<'a, N: Scalar + Copy, R: Dim, C: Dim, RStride: Dim, CStride: Dim> $T<'a, N, R, C, RStride, CStride> { + impl<'a, N: Scalar + Clone, R: Dim, C: Dim, RStride: Dim, CStride: Dim> $T<'a, N, R, C, RStride, CStride> { /// Create a new matrix slice without bound checking and from a raw pointer. #[inline] pub unsafe fn from_raw_parts(ptr: $Ptr, @@ -48,7 +48,7 @@ macro_rules! slice_storage_impl( } // Dynamic is arbitrary. It's just to be able to call the constructors with `Slice::` - impl<'a, N: Scalar + Copy, R: Dim, C: Dim> $T<'a, N, R, C, Dynamic, Dynamic> { + impl<'a, N: Scalar + Clone, R: Dim, C: Dim> $T<'a, N, R, C, Dynamic, Dynamic> { /// Create a new matrix slice without bound checking. #[inline] pub unsafe fn new_unchecked(storage: $SRef, start: (usize, usize), shape: (R, C)) @@ -89,12 +89,12 @@ slice_storage_impl!("A mutable matrix data storage for mutable matrix slice. Onl StorageMut as &'a mut S; SliceStorageMut.get_address_unchecked_mut(*mut N as &'a mut N) ); -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Copy +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Copy for SliceStorage<'a, N, R, C, RStride, CStride> { } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Clone +impl<'a, N: Scalar + Clone, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Clone for SliceStorage<'a, N, R, C, RStride, CStride> { #[inline] @@ -110,7 +110,7 @@ impl<'a, N: Scalar + Copy, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Clone macro_rules! storage_impl( ($($T: ident),* $(,)*) => {$( - unsafe impl<'a, N: Scalar + Copy, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Storage + unsafe impl<'a, N: Scalar + Clone, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Storage for $T<'a, N, R, C, RStride, CStride> { type RStride = RStride; @@ -178,7 +178,7 @@ macro_rules! storage_impl( storage_impl!(SliceStorage, SliceStorageMut); -unsafe impl<'a, N: Scalar + Copy, R: Dim, C: Dim, RStride: Dim, CStride: Dim> StorageMut +unsafe impl<'a, N: Scalar + Clone, R: Dim, C: Dim, RStride: Dim, CStride: Dim> StorageMut for SliceStorageMut<'a, N, R, C, RStride, CStride> { #[inline] @@ -198,15 +198,15 @@ unsafe impl<'a, N: Scalar + Copy, R: Dim, C: Dim, RStride: Dim, CStride: Dim> St } } -unsafe impl<'a, N: Scalar + Copy, R: Dim, CStride: Dim> ContiguousStorage for SliceStorage<'a, N, R, U1, U1, CStride> { } -unsafe impl<'a, N: Scalar + Copy, R: Dim, CStride: Dim> ContiguousStorage for SliceStorageMut<'a, N, R, U1, U1, CStride> { } -unsafe impl<'a, N: Scalar + Copy, R: Dim, CStride: Dim> ContiguousStorageMut for SliceStorageMut<'a, N, R, U1, U1, CStride> { } +unsafe impl<'a, N: Scalar + Clone, R: Dim, CStride: Dim> ContiguousStorage for SliceStorage<'a, N, R, U1, U1, CStride> { } +unsafe impl<'a, N: Scalar + Clone, R: Dim, CStride: Dim> ContiguousStorage for SliceStorageMut<'a, N, R, U1, U1, CStride> { } +unsafe impl<'a, N: Scalar + Clone, R: Dim, CStride: Dim> ContiguousStorageMut for SliceStorageMut<'a, N, R, U1, U1, CStride> { } -unsafe impl<'a, N: Scalar + Copy, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorage for SliceStorage<'a, N, R, C, U1, R> { } -unsafe impl<'a, N: Scalar + Copy, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorage for SliceStorageMut<'a, N, R, C, U1, R> { } -unsafe impl<'a, N: Scalar + Copy, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorageMut for SliceStorageMut<'a, N, R, C, U1, R> { } +unsafe impl<'a, N: Scalar + Clone, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorage for SliceStorage<'a, N, R, C, U1, R> { } +unsafe impl<'a, N: Scalar + Clone, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorage for SliceStorageMut<'a, N, R, C, U1, R> { } +unsafe impl<'a, N: Scalar + Clone, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorageMut for SliceStorageMut<'a, N, R, C, U1, R> { } -impl> Matrix { +impl> Matrix { #[inline] fn assert_slice_index( &self, @@ -261,7 +261,7 @@ macro_rules! matrix_slice_impl( pub type $MatrixSlice<'a, N, R, C, RStride, CStride> = Matrix>; - impl> Matrix { + impl> Matrix { /* * * Row slicing. @@ -786,7 +786,7 @@ impl SliceRange for RangeFull { } } -impl> Matrix { +impl> Matrix { /// Slices a sub-matrix containing the rows indexed by the range `rows` and the columns indexed /// by the range `cols`. #[inline] @@ -827,7 +827,7 @@ impl> Matrix { } } -impl> Matrix { +impl> Matrix { /// Slices a mutable sub-matrix containing the rows indexed by the range `rows` and the columns /// indexed by the range `cols`. pub fn slice_range_mut( @@ -871,7 +871,7 @@ impl> Matrix From> for MatrixSlice<'a, N, R, C, RStride, CStride> where - N: Scalar + Copy, + N: Scalar + Clone, R: Dim, C: Dim, RStride: Dim, diff --git a/src/base/ops.rs b/src/base/ops.rs index 77b35e94..9f785daa 100644 --- a/src/base/ops.rs +++ b/src/base/ops.rs @@ -20,7 +20,7 @@ use crate::base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, MatrixSum, Scalar * Indexing. * */ -impl> Index for Matrix { +impl> Index for Matrix { type Output = N; #[inline] @@ -32,7 +32,7 @@ impl> Index for Mat impl Index<(usize, usize)> for Matrix where - N: Scalar + Copy, + N: Scalar + Clone, S: Storage, { type Output = N; @@ -50,7 +50,7 @@ where } // Mutable versions. -impl> IndexMut for Matrix { +impl> IndexMut for Matrix { #[inline] fn index_mut(&mut self, i: usize) -> &mut N { let ij = self.vector_to_matrix_index(i); @@ -60,7 +60,7 @@ impl> IndexMut f impl IndexMut<(usize, usize)> for Matrix where - N: Scalar + Copy, + N: Scalar + Clone, S: StorageMut, { #[inline] @@ -82,7 +82,7 @@ where */ impl Neg for Matrix where - N: Scalar + Copy + ClosedNeg, + N: Scalar + Clone + ClosedNeg, S: Storage, DefaultAllocator: Allocator, { @@ -98,7 +98,7 @@ where impl<'a, N, R: Dim, C: Dim, S> Neg for &'a Matrix where - N: Scalar + Copy + ClosedNeg, + N: Scalar + Clone + ClosedNeg, S: Storage, DefaultAllocator: Allocator, { @@ -112,14 +112,14 @@ where impl Matrix where - N: Scalar + Copy + ClosedNeg, + N: Scalar + Clone + ClosedNeg, S: StorageMut, { /// Negates `self` in-place. #[inline] pub fn neg_mut(&mut self) { for e in self.iter_mut() { - *e = -*e + *e = -e.inlined_clone() } } } @@ -137,7 +137,7 @@ macro_rules! componentwise_binop_impl( $method_to: ident, $method_to_statically_unchecked: ident) => { impl> Matrix - where N: Scalar + Copy + $bound { + where N: Scalar + Clone + $bound { /* * @@ -164,7 +164,7 @@ macro_rules! componentwise_binop_impl( let out = out.data.as_mut_slice(); for i in 0 .. arr1.len() { unsafe { - *out.get_unchecked_mut(i) = arr1.get_unchecked(i).$method(*arr2.get_unchecked(i)); + *out.get_unchecked_mut(i) = arr1.get_unchecked(i).inlined_clone().$method(arr2.get_unchecked(i).inlined_clone()); } } } @@ -172,7 +172,7 @@ macro_rules! componentwise_binop_impl( for j in 0 .. self.ncols() { for i in 0 .. self.nrows() { unsafe { - let val = self.get_unchecked((i, j)).$method(*rhs.get_unchecked((i, j))); + let val = self.get_unchecked((i, j)).inlined_clone().$method(rhs.get_unchecked((i, j)).inlined_clone()); *out.get_unchecked_mut((i, j)) = val; } } @@ -196,7 +196,7 @@ macro_rules! componentwise_binop_impl( let arr2 = rhs.data.as_slice(); for i in 0 .. arr2.len() { unsafe { - arr1.get_unchecked_mut(i).$method_assign(*arr2.get_unchecked(i)); + arr1.get_unchecked_mut(i).$method_assign(arr2.get_unchecked(i).inlined_clone()); } } } @@ -204,7 +204,7 @@ macro_rules! componentwise_binop_impl( for j in 0 .. rhs.ncols() { for i in 0 .. rhs.nrows() { unsafe { - self.get_unchecked_mut((i, j)).$method_assign(*rhs.get_unchecked((i, j))) + self.get_unchecked_mut((i, j)).$method_assign(rhs.get_unchecked((i, j)).inlined_clone()) } } } @@ -226,7 +226,7 @@ macro_rules! componentwise_binop_impl( let arr2 = rhs.data.as_mut_slice(); for i in 0 .. arr1.len() { unsafe { - let res = arr1.get_unchecked(i).$method(*arr2.get_unchecked(i)); + let res = arr1.get_unchecked(i).inlined_clone().$method(arr2.get_unchecked(i).inlined_clone()); *arr2.get_unchecked_mut(i) = res; } } @@ -236,7 +236,7 @@ macro_rules! componentwise_binop_impl( for i in 0 .. self.nrows() { unsafe { let r = rhs.get_unchecked_mut((i, j)); - *r = self.get_unchecked((i, j)).$method(*r) + *r = self.get_unchecked((i, j)).inlined_clone().$method(r.inlined_clone()) } } } @@ -267,7 +267,7 @@ macro_rules! componentwise_binop_impl( impl<'b, N, R1, C1, R2, C2, SA, SB> $Trait<&'b Matrix> for Matrix where R1: Dim, C1: Dim, R2: Dim, C2: Dim, - N: Scalar + Copy + $bound, + N: Scalar + Clone + $bound, SA: Storage, SB: Storage, DefaultAllocator: SameShapeAllocator, @@ -285,7 +285,7 @@ macro_rules! componentwise_binop_impl( impl<'a, N, R1, C1, R2, C2, SA, SB> $Trait> for &'a Matrix where R1: Dim, C1: Dim, R2: Dim, C2: Dim, - N: Scalar + Copy + $bound, + N: Scalar + Clone + $bound, SA: Storage, SB: Storage, DefaultAllocator: SameShapeAllocator, @@ -303,7 +303,7 @@ macro_rules! componentwise_binop_impl( impl $Trait> for Matrix where R1: Dim, C1: Dim, R2: Dim, C2: Dim, - N: Scalar + Copy + $bound, + N: Scalar + Clone + $bound, SA: Storage, SB: Storage, DefaultAllocator: SameShapeAllocator, @@ -318,7 +318,7 @@ macro_rules! componentwise_binop_impl( impl<'a, 'b, N, R1, C1, R2, C2, SA, SB> $Trait<&'b Matrix> for &'a Matrix where R1: Dim, C1: Dim, R2: Dim, C2: Dim, - N: Scalar + Copy + $bound, + N: Scalar + Clone + $bound, SA: Storage, SB: Storage, DefaultAllocator: SameShapeAllocator, @@ -341,7 +341,7 @@ macro_rules! componentwise_binop_impl( impl<'b, N, R1, C1, R2, C2, SA, SB> $TraitAssign<&'b Matrix> for Matrix where R1: Dim, C1: Dim, R2: Dim, C2: Dim, - N: Scalar + Copy + $bound, + N: Scalar + Clone + $bound, SA: StorageMut, SB: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns { @@ -354,7 +354,7 @@ macro_rules! componentwise_binop_impl( impl $TraitAssign> for Matrix where R1: Dim, C1: Dim, R2: Dim, C2: Dim, - N: Scalar + Copy + $bound, + N: Scalar + Clone + $bound, SA: StorageMut, SB: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns { @@ -376,7 +376,7 @@ componentwise_binop_impl!(Sub, sub, ClosedSub; impl iter::Sum for MatrixMN where - N: Scalar + Copy + ClosedAdd + Zero, + N: Scalar + Clone + ClosedAdd + Zero, DefaultAllocator: Allocator, { fn sum>>(iter: I) -> MatrixMN { @@ -386,7 +386,7 @@ where impl iter::Sum for MatrixMN where - N: Scalar + Copy + ClosedAdd + Zero, + N: Scalar + Clone + ClosedAdd + Zero, DefaultAllocator: Allocator, { /// # Example @@ -416,7 +416,7 @@ where impl<'a, N, R: DimName, C: DimName> iter::Sum<&'a MatrixMN> for MatrixMN where - N: Scalar + Copy + ClosedAdd + Zero, + N: Scalar + Clone + ClosedAdd + Zero, DefaultAllocator: Allocator, { fn sum>>(iter: I) -> MatrixMN { @@ -426,7 +426,7 @@ where impl<'a, N, C: Dim> iter::Sum<&'a MatrixMN> for MatrixMN where - N: Scalar + Copy + ClosedAdd + Zero, + N: Scalar + Clone + ClosedAdd + Zero, DefaultAllocator: Allocator, { /// # Example @@ -466,7 +466,7 @@ macro_rules! componentwise_scalarop_impl( ($Trait: ident, $method: ident, $bound: ident; $TraitAssign: ident, $method_assign: ident) => { impl $Trait for Matrix - where N: Scalar + Copy + $bound, + where N: Scalar + Clone + $bound, S: Storage, DefaultAllocator: Allocator { type Output = MatrixMN; @@ -482,7 +482,7 @@ macro_rules! componentwise_scalarop_impl( // for left in res.iter_mut() { for left in res.as_mut_slice().iter_mut() { - *left = left.$method(rhs) + *left = left.inlined_clone().$method(rhs.inlined_clone()) } res @@ -490,7 +490,7 @@ macro_rules! componentwise_scalarop_impl( } impl<'a, N, R: Dim, C: Dim, S> $Trait for &'a Matrix - where N: Scalar + Copy + $bound, + where N: Scalar + Clone + $bound, S: Storage, DefaultAllocator: Allocator { type Output = MatrixMN; @@ -502,13 +502,13 @@ macro_rules! componentwise_scalarop_impl( } impl $TraitAssign for Matrix - where N: Scalar + Copy + $bound, + where N: Scalar + Clone + $bound, S: StorageMut { #[inline] fn $method_assign(&mut self, rhs: N) { for j in 0 .. self.ncols() { for i in 0 .. self.nrows() { - unsafe { self.get_unchecked_mut((i, j)).$method_assign(rhs) }; + unsafe { self.get_unchecked_mut((i, j)).$method_assign(rhs.inlined_clone()) }; } } } @@ -561,7 +561,7 @@ left_scalar_mul_impl!(u8, u16, u32, u64, usize, i8, i16, i32, i64, isize, f32, f impl<'a, 'b, N, R1: Dim, C1: Dim, R2: Dim, C2: Dim, SA, SB> Mul<&'b Matrix> for &'a Matrix where - N: Scalar + Copy + Zero + One + ClosedAdd + ClosedMul, + N: Scalar + Clone + Zero + One + ClosedAdd + ClosedMul, SA: Storage, SB: Storage, DefaultAllocator: Allocator, @@ -582,7 +582,7 @@ where impl<'a, N, R1: Dim, C1: Dim, R2: Dim, C2: Dim, SA, SB> Mul> for &'a Matrix where - N: Scalar + Copy + Zero + One + ClosedAdd + ClosedMul, + N: Scalar + Clone + Zero + One + ClosedAdd + ClosedMul, SB: Storage, SA: Storage, DefaultAllocator: Allocator, @@ -599,7 +599,7 @@ where impl<'b, N, R1: Dim, C1: Dim, R2: Dim, C2: Dim, SA, SB> Mul<&'b Matrix> for Matrix where - N: Scalar + Copy + Zero + One + ClosedAdd + ClosedMul, + N: Scalar + Clone + Zero + One + ClosedAdd + ClosedMul, SB: Storage, SA: Storage, DefaultAllocator: Allocator, @@ -616,7 +616,7 @@ where impl Mul> for Matrix where - N: Scalar + Copy + Zero + One + ClosedAdd + ClosedMul, + N: Scalar + Clone + Zero + One + ClosedAdd + ClosedMul, SB: Storage, SA: Storage, DefaultAllocator: Allocator, @@ -638,7 +638,7 @@ where R1: Dim, C1: Dim, R2: Dim, - N: Scalar + Copy + Zero + One + ClosedAdd + ClosedMul, + N: Scalar + Clone + Zero + One + ClosedAdd + ClosedMul, SB: Storage, SA: ContiguousStorageMut + Clone, ShapeConstraint: AreMultipliable, @@ -655,7 +655,7 @@ where R1: Dim, C1: Dim, R2: Dim, - N: Scalar + Copy + Zero + One + ClosedAdd + ClosedMul, + N: Scalar + Clone + Zero + One + ClosedAdd + ClosedMul, SB: Storage, SA: ContiguousStorageMut + Clone, ShapeConstraint: AreMultipliable, @@ -671,7 +671,7 @@ where // Transpose-multiplication. impl Matrix where - N: Scalar + Copy + Zero + One + ClosedAdd + ClosedMul, + N: Scalar + Clone + Zero + One + ClosedAdd + ClosedMul, SA: Storage, { /// Equivalent to `self.transpose() * rhs`. @@ -810,10 +810,10 @@ where for j2 in 0..ncols2.value() { for i1 in 0..nrows1.value() { unsafe { - let coeff = *self.get_unchecked((i1, j1)); + let coeff = self.get_unchecked((i1, j1)).inlined_clone(); for i2 in 0..nrows2.value() { - *data_res = coeff * *rhs.get_unchecked((i2, j2)); + *data_res = coeff.inlined_clone() * rhs.get_unchecked((i2, j2)).inlined_clone(); data_res = data_res.offset(1); } } @@ -826,7 +826,7 @@ where } } -impl> Matrix { +impl> Matrix { /// Adds a scalar to `self`. #[inline] pub fn add_scalar(&self, rhs: N) -> MatrixMN @@ -841,14 +841,14 @@ impl> Matrix { for e in self.iter_mut() { - *e += rhs + *e += rhs.inlined_clone() } } } impl iter::Product for MatrixN where - N: Scalar + Copy + Zero + One + ClosedMul + ClosedAdd, + N: Scalar + Clone + Zero + One + ClosedMul + ClosedAdd, DefaultAllocator: Allocator, { fn product>>(iter: I) -> MatrixN { @@ -858,7 +858,7 @@ where impl<'a, N, D: DimName> iter::Product<&'a MatrixN> for MatrixN where - N: Scalar + Copy + Zero + One + ClosedMul + ClosedAdd, + N: Scalar + Clone + Zero + One + ClosedMul + ClosedAdd, DefaultAllocator: Allocator, { fn product>>(iter: I) -> MatrixN { @@ -866,7 +866,7 @@ where } } -impl> Matrix { +impl> Matrix { #[inline(always)] fn xcmp(&self, abs: impl Fn(N) -> N2, ordering: Ordering) -> N2 where N2: Scalar + PartialOrd + Zero { @@ -874,7 +874,7 @@ impl> Matrix { let mut max = iter.next().cloned().map_or(N2::zero(), &abs); for e in iter { - let ae = abs(*e); + let ae = abs(e.inlined_clone()); if ae.partial_cmp(&max) == Some(ordering) { max = ae; @@ -967,4 +967,4 @@ impl> Matrix { where N: PartialOrd + Zero { self.xcmp(|e| e, Ordering::Less) } -} \ No newline at end of file +} diff --git a/src/base/properties.rs b/src/base/properties.rs index 020e38d7..74ddf8cf 100644 --- a/src/base/properties.rs +++ b/src/base/properties.rs @@ -9,7 +9,7 @@ use crate::base::dimension::{Dim, DimMin}; use crate::base::storage::Storage; use crate::base::{DefaultAllocator, Matrix, Scalar, SquareMatrix}; -impl> Matrix { +impl> Matrix { /// Indicates if this is an empty matrix. #[inline] pub fn is_empty(&self) -> bool { diff --git a/src/base/scalar.rs b/src/base/scalar.rs index a6c837ff..070dc0a7 100644 --- a/src/base/scalar.rs +++ b/src/base/scalar.rs @@ -13,5 +13,17 @@ pub trait Scalar: PartialEq + Debug + Any { fn is() -> bool { TypeId::of::() == TypeId::of::() } + + #[inline(always)] + /// Performance hack: Clone doesn't get inlined for Copy types in debug mode, so make it inline anyway. + /// + /// Downstream crates need to implement this on any Clone Scalars, as a blanket impl would conflict with with the blanket Copy impl. + fn inlined_clone(&self) -> Self; +} + +impl Scalar for T { + #[inline(always)] + fn inlined_clone(&self) -> T { + *self + } } -impl Scalar for T {} diff --git a/src/base/statistics.rs b/src/base/statistics.rs index d71697d7..8a355c87 100644 --- a/src/base/statistics.rs +++ b/src/base/statistics.rs @@ -3,7 +3,7 @@ use alga::general::{Field, SupersetOf}; use crate::storage::Storage; use crate::allocator::Allocator; -impl> Matrix { +impl> Matrix { /// Returns a row vector where each element is the result of the application of `f` on the /// corresponding column of the original matrix. #[inline] @@ -54,7 +54,7 @@ impl> Matrix { } } -impl, R: Dim, C: Dim, S: Storage> Matrix { +impl, R: Dim, C: Dim, S: Storage> Matrix { /* * * Sum computation. @@ -154,9 +154,10 @@ impl, R: Dim, C: Dim, S: Storage(self.len() as f64); - val.0 * denom - (val.1 * denom) * (val.1 * denom) + let vd = val.1 * denom.inlined_clone(); + val.0 * denom - vd.inlined_clone() * vd } } @@ -213,14 +214,14 @@ impl, R: Dim, C: Dim, S: Storage(ncols.value() as f64); self.compress_columns(mean, |out, col| { for i in 0..nrows.value() { unsafe { let val = col.vget_unchecked(i); - *out.vget_unchecked_mut(i) += denom * *val * *val + *out.vget_unchecked_mut(i) += denom.inlined_clone() * val.inlined_clone() * val.inlined_clone() } } }) @@ -304,7 +305,7 @@ impl, R: Dim, C: Dim, S: Storage(ncols.value() as f64); self.compress_columns(VectorN::zeros_generic(nrows, U1), |out, col| { - out.axpy(denom, &col, N::one()) + out.axpy(denom.inlined_clone(), &col, N::one()) }) } } diff --git a/src/base/storage.rs b/src/base/storage.rs index cbd27527..f1b0177b 100644 --- a/src/base/storage.rs +++ b/src/base/storage.rs @@ -36,7 +36,7 @@ pub type CStride = /// should **not** allow the user to modify the size of the underlying buffer with safe methods /// (for example the `VecStorage::data_mut` method is unsafe because the user could change the /// vector's size so that it no longer contains enough elements: this will lead to UB. -pub unsafe trait Storage: Debug + Sized { +pub unsafe trait Storage: Debug + Sized { /// The static stride of this storage's rows. type RStride: Dim; @@ -117,7 +117,7 @@ pub unsafe trait Storage: Debug + Sized { /// Note that a mutable access does not mean that the matrix owns its data. For example, a mutable /// matrix slice can provide mutable access to its elements even if it does not own its data (it /// contains only an internal reference to them). -pub unsafe trait StorageMut: Storage { +pub unsafe trait StorageMut: Storage { /// The matrix mutable data pointer. fn ptr_mut(&mut self) -> *mut N; @@ -175,7 +175,7 @@ pub unsafe trait StorageMut: Storage: +pub unsafe trait ContiguousStorage: Storage { } @@ -185,7 +185,7 @@ pub unsafe trait ContiguousStorage: /// The storage requirement means that for any value of `i` in `[0, nrows * ncols[`, the value /// `.get_unchecked_linear` returns one of the matrix component. This trait is unsafe because /// failing to comply to this may cause Undefined Behaviors. -pub unsafe trait ContiguousStorageMut: +pub unsafe trait ContiguousStorageMut: ContiguousStorage + StorageMut { } diff --git a/src/base/swizzle.rs b/src/base/swizzle.rs index 4508c758..ec33f8da 100644 --- a/src/base/swizzle.rs +++ b/src/base/swizzle.rs @@ -5,14 +5,14 @@ use typenum::{self, Cmp, Greater}; macro_rules! impl_swizzle { ($( where $BaseDim: ident: $( $name: ident() -> $Result: ident[$($i: expr),+] ),+ ;)* ) => { $( - impl> Vector + impl> Vector where D::Value: Cmp { $( /// Builds a new vector from components of `self`. #[inline] pub fn $name(&self) -> $Result { - $Result::new($(self[$i]),*) + $Result::new($(self[$i].inlined_clone()),*) } )* } diff --git a/src/base/vec_storage.rs b/src/base/vec_storage.rs index a0230488..ffb1ac0c 100644 --- a/src/base/vec_storage.rs +++ b/src/base/vec_storage.rs @@ -102,7 +102,7 @@ impl Into> for VecStorage * Dynamic − Dynamic * */ -unsafe impl Storage for VecStorage +unsafe impl Storage for VecStorage where DefaultAllocator: Allocator { type RStride = U1; @@ -146,7 +146,7 @@ where DefaultAllocator: Allocator } } -unsafe impl Storage for VecStorage +unsafe impl Storage for VecStorage where DefaultAllocator: Allocator { type RStride = U1; @@ -195,7 +195,7 @@ where DefaultAllocator: Allocator * StorageMut, ContiguousStorage. * */ -unsafe impl StorageMut for VecStorage +unsafe impl StorageMut for VecStorage where DefaultAllocator: Allocator { #[inline] @@ -209,13 +209,13 @@ where DefaultAllocator: Allocator } } -unsafe impl ContiguousStorage for VecStorage where DefaultAllocator: Allocator +unsafe impl ContiguousStorage for VecStorage where DefaultAllocator: Allocator {} -unsafe impl ContiguousStorageMut for VecStorage where DefaultAllocator: Allocator +unsafe impl ContiguousStorageMut for VecStorage where DefaultAllocator: Allocator {} -unsafe impl StorageMut for VecStorage +unsafe impl StorageMut for VecStorage where DefaultAllocator: Allocator { #[inline] @@ -244,10 +244,10 @@ impl Abomonation for VecStorage { } } -unsafe impl ContiguousStorage for VecStorage where DefaultAllocator: Allocator +unsafe impl ContiguousStorage for VecStorage where DefaultAllocator: Allocator {} -unsafe impl ContiguousStorageMut for VecStorage where DefaultAllocator: Allocator +unsafe impl ContiguousStorageMut for VecStorage where DefaultAllocator: Allocator {} impl Extend for VecStorage @@ -270,7 +270,7 @@ impl Extend for VecStorage impl Extend> for VecStorage where - N: Scalar + Copy, + N: Scalar + Clone, R: Dim, RV: Dim, SV: Storage, @@ -291,7 +291,7 @@ where self.data.reserve(nrows * lower); for vector in iter { assert_eq!(nrows, vector.shape().0); - self.data.extend(vector.iter()); + self.data.extend(vector.iter().cloned()); } self.ncols = Dynamic::new(self.data.len() / nrows); } diff --git a/src/debug/random_orthogonal.rs b/src/debug/random_orthogonal.rs index 8a3e6486..8b9321f2 100644 --- a/src/debug/random_orthogonal.rs +++ b/src/debug/random_orthogonal.rs @@ -12,7 +12,7 @@ use crate::linalg::givens::GivensRotation; /// A random orthogonal matrix. #[derive(Clone, Debug)] -pub struct RandomOrthogonal +pub struct RandomOrthogonal where DefaultAllocator: Allocator { m: MatrixN, diff --git a/src/debug/random_sdp.rs b/src/debug/random_sdp.rs index 5875faf6..503d8689 100644 --- a/src/debug/random_sdp.rs +++ b/src/debug/random_sdp.rs @@ -13,7 +13,7 @@ use crate::debug::RandomOrthogonal; /// A random, well-conditioned, symmetric definite-positive matrix. #[derive(Clone, Debug)] -pub struct RandomSDP +pub struct RandomSDP where DefaultAllocator: Allocator { m: MatrixN, diff --git a/src/geometry/op_macros.rs b/src/geometry/op_macros.rs index 7ee81f07..2b12a8c9 100644 --- a/src/geometry/op_macros.rs +++ b/src/geometry/op_macros.rs @@ -18,7 +18,7 @@ macro_rules! md_impl( // Lifetime. $($lives: tt),*) => { impl<$($lives ,)* N $(, $Dims: $DimsBound $(<$($BoundParam),*>)*)*> $Op<$Rhs> for $Lhs - where N: Scalar + Copy + Zero + One + ClosedAdd + ClosedMul $($(+ $ScalarBounds)*)*, + where N: Scalar + Clone + Zero + One + ClosedAdd + ClosedMul $($(+ $ScalarBounds)*)*, DefaultAllocator: Allocator + Allocator + Allocator, @@ -96,7 +96,7 @@ macro_rules! md_assign_impl( // Actual implementation and lifetimes. $action: expr; $($lives: tt),*) => { impl<$($lives ,)* N $(, $Dims: $DimsBound $(<$($BoundParam),*>)*)*> $Op<$Rhs> for $Lhs - where N: Scalar + Copy + Zero + One + ClosedAdd + ClosedMul $($(+ $ScalarBounds)*)*, + where N: Scalar + Clone + Zero + One + ClosedAdd + ClosedMul $($(+ $ScalarBounds)*)*, DefaultAllocator: Allocator + Allocator, $( $ConstraintType: $ConstraintBound $(<$( $ConstraintBoundParams $( = $EqBound )*),*>)* ),* @@ -148,7 +148,7 @@ macro_rules! add_sub_impl( $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Result: ty; $action: expr; $($lives: tt),*) => { impl<$($lives ,)* N $(, $Dims: $DimsBound $(<$($BoundParam),*>)*)*> $Op<$Rhs> for $Lhs - where N: Scalar + Copy + $bound, + where N: Scalar + Clone + $bound, DefaultAllocator: Allocator + Allocator + SameShapeAllocator, @@ -172,7 +172,7 @@ macro_rules! add_sub_assign_impl( $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty; $action: expr; $($lives: tt),*) => { impl<$($lives ,)* N $(, $Dims: $DimsBound)*> $Op<$Rhs> for $Lhs - where N: Scalar + Copy + $bound, + where N: Scalar + Clone + $bound, DefaultAllocator: Allocator + Allocator, ShapeConstraint: SameNumberOfRows<$R1, $R2> + SameNumberOfColumns<$C1, $C2> { diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index 923da505..ec4575fa 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -18,7 +18,7 @@ use crate::base::{Matrix4, Scalar, Vector, Vector3}; use crate::geometry::{Point3, Projective3}; /// A 3D perspective projection stored as an homogeneous 4x4 matrix. -pub struct Perspective3 { +pub struct Perspective3 { matrix: Matrix4, } diff --git a/src/geometry/point.rs b/src/geometry/point.rs index 48031ba9..6911db78 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -20,14 +20,14 @@ use crate::base::{DefaultAllocator, Scalar, VectorN}; /// A point in a n-dimensional euclidean space. #[repr(C)] #[derive(Debug, Clone)] -pub struct Point +pub struct Point where DefaultAllocator: Allocator { /// The coordinates of this point, i.e., the shift from the origin. pub coords: VectorN, } -impl hash::Hash for Point +impl hash::Hash for Point where DefaultAllocator: Allocator, >::Buffer: hash::Hash, @@ -45,7 +45,7 @@ where } #[cfg(feature = "serde-serialize")] -impl Serialize for Point +impl Serialize for Point where DefaultAllocator: Allocator, >::Buffer: Serialize, @@ -57,7 +57,7 @@ where } #[cfg(feature = "serde-serialize")] -impl<'a, N: Scalar + Copy, D: DimName> Deserialize<'a> for Point +impl<'a, N: Scalar + Clone, D: DimName> Deserialize<'a> for Point where DefaultAllocator: Allocator, >::Buffer: Deserialize<'a>, @@ -73,7 +73,7 @@ where #[cfg(feature = "abomonation-serialize")] impl Abomonation for Point where - N: Scalar + Copy, + N: Scalar + Clone, D: DimName, VectorN: Abomonation, DefaultAllocator: Allocator, @@ -91,7 +91,7 @@ where } } -impl Point +impl Point where DefaultAllocator: Allocator { /// Converts this point into a vector in homogeneous coordinates, i.e., appends a `1` at the @@ -210,7 +210,7 @@ where DefaultAllocator: Allocator } } -impl AbsDiffEq for Point +impl AbsDiffEq for Point where DefaultAllocator: Allocator, N::Epsilon: Copy, @@ -228,7 +228,7 @@ where } } -impl RelativeEq for Point +impl RelativeEq for Point where DefaultAllocator: Allocator, N::Epsilon: Copy, @@ -251,7 +251,7 @@ where } } -impl UlpsEq for Point +impl UlpsEq for Point where DefaultAllocator: Allocator, N::Epsilon: Copy, @@ -267,9 +267,9 @@ where } } -impl Eq for Point where DefaultAllocator: Allocator {} +impl Eq for Point where DefaultAllocator: Allocator {} -impl PartialEq for Point +impl PartialEq for Point where DefaultAllocator: Allocator { #[inline] @@ -278,7 +278,7 @@ where DefaultAllocator: Allocator } } -impl PartialOrd for Point +impl PartialOrd for Point where DefaultAllocator: Allocator { #[inline] @@ -312,7 +312,7 @@ where DefaultAllocator: Allocator * Display * */ -impl fmt::Display for Point +impl fmt::Display for Point where DefaultAllocator: Allocator { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/src/geometry/point_alga.rs b/src/geometry/point_alga.rs index 0deb52d3..b5ae46b8 100644 --- a/src/geometry/point_alga.rs +++ b/src/geometry/point_alga.rs @@ -7,9 +7,9 @@ use crate::base::{DefaultAllocator, Scalar, VectorN}; use crate::geometry::Point; -impl AffineSpace for Point +impl AffineSpace for Point where - N: Scalar + Copy + Field, + N: Scalar + Clone + Field, DefaultAllocator: Allocator, { type Translation = VectorN; @@ -49,7 +49,7 @@ where DefaultAllocator: Allocator */ impl MeetSemilattice for Point where - N: Scalar + Copy + MeetSemilattice, + N: Scalar + Clone + MeetSemilattice, DefaultAllocator: Allocator, { #[inline] @@ -60,7 +60,7 @@ where impl JoinSemilattice for Point where - N: Scalar + Copy + JoinSemilattice, + N: Scalar + Clone + JoinSemilattice, DefaultAllocator: Allocator, { #[inline] @@ -71,7 +71,7 @@ where impl Lattice for Point where - N: Scalar + Copy + Lattice, + N: Scalar + Clone + Lattice, DefaultAllocator: Allocator, { #[inline] diff --git a/src/geometry/point_construction.rs b/src/geometry/point_construction.rs index 530c18a8..5ba9bc2e 100644 --- a/src/geometry/point_construction.rs +++ b/src/geometry/point_construction.rs @@ -12,7 +12,7 @@ use crate::base::{DefaultAllocator, Scalar, VectorN}; use crate::geometry::Point; -impl Point +impl Point where DefaultAllocator: Allocator { /// Creates a new point with uninitialized coordinates. @@ -94,12 +94,12 @@ where DefaultAllocator: Allocator #[inline] pub fn from_homogeneous(v: VectorN>) -> Option where - N: Scalar + Copy + Zero + One + ClosedDiv, + N: Scalar + Clone + Zero + One + ClosedDiv, D: DimNameAdd, DefaultAllocator: Allocator>, { if !v[D::dim()].is_zero() { - let coords = v.fixed_slice::(0, 0) / v[D::dim()]; + let coords = v.fixed_slice::(0, 0) / v[D::dim()].inlined_clone(); Some(Self::from(coords)) } else { None @@ -112,7 +112,7 @@ where DefaultAllocator: Allocator * Traits that build points. * */ -impl Bounded for Point +impl Bounded for Point where DefaultAllocator: Allocator { #[inline] @@ -126,7 +126,7 @@ where DefaultAllocator: Allocator } } -impl Distribution> for Standard +impl Distribution> for Standard where DefaultAllocator: Allocator, Standard: Distribution, @@ -138,7 +138,7 @@ where } #[cfg(feature = "arbitrary")] -impl Arbitrary for Point +impl Arbitrary for Point where DefaultAllocator: Allocator, >::Buffer: Send, @@ -156,7 +156,7 @@ where */ macro_rules! componentwise_constructors_impl( ($($doc: expr; $D: ty, $($args: ident:$irow: expr),*);* $(;)*) => {$( - impl Point + impl Point where DefaultAllocator: Allocator { #[doc = "Initializes this point from its components."] #[doc = "# Example\n```"] @@ -192,7 +192,7 @@ componentwise_constructors_impl!( macro_rules! from_array_impl( ($($D: ty, $len: expr);*) => {$( - impl From<[N; $len]> for Point { + impl From<[N; $len]> for Point { fn from (coords: [N; $len]) -> Self { Self { coords: coords.into() diff --git a/src/geometry/point_conversion.rs b/src/geometry/point_conversion.rs index b3131f52..d2c5a8c0 100644 --- a/src/geometry/point_conversion.rs +++ b/src/geometry/point_conversion.rs @@ -27,8 +27,8 @@ use std::convert::{AsMut, AsRef, From, Into}; impl SubsetOf> for Point where D: DimName, - N1: Scalar + Copy, - N2: Scalar + Copy + SupersetOf, + N1: Scalar + Clone, + N2: Scalar + Clone + SupersetOf, DefaultAllocator: Allocator + Allocator, { #[inline] @@ -52,8 +52,8 @@ where impl SubsetOf>> for Point where D: DimNameAdd, - N1: Scalar + Copy, - N2: Scalar + Copy + Zero + One + ClosedDiv + SupersetOf, + N1: Scalar + Clone, + N2: Scalar + Clone + Zero + One + ClosedDiv + SupersetOf, DefaultAllocator: Allocator + Allocator> + Allocator> @@ -72,7 +72,7 @@ where #[inline] unsafe fn from_superset_unchecked(v: &VectorN>) -> Self { - let coords = v.fixed_slice::(0, 0) / v[D::dim()]; + let coords = v.fixed_slice::(0, 0) / v[D::dim()].inlined_clone(); Self { coords: crate::convert_unchecked(coords) } @@ -83,7 +83,7 @@ where macro_rules! impl_from_into_mint_1D( ($($NRows: ident => $PT:ident, $VT:ident [$SZ: expr]);* $(;)*) => {$( impl From> for Point - where N: Scalar + Copy { + where N: Scalar + Clone { #[inline] fn from(p: mint::$PT) -> Self { Self { @@ -93,7 +93,7 @@ macro_rules! impl_from_into_mint_1D( } impl Into> for Point - where N: Scalar + Copy { + where N: Scalar + Clone { #[inline] fn into(self) -> mint::$PT { let mint_vec: mint::$VT = self.coords.into(); @@ -102,7 +102,7 @@ macro_rules! impl_from_into_mint_1D( } impl AsRef> for Point - where N: Scalar + Copy { + where N: Scalar + Clone { #[inline] fn as_ref(&self) -> &mint::$PT { unsafe { @@ -112,7 +112,7 @@ macro_rules! impl_from_into_mint_1D( } impl AsMut> for Point - where N: Scalar + Copy { + where N: Scalar + Clone { #[inline] fn as_mut(&mut self) -> &mut mint::$PT { unsafe { @@ -130,7 +130,7 @@ impl_from_into_mint_1D!( U3 => Point3, Vector3[3]; ); -impl From> for VectorN> +impl From> for VectorN> where D: DimNameAdd, DefaultAllocator: Allocator + Allocator>, @@ -141,7 +141,7 @@ where } } -impl From> for Point +impl From> for Point where DefaultAllocator: Allocator, { diff --git a/src/geometry/point_coordinates.rs b/src/geometry/point_coordinates.rs index 1b6edf67..0ccc9441 100644 --- a/src/geometry/point_coordinates.rs +++ b/src/geometry/point_coordinates.rs @@ -16,7 +16,7 @@ use crate::geometry::Point; macro_rules! deref_impl( ($D: ty, $Target: ident $(, $comps: ident)*) => { - impl Deref for Point + impl Deref for Point where DefaultAllocator: Allocator { type Target = $Target; @@ -26,7 +26,7 @@ macro_rules! deref_impl( } } - impl DerefMut for Point + impl DerefMut for Point where DefaultAllocator: Allocator { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { diff --git a/src/geometry/point_ops.rs b/src/geometry/point_ops.rs index 2a4fae03..4f08f526 100644 --- a/src/geometry/point_ops.rs +++ b/src/geometry/point_ops.rs @@ -18,7 +18,7 @@ use crate::geometry::Point; * Indexing. * */ -impl Index for Point +impl Index for Point where DefaultAllocator: Allocator { type Output = N; @@ -29,7 +29,7 @@ where DefaultAllocator: Allocator } } -impl IndexMut for Point +impl IndexMut for Point where DefaultAllocator: Allocator { #[inline] @@ -43,7 +43,7 @@ where DefaultAllocator: Allocator * Neg. * */ -impl Neg for Point +impl Neg for Point where DefaultAllocator: Allocator { type Output = Self; @@ -54,7 +54,7 @@ where DefaultAllocator: Allocator } } -impl<'a, N: Scalar + Copy + ClosedNeg, D: DimName> Neg for &'a Point +impl<'a, N: Scalar + Clone + ClosedNeg, D: DimName> Neg for &'a Point where DefaultAllocator: Allocator { type Output = Point; @@ -138,7 +138,7 @@ add_sub_impl!(Add, add, ClosedAdd; macro_rules! op_assign_impl( ($($TraitAssign: ident, $method_assign: ident, $bound: ident);* $(;)*) => {$( impl<'b, N, D1: DimName, D2: Dim, SB> $TraitAssign<&'b Vector> for Point - where N: Scalar + Copy + $bound, + where N: Scalar + Clone + $bound, SB: Storage, DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows { @@ -150,7 +150,7 @@ macro_rules! op_assign_impl( } impl $TraitAssign> for Point - where N: Scalar + Copy + $bound, + where N: Scalar + Clone + $bound, SB: Storage, DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows { @@ -192,7 +192,7 @@ md_impl_all!( macro_rules! componentwise_scalarop_impl( ($Trait: ident, $method: ident, $bound: ident; $TraitAssign: ident, $method_assign: ident) => { - impl $Trait for Point + impl $Trait for Point where DefaultAllocator: Allocator { type Output = Point; @@ -202,7 +202,7 @@ macro_rules! componentwise_scalarop_impl( } } - impl<'a, N: Scalar + Copy + $bound, D: DimName> $Trait for &'a Point + impl<'a, N: Scalar + Clone + $bound, D: DimName> $Trait for &'a Point where DefaultAllocator: Allocator { type Output = Point; @@ -212,7 +212,7 @@ macro_rules! componentwise_scalarop_impl( } } - impl $TraitAssign for Point + impl $TraitAssign for Point where DefaultAllocator: Allocator { #[inline] fn $method_assign(&mut self, right: N) { diff --git a/src/geometry/reflection.rs b/src/geometry/reflection.rs index 9b4da872..585fe57b 100644 --- a/src/geometry/reflection.rs +++ b/src/geometry/reflection.rs @@ -8,7 +8,7 @@ use crate::storage::{Storage, StorageMut}; use crate::geometry::Point; /// A reflection wrt. a plane. -pub struct Reflection> { +pub struct Reflection> { axis: Vector, bias: N, } diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index 0081262b..9ee8511a 100755 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -24,13 +24,13 @@ use crate::geometry::Point; /// A rotation matrix. #[repr(C)] #[derive(Debug)] -pub struct Rotation +pub struct Rotation where DefaultAllocator: Allocator { matrix: MatrixN, } -impl hash::Hash for Rotation +impl hash::Hash for Rotation where DefaultAllocator: Allocator, >::Buffer: hash::Hash, @@ -47,7 +47,7 @@ where { } -impl Clone for Rotation +impl Clone for Rotation where DefaultAllocator: Allocator, >::Buffer: Clone, @@ -61,7 +61,7 @@ where #[cfg(feature = "abomonation-serialize")] impl Abomonation for Rotation where - N: Scalar + Copy, + N: Scalar + Clone, D: DimName, MatrixN: Abomonation, DefaultAllocator: Allocator, @@ -80,7 +80,7 @@ where } #[cfg(feature = "serde-serialize")] -impl Serialize for Rotation +impl Serialize for Rotation where DefaultAllocator: Allocator, Owned: Serialize, @@ -92,7 +92,7 @@ where } #[cfg(feature = "serde-serialize")] -impl<'a, N: Scalar + Copy, D: DimName> Deserialize<'a> for Rotation +impl<'a, N: Scalar + Clone, D: DimName> Deserialize<'a> for Rotation where DefaultAllocator: Allocator, Owned: Deserialize<'a>, @@ -105,7 +105,7 @@ where } } -impl Rotation +impl Rotation where DefaultAllocator: Allocator { /// A reference to the underlying matrix representation of this rotation. @@ -432,9 +432,9 @@ where DefaultAllocator: Allocator + Allocator } } -impl Eq for Rotation where DefaultAllocator: Allocator {} +impl Eq for Rotation where DefaultAllocator: Allocator {} -impl PartialEq for Rotation +impl PartialEq for Rotation where DefaultAllocator: Allocator { #[inline] @@ -445,7 +445,7 @@ where DefaultAllocator: Allocator impl AbsDiffEq for Rotation where - N: Scalar + Copy + AbsDiffEq, + N: Scalar + Clone + AbsDiffEq, DefaultAllocator: Allocator, N::Epsilon: Copy, { @@ -464,7 +464,7 @@ where impl RelativeEq for Rotation where - N: Scalar + Copy + RelativeEq, + N: Scalar + Clone + RelativeEq, DefaultAllocator: Allocator, N::Epsilon: Copy, { @@ -488,7 +488,7 @@ where impl UlpsEq for Rotation where - N: Scalar + Copy + UlpsEq, + N: Scalar + Clone + UlpsEq, DefaultAllocator: Allocator, N::Epsilon: Copy, { diff --git a/src/geometry/rotation_construction.rs b/src/geometry/rotation_construction.rs index 3e9b2930..514ed439 100644 --- a/src/geometry/rotation_construction.rs +++ b/src/geometry/rotation_construction.rs @@ -10,7 +10,7 @@ use crate::geometry::Rotation; impl Rotation where - N: Scalar + Copy + Zero + One, + N: Scalar + Clone + Zero + One, DefaultAllocator: Allocator, { /// Creates a new square identity rotation of the given `dimension`. @@ -32,7 +32,7 @@ where impl One for Rotation where - N: Scalar + Copy + Zero + One + ClosedAdd + ClosedMul, + N: Scalar + Clone + Zero + One + ClosedAdd + ClosedMul, DefaultAllocator: Allocator, { #[inline] diff --git a/src/geometry/rotation_ops.rs b/src/geometry/rotation_ops.rs index 8b0810a1..553d8c62 100644 --- a/src/geometry/rotation_ops.rs +++ b/src/geometry/rotation_ops.rs @@ -30,7 +30,7 @@ use crate::base::{DefaultAllocator, Matrix, MatrixMN, Scalar, Unit, Vector, Vect use crate::geometry::{Point, Rotation}; -impl Index<(usize, usize)> for Rotation +impl Index<(usize, usize)> for Rotation where DefaultAllocator: Allocator { type Output = N; diff --git a/src/geometry/swizzle.rs b/src/geometry/swizzle.rs index fdcb4743..149bcf02 100644 --- a/src/geometry/swizzle.rs +++ b/src/geometry/swizzle.rs @@ -6,7 +6,7 @@ use typenum::{self, Cmp, Greater}; macro_rules! impl_swizzle { ($( where $BaseDim: ident: $( $name: ident() -> $Result: ident[$($i: expr),+] ),+ ;)* ) => { $( - impl Point + impl Point where DefaultAllocator: Allocator, D::Value: Cmp @@ -15,7 +15,7 @@ macro_rules! impl_swizzle { /// Builds a new point from components of `self`. #[inline] pub fn $name(&self) -> $Result { - $Result::new($(self[$i]),*) + $Result::new($(self[$i].inlined_clone()),*) } )* } diff --git a/src/geometry/translation.rs b/src/geometry/translation.rs index 0e9b37fc..1540da09 100755 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -23,7 +23,7 @@ use crate::geometry::Point; /// A translation. #[repr(C)] #[derive(Debug)] -pub struct Translation +pub struct Translation where DefaultAllocator: Allocator { /// The translation coordinates, i.e., how much is added to a point's coordinates when it is @@ -31,7 +31,7 @@ where DefaultAllocator: Allocator pub vector: VectorN, } -impl hash::Hash for Translation +impl hash::Hash for Translation where DefaultAllocator: Allocator, Owned: hash::Hash, @@ -47,7 +47,7 @@ where Owned: Copy, {} -impl Clone for Translation +impl Clone for Translation where DefaultAllocator: Allocator, Owned: Clone, @@ -61,7 +61,7 @@ where #[cfg(feature = "abomonation-serialize")] impl Abomonation for Translation where - N: Scalar + Copy, + N: Scalar + Clone, D: DimName, VectorN: Abomonation, DefaultAllocator: Allocator, @@ -80,7 +80,7 @@ where } #[cfg(feature = "serde-serialize")] -impl Serialize for Translation +impl Serialize for Translation where DefaultAllocator: Allocator, Owned: Serialize, @@ -92,7 +92,7 @@ where } #[cfg(feature = "serde-serialize")] -impl<'a, N: Scalar + Copy, D: DimName> Deserialize<'a> for Translation +impl<'a, N: Scalar + Clone, D: DimName> Deserialize<'a> for Translation where DefaultAllocator: Allocator, Owned: Deserialize<'a>, @@ -105,7 +105,7 @@ where } } -impl Translation +impl Translation where DefaultAllocator: Allocator { /// Creates a new translation from the given vector. @@ -192,7 +192,7 @@ where DefaultAllocator: Allocator } } -impl Translation +impl Translation where DefaultAllocator: Allocator { /// Translate the given point. @@ -211,7 +211,7 @@ where DefaultAllocator: Allocator } } -impl Translation +impl Translation where DefaultAllocator: Allocator { /// Translate the given point by the inverse of this translation. @@ -228,9 +228,9 @@ where DefaultAllocator: Allocator } } -impl Eq for Translation where DefaultAllocator: Allocator {} +impl Eq for Translation where DefaultAllocator: Allocator {} -impl PartialEq for Translation +impl PartialEq for Translation where DefaultAllocator: Allocator { #[inline] @@ -239,7 +239,7 @@ where DefaultAllocator: Allocator } } -impl AbsDiffEq for Translation +impl AbsDiffEq for Translation where DefaultAllocator: Allocator, N::Epsilon: Copy, @@ -257,7 +257,7 @@ where } } -impl RelativeEq for Translation +impl RelativeEq for Translation where DefaultAllocator: Allocator, N::Epsilon: Copy, @@ -280,7 +280,7 @@ where } } -impl UlpsEq for Translation +impl UlpsEq for Translation where DefaultAllocator: Allocator, N::Epsilon: Copy, diff --git a/src/geometry/translation_construction.rs b/src/geometry/translation_construction.rs index 370fbf63..7ac3c5fc 100644 --- a/src/geometry/translation_construction.rs +++ b/src/geometry/translation_construction.rs @@ -15,7 +15,7 @@ use crate::base::{DefaultAllocator, Scalar, VectorN}; use crate::geometry::Translation; -impl Translation +impl Translation where DefaultAllocator: Allocator { /// Creates a new identity translation. @@ -38,7 +38,7 @@ where DefaultAllocator: Allocator } } -impl One for Translation +impl One for Translation where DefaultAllocator: Allocator { #[inline] @@ -47,7 +47,7 @@ where DefaultAllocator: Allocator } } -impl Distribution> for Standard +impl Distribution> for Standard where DefaultAllocator: Allocator, Standard: Distribution, @@ -59,7 +59,7 @@ where } #[cfg(feature = "arbitrary")] -impl Arbitrary for Translation +impl Arbitrary for Translation where DefaultAllocator: Allocator, Owned: Send, @@ -78,7 +78,7 @@ where */ macro_rules! componentwise_constructors_impl( ($($doc: expr; $D: ty, $($args: ident:$irow: expr),*);* $(;)*) => {$( - impl Translation + impl Translation where DefaultAllocator: Allocator { #[doc = "Initializes this translation from its components."] #[doc = "# Example\n```"] diff --git a/src/geometry/translation_conversion.rs b/src/geometry/translation_conversion.rs index 2a6d9535..ee2f0e6d 100644 --- a/src/geometry/translation_conversion.rs +++ b/src/geometry/translation_conversion.rs @@ -22,8 +22,8 @@ use crate::geometry::{Isometry, Point, Similarity, SuperTCategoryOf, TAffine, Tr impl SubsetOf> for Translation where - N1: Scalar + Copy, - N2: Scalar + Copy + SupersetOf, + N1: Scalar + Clone, + N2: Scalar + Clone + SupersetOf, DefaultAllocator: Allocator + Allocator, { #[inline] @@ -153,7 +153,7 @@ where } } -impl From> for MatrixN> +impl From> for MatrixN> where D: DimNameAdd, DefaultAllocator: Allocator + Allocator, DimNameSum>, @@ -164,7 +164,7 @@ where } } -impl From> for Translation +impl From> for Translation where DefaultAllocator: Allocator { #[inline] diff --git a/src/geometry/translation_coordinates.rs b/src/geometry/translation_coordinates.rs index 97eb5b32..10e5926f 100644 --- a/src/geometry/translation_coordinates.rs +++ b/src/geometry/translation_coordinates.rs @@ -16,7 +16,7 @@ use crate::geometry::Translation; macro_rules! deref_impl( ($D: ty, $Target: ident $(, $comps: ident)*) => { - impl Deref for Translation + impl Deref for Translation where DefaultAllocator: Allocator { type Target = $Target; @@ -26,7 +26,7 @@ macro_rules! deref_impl( } } - impl DerefMut for Translation + impl DerefMut for Translation where DefaultAllocator: Allocator { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { diff --git a/src/linalg/lu.rs b/src/linalg/lu.rs index 9676cd83..42cea3ad 100644 --- a/src/linalg/lu.rs +++ b/src/linalg/lu.rs @@ -318,7 +318,7 @@ where DefaultAllocator: Allocator + Allocator<(usize, usize), D> /// element `matrix[(i, i)]` is provided as argument. pub fn gauss_step(matrix: &mut Matrix, diag: N, i: usize) where - N: Scalar + Copy + Field, + N: Scalar + Clone + Field, S: StorageMut, { let mut submat = matrix.slice_range_mut(i.., i..); @@ -333,7 +333,7 @@ where let (pivot_row, mut down) = submat.rows_range_pair_mut(0, 1..); for k in 0..pivot_row.ncols() { - down.column_mut(k).axpy(-pivot_row[k], &coeffs, N::one()); + down.column_mut(k).axpy(-pivot_row[k].inlined_clone(), &coeffs, N::one()); } } @@ -346,7 +346,7 @@ pub fn gauss_step_swap( i: usize, piv: usize, ) where - N: Scalar + Copy + Field, + N: Scalar + Clone + Field, S: StorageMut, { let piv = piv - i; @@ -364,7 +364,7 @@ pub fn gauss_step_swap( for k in 0..pivot_row.ncols() { mem::swap(&mut pivot_row[k], &mut down[(piv - 1, k)]); - down.column_mut(k).axpy(-pivot_row[k], &coeffs, N::one()); + down.column_mut(k).axpy(-pivot_row[k].inlined_clone(), &coeffs, N::one()); } } diff --git a/src/linalg/permutation_sequence.rs b/src/linalg/permutation_sequence.rs index c7fb9b2b..a7d2e8aa 100644 --- a/src/linalg/permutation_sequence.rs +++ b/src/linalg/permutation_sequence.rs @@ -92,7 +92,7 @@ where DefaultAllocator: Allocator<(usize, usize), D> /// Applies this sequence of permutations to the rows of `rhs`. #[inline] - pub fn permute_rows(&self, rhs: &mut Matrix) + pub fn permute_rows(&self, rhs: &mut Matrix) where S2: StorageMut { for i in self.ipiv.rows_range(..self.len).iter() { rhs.swap_rows(i.0, i.1) @@ -101,7 +101,7 @@ where DefaultAllocator: Allocator<(usize, usize), D> /// Applies this sequence of permutations in reverse to the rows of `rhs`. #[inline] - pub fn inv_permute_rows( + pub fn inv_permute_rows( &self, rhs: &mut Matrix, ) where @@ -115,7 +115,7 @@ where DefaultAllocator: Allocator<(usize, usize), D> /// Applies this sequence of permutations to the columns of `rhs`. #[inline] - pub fn permute_columns( + pub fn permute_columns( &self, rhs: &mut Matrix, ) where @@ -128,7 +128,7 @@ where DefaultAllocator: Allocator<(usize, usize), D> /// Applies this sequence of permutations in reverse to the columns of `rhs`. #[inline] - pub fn inv_permute_columns( + pub fn inv_permute_columns( &self, rhs: &mut Matrix, ) where diff --git a/src/sparse/cs_matrix.rs b/src/sparse/cs_matrix.rs index e8c259a2..9cc6b51b 100644 --- a/src/sparse/cs_matrix.rs +++ b/src/sparse/cs_matrix.rs @@ -25,7 +25,7 @@ impl<'a, N> ColumnEntries<'a, N> { } } -impl<'a, N: Copy> Iterator for ColumnEntries<'a, N> { +impl<'a, N: Clone> Iterator for ColumnEntries<'a, N> { type Item = (usize, N); #[inline] @@ -33,8 +33,8 @@ impl<'a, N: Copy> Iterator for ColumnEntries<'a, N> { if self.curr >= self.i.len() { None } else { - let res = Some((unsafe { *self.i.get_unchecked(self.curr) }, unsafe { - *self.v.get_unchecked(self.curr) + let res = Some((unsafe { self.i.get_unchecked(self.curr).clone() }, unsafe { + self.v.get_unchecked(self.curr).clone() })); self.curr += 1; res @@ -105,7 +105,7 @@ pub trait CsStorageMut: /// A storage of column-compressed sparse matrix based on a Vec. #[derive(Clone, Debug, PartialEq)] -pub struct CsVecStorage +pub struct CsVecStorage where DefaultAllocator: Allocator { pub(crate) shape: (R, C), @@ -114,7 +114,7 @@ where DefaultAllocator: Allocator pub(crate) vals: Vec, } -impl CsVecStorage +impl CsVecStorage where DefaultAllocator: Allocator { /// The value buffer of this storage. @@ -133,9 +133,9 @@ where DefaultAllocator: Allocator } } -impl CsVecStorage where DefaultAllocator: Allocator {} +impl CsVecStorage where DefaultAllocator: Allocator {} -impl<'a, N: Scalar + Copy, R: Dim, C: Dim> CsStorageIter<'a, N, R, C> for CsVecStorage +impl<'a, N: Scalar + Clone, R: Dim, C: Dim> CsStorageIter<'a, N, R, C> for CsVecStorage where DefaultAllocator: Allocator { type ColumnEntries = ColumnEntries<'a, N>; @@ -154,7 +154,7 @@ where DefaultAllocator: Allocator } } -impl CsStorage for CsVecStorage +impl CsStorage for CsVecStorage where DefaultAllocator: Allocator { #[inline] @@ -199,7 +199,7 @@ where DefaultAllocator: Allocator } } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim> CsStorageIterMut<'a, N, R, C> for CsVecStorage +impl<'a, N: Scalar + Clone, R: Dim, C: Dim> CsStorageIterMut<'a, N, R, C> for CsVecStorage where DefaultAllocator: Allocator { type ValuesMut = slice::IterMut<'a, N>; @@ -220,11 +220,11 @@ where DefaultAllocator: Allocator } } -impl CsStorageMut for CsVecStorage where DefaultAllocator: Allocator +impl CsStorageMut for CsVecStorage where DefaultAllocator: Allocator {} /* -pub struct CsSliceStorage<'a, N: Scalar + Copy, R: Dim, C: DimAdd> { +pub struct CsSliceStorage<'a, N: Scalar + Clone, R: Dim, C: DimAdd> { shape: (R, C), p: VectorSlice>, i: VectorSlice, @@ -234,7 +234,7 @@ pub struct CsSliceStorage<'a, N: Scalar + Copy, R: Dim, C: DimAdd> { /// A compressed sparse column matrix. #[derive(Clone, Debug, PartialEq)] pub struct CsMatrix< - N: Scalar + Copy, + N: Scalar + Clone, R: Dim = Dynamic, C: Dim = Dynamic, S: CsStorage = CsVecStorage, @@ -246,7 +246,7 @@ pub struct CsMatrix< /// A column compressed sparse vector. pub type CsVector> = CsMatrix; -impl CsMatrix +impl CsMatrix where DefaultAllocator: Allocator { /// Creates a new compressed sparse column matrix with the specified dimension and @@ -323,7 +323,7 @@ where DefaultAllocator: Allocator } /* -impl CsMatrix { +impl CsMatrix { pub(crate) fn from_parts( nrows: usize, ncols: usize, @@ -340,7 +340,7 @@ impl CsMatrix { } */ -impl> CsMatrix { +impl> CsMatrix { pub(crate) fn from_data(data: S) -> Self { CsMatrix { data, @@ -433,7 +433,7 @@ impl> CsMatrix> CsMatrix { +impl> CsMatrix { /// Iterator through all the mutable values of this sparse matrix. #[inline] pub fn values_mut(&mut self) -> impl Iterator { @@ -441,7 +441,7 @@ impl> CsMatrix CsMatrix +impl CsMatrix where DefaultAllocator: Allocator { pub(crate) fn sort(&mut self) @@ -470,7 +470,7 @@ where DefaultAllocator: Allocator // Permute the values too. for (i, irow) in range.clone().zip(self.data.i[range].iter().cloned()) { - self.data.vals[i] = workspace[irow]; + self.data.vals[i] = workspace[irow].inlined_clone(); } } } @@ -492,11 +492,11 @@ where DefaultAllocator: Allocator let curr_irow = self.data.i[idx]; if curr_irow == irow { - value += self.data.vals[idx]; + value += self.data.vals[idx].inlined_clone(); } else { self.data.i[curr_i] = irow; self.data.vals[curr_i] = value; - value = self.data.vals[idx]; + value = self.data.vals[idx].inlined_clone(); irow = curr_irow; curr_i += 1; } diff --git a/src/sparse/cs_matrix_conversion.rs b/src/sparse/cs_matrix_conversion.rs index 251fa282..0844f22c 100644 --- a/src/sparse/cs_matrix_conversion.rs +++ b/src/sparse/cs_matrix_conversion.rs @@ -7,7 +7,7 @@ use crate::sparse::{CsMatrix, CsStorage}; use crate::storage::Storage; use crate::{DefaultAllocator, Dim, Dynamic, Matrix, MatrixMN, Scalar}; -impl<'a, N: Scalar + Copy + Zero + ClosedAdd> CsMatrix { +impl<'a, N: Scalar + Clone + Zero + ClosedAdd> CsMatrix { /// Creates a column-compressed sparse matrix from a sparse matrix in triplet form. pub fn from_triplet( nrows: usize, @@ -21,7 +21,7 @@ impl<'a, N: Scalar + Copy + Zero + ClosedAdd> CsMatrix { } } -impl<'a, N: Scalar + Copy + Zero + ClosedAdd, R: Dim, C: Dim> CsMatrix +impl<'a, N: Scalar + Clone + Zero + ClosedAdd, R: Dim, C: Dim> CsMatrix where DefaultAllocator: Allocator + Allocator { /// Creates a column-compressed sparse matrix from a sparse matrix in triplet form. @@ -66,7 +66,7 @@ where DefaultAllocator: Allocator + Allocator } } -impl<'a, N: Scalar + Copy + Zero, R: Dim, C: Dim, S> From> for MatrixMN +impl<'a, N: Scalar + Clone + Zero, R: Dim, C: Dim, S> From> for MatrixMN where S: CsStorage, DefaultAllocator: Allocator, @@ -85,7 +85,7 @@ where } } -impl<'a, N: Scalar + Copy + Zero, R: Dim, C: Dim, S> From> for CsMatrix +impl<'a, N: Scalar + Clone + Zero, R: Dim, C: Dim, S> From> for CsMatrix where S: Storage, DefaultAllocator: Allocator + Allocator, @@ -103,7 +103,7 @@ where for i in 0..nrows.value() { if !column[i].is_zero() { res.data.i[nz] = i; - res.data.vals[nz] = column[i]; + res.data.vals[nz] = column[i].inlined_clone(); nz += 1; } } diff --git a/src/sparse/cs_matrix_ops.rs b/src/sparse/cs_matrix_ops.rs index 9e827e3c..e602fec6 100644 --- a/src/sparse/cs_matrix_ops.rs +++ b/src/sparse/cs_matrix_ops.rs @@ -8,7 +8,7 @@ use crate::sparse::{CsMatrix, CsStorage, CsStorageMut, CsVector}; use crate::storage::StorageMut; use crate::{DefaultAllocator, Dim, Scalar, Vector, VectorN, U1}; -impl> CsMatrix { +impl> CsMatrix { fn scatter( &self, j: usize, @@ -28,9 +28,9 @@ impl> CsMatrix> CsMatrix CsVector { +impl CsVector { pub fn axpy(&mut self, alpha: N, x: CsVector, beta: N) { // First, compute the number of non-zero entries. let mut nnzero = 0; @@ -76,7 +76,7 @@ impl CsVector { } */ -impl> Vector { +impl> Vector { /// Perform a sparse axpy operation: `self = alpha * x + beta * self` operation. pub fn axpy_cs(&mut self, alpha: N, x: &CsVector, beta: N) where @@ -88,18 +88,18 @@ impl Mul<&'b CsMatrix> for &'a CsMatrix where - N: Scalar + Copy + ClosedAdd + ClosedMul + Zero, + N: Scalar + Clone + ClosedAdd + ClosedMul + Zero, R1: Dim, C1: Dim, R2: Dim, @@ -159,14 +159,14 @@ where for (i, beta) in rhs.data.column_entries(j) { for (k, val) in self.data.column_entries(i) { - workspace[k] += val * beta; + workspace[k] += val.inlined_clone() * beta.inlined_clone(); } } for (i, val) in workspace.as_mut_slice().iter_mut().enumerate() { if !val.is_zero() { res.data.i[nz] = i; - res.data.vals[nz] = *val; + res.data.vals[nz] = val.inlined_clone(); *val = N::zero(); nz += 1; } @@ -219,7 +219,7 @@ where impl<'a, 'b, N, R1, R2, C1, C2, S1, S2> Add<&'b CsMatrix> for &'a CsMatrix where - N: Scalar + Copy + ClosedAdd + ClosedMul + One, + N: Scalar + Clone + ClosedAdd + ClosedMul + One, R1: Dim, C1: Dim, R2: Dim, @@ -273,7 +273,7 @@ where res.data.i[range.clone()].sort(); for p in range { - res.data.vals[p] = workspace[res.data.i[p]] + res.data.vals[p] = workspace[res.data.i[p]].inlined_clone() } } @@ -287,7 +287,7 @@ where impl<'a, 'b, N, R, C, S> Mul for CsMatrix where - N: Scalar + Copy + ClosedAdd + ClosedMul + Zero, + N: Scalar + Clone + ClosedAdd + ClosedMul + Zero, R: Dim, C: Dim, S: CsStorageMut, @@ -296,7 +296,7 @@ where fn mul(mut self, rhs: N) -> Self::Output { for e in self.values_mut() { - *e *= rhs + *e *= rhs.inlined_clone() } self