Questions tagged [nalgebra]

nalgebra is a linear algebra library written for Rust

Filter by
Sorted by
Tagged with
0 votes
0 answers
25 views

Element-wise inverse square root of dynamic matrices

Is there a method to use the nalgebra glm methods on dynamically sized matrices The aim is to Find X such that X†SX = I: the current method is X=Us^{-1/2}U† where S=UsU†: // in general these will be ...
0 votes
1 answer
42 views

Similar function to numpy.dot with nalgebra in Rust

I recently started to use nalgebra, but I can't for the life of me figure out how to do a regular dot product, like below: This is similar to how in Python, you can do this: import numpy as np arr1 =...
  • 2,024
0 votes
1 answer
58 views

How to convert a Matrix4<f32> into a [f32; 4] using nalgebra

I have a Matrix4<f32> representing a transformation. I would like to convert it to a [f32; 16] to use with wgpu. I've not managed to find the right method (if there is one at all).
0 votes
1 answer
54 views

Is there a way to get Euler angle orders in nalgebra or another Rust library?

I'm trying to convert raw quaternion values to Euler angles in order zyx. I'm trying to use nalgebra rotations to convert, but the in-built conversion only gives angles in order xyz. Is there a way to ...
1 vote
0 answers
60 views

How to Append matrices together in nalgebra Rust?

Suppose I have a matrix [[1,0],[0,1]] and [[2,0],[0,2]] I want to figure out a way to combine these 2 matrices into [[1,0,2,0],[0,1,0,2]]. I cannot find the appropriate constructor in the ...
0 votes
1 answer
107 views

Rust nalgebra - new_random() throws error for DMatrix

Im trying to port https://github.com/markkraay/mnist-from-scratch to rust as an introduction to ML and the rust programming language. I've decided to use nalgebra instead of rewriting a matrix library....
0 votes
0 answers
48 views

nalgebra, decomposing homogeneous matrix into operations

Does nalgebra have a built in method to decompose a 4x4 homogeneous matrix into its rotation, scaling and translation components? I went through the documentation but I cannot find anything on the ...
  • 7,766
0 votes
0 answers
55 views

How can I call complex_eigenvalues on a generically sized nalgebra matrix?

I'm using Rust 1.65.0 and nalgebra 0.31.3. Following this blog post, I would like to write a generic function to compute roots of polynomials, without using dynamic memory allocation: use nalgebra::{...
  • 12.9k
1 vote
1 answer
106 views

nalgebra type annotations for converting Matrix to DMatrix

I'm trying to convert a static matrix into a dynamic matrix using a function. Reason being is that I'm comparing two matrices for unit-testing. Thus the test_value from the test, and the benchmark ...
  • 467
0 votes
0 answers
28 views

How to convert an OMatrix to a vector and use it to populate a single row of a DMatrix in Rust?

I have an OLS fitting function that returns an OMatrix. The return type should always be a one-dimensional vector of coefficients. use std::f64::NAN; use nalgebra::{DMatrix, Dynamic, MatrixSlice, ...
  • 6,702
0 votes
0 answers
69 views

Slicing a `DMatrix` and inserting the elements of that sub-matrix into a new matrix in Rust?

I have a function that takes in a 2-D DMatrix, x as a parameter, operates on slices of x and takes the output of the operation and inserts it into a new output matrix. What I have so far, with code ...
  • 6,702
0 votes
1 answer
127 views

How does the Rust nalgebra crate implement broadcast operations on matrix?

I'm learning to use the nalgebra library and the problem I'm having is: how to add, subtract, multiply, divide a number for each element in a matrix? Say I have a 2x3 matrix which has i32 elements: ...
  • 35
1 vote
0 answers
50 views

Use nalgebra with float types from rug

Is it possible to replace the rust f64 fundamental type with rug::Float types? If so, which traits must be implemented in order to call svd() on a nalgebra matrix?
0 votes
0 answers
59 views

Wrong number of rows / columns in nalgebra SMatrix generated from iterator

The following code: let m: SMatrix<f64, 2, 3> = SMatrix::from_iterator((1..).map(|x| x as f64)); println!("{:?}", m); produces the following output: [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]...
  • 166
2 votes
1 answer
140 views

Error multiplying matrix by vector with generic sizing using nalgebra

Running into what seems like an odd issue when trying to multiply a square matrix A with X rows and X columns by a vector x with X rows, constructed from a struct with generic sizing. Just a basic A*x ...
0 votes
0 answers
134 views

rust nalgebra set a block in matrix to rotation?

I am trying to set the upper left block of a 4X4 matrix to a rotation matrix. I have tried different flavours of: let mut mat = Mat4::identity(); mat.set_column(3, &Vec4::new(trans.x, ...
  • 7,766
1 vote
0 answers
74 views

Calculate matrix null space through rust nalgebra library

How can I get the basis of the null space (kernel) of a matrix through the rust nalgebra lib?
  • 2,714
1 vote
0 answers
118 views

Nalgerba, how is the axis angle represented for a unit quaternion?

The docs for nalgebra say fn new(axisangle: Vector3<N>) -> UnitQuaternion<N>[−] Creates a new unit quaternion from the axis-angle representation of a rotation. That's great, except, ...
  • 7,766
0 votes
0 answers
51 views

How to construct a dynamically-dimensioned type based on of nalgebra::OPoint and simultaneously implement its constant-dimensioned functions?

Background For a geometry library in Rust we need bounding boxes. As we need bounding boxes in several dimensions (mostly 2 and 3), we need implementations in every required dimension. To reduce the ...
  • 99
2 votes
1 answer
249 views

rust nalgebra, how to modify a matrix block?

I am using nalgebra and trying to do the following: Given a large dense amtrix, e.g. a 5x5. I want to grab a block of that matrix, e.e.g a 4x5 sublock, and treat that block as a matrix. I want to ...
  • 7,766
0 votes
1 answer
265 views

Initialize a matrix in Rust using the "nalgebra" crate

How can I initialize a 3D matrix in Rust given the number number of component in x, y, z and a given nuber for intialization (let's say 1.0). At the moment I use no librares: let nx: usize = 100; ...
0 votes
1 answer
88 views

How do I calculate inner product of two vectors in nalgebra?

From the following let v = OVector::<f64, U2>::from_column_slice(&[3_f64, 4_f64]); let x = &v.transpose() * &v; // get the inner product, i.e. <v,v> I expected x to be ...
  • 172
1 vote
0 answers
39 views

Compiler does not believe that my trait bound is enforcing the trait that it has to be enforcing [duplicate]

I am trying to compile code such as the following: lib.rs use nalgebra::ComplexField; use num::FromPrimitive; use bacon_sci::polynomial; use bacon_sci::polynomial::Polynomial; fn foo <R> () -&...
  • 506
0 votes
0 answers
305 views

Is there a way to convert rust nalgebra matrix into ndarray

I am using ode_solvers::dopri5::Dopri5 and it returns a nalgebra matrix is it possible for me to convert this to ndarray or whould it be easyer to implement rk45 myself to solve my ode's in this ...
1 vote
2 answers
59 views

How do I reduce repeated generic specification?

In this example, I repeat na::SVector<f64, NumStates> a bunch, can I define a type type StateVector = na::SVector<f64, NumStates>; like this? I get an error that associated type defaults ...
0 votes
1 answer
259 views

Rust: nalgebra transpose

I've started to practice rust. I've run the program and got: VecStorage { data: [1.0, 88.0, 87.0, 1.0, 70.0, 77.0, 1.0, 80.0, 79.0, 1.0, 82.0, 85.0, 1.0, 90.0, 97.0, 1.0, 100.0, 98.0], nrows: Dynamic {...
0 votes
0 answers
192 views

How to satisfy trait bounds on nalgebra SVD

I have the following working code: use nalgebra::{DMatrix, SVector, RealField, convert}; pub fn polyfit<T: RealField, const N: usize>( x_values: &[T; N], y_values: &[T; N], ...
0 votes
1 answer
515 views

nalgebra apply function to every element of a vector

sorry if this is a noob question but is it posible to apply a function to every element in a nalgebra vector? if I for example have a vector like this: type Vector2x1 = SVector<f32, 2>; let ...
0 votes
1 answer
840 views

Rust nalgebra inverse matrix

Does anyone no a simple way to get the inverse of a matrix using the Rust nalgebra::Matrix ? I'm trying to do this the same way as with the C++ Eigen library but clearly not working. #cargo.toml [...
  • 2,240
0 votes
0 answers
114 views

nalgebra OVector vs SVector?

What's the difference between OVector and SVector in nalgebra? Why is there no SPoint?
  • 1,795
3 votes
0 answers
158 views

Rust trait bound bloat / lack of inheritance

I'm trying to wrap the nalgebra and/or ndarray Rust crates into an abstract LinearOperator trait and corresponding AdjointableOperator etc. traits. The problem is that I get significant “trait bound ...
1 vote
1 answer
97 views

nalgebra convention about roll pitch yaw

I write small ray tracer to learn rust language. I decided to use nalgebra as library for vectors and so on. https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=...
  • 1,303
0 votes
0 answers
160 views

Is it possible to expose nalgebra matrix types to python via pyo3 in rust

I'm able to expose simple functions written in Rust to python using pyo3 but can see no way to expose complex "eigen" / matrix types. Does anyone know if this is possible? lib.rs extern ...
  • 2,240
3 votes
3 answers
832 views

How do I create an nalgebra static matrix by copying from a dynamic matrix view?

I'm trying to create a na::Matrix2x3 by copying from the first two rows of a na::Matrix3. The result will be stored in a struct. I don't know how to do this and the documentation is confusing. I tried ...
  • 501
3 votes
2 answers
161 views

Extract original slice from SliceStorage and SliceStorageMut

I am working on some software where I am managing a buffer of floats in a Vec<T> where T is either an f32 or f64. I sometimes need to interpret this buffer, or sections of it, as a mathematical ...
  • 115
2 votes
1 answer
269 views

Why is Rust unable to figure out the correct `from_iterator` to use when constructing a nalgebra::MatrixN?

I have a struct defined as: use nalgebra::{ allocator::Allocator, DefaultAllocator, Dim, DimName, MatrixN, RowVectorN, VectorN, U1, }; // 0.22.0 pub struct Filter<Order: Dim + DimName> ...
  • 4,490
1 vote
1 answer
410 views

How do I get a (1.0, 1.0, 1.0) Vector3 from the nalgebra crate?

I'm trying to create a Vector3 from the nalgebra crate with components (1.0, 1.0, 1.0). I can't find what I need from the documentation, and my IDE's suggestions don't help.
  • 37
1 vote
1 answer
542 views

How to convert from nalgebra::Matrix to Eigen::MatrixXf correctly?

I have a DLL written in C++ and I need to call a function called print_matrix(Eigen::MatrixXf *m) from a Rust program. I created the a 4x3 mactrix and the function in question takes a pointer as its ...
2 votes
1 answer
620 views

nalgebra: Implementing a function for a generic MatrixMN

I'm trying to implement the exp function for a generic square MatrixMN pub fn exp<N, R>(m: &MatrixMN<N, R, R>, k: usize) -> MatrixMN<N, R, R> where N: Scalar + One + Zero,...
0 votes
1 answer
389 views

How to average two points in nalgebra?

I have a triangle ABC, and I want to generate triangle DEF. Triangle DEF is created using the centre of all edges of ABC. Nalgebra doesn't seem to allow me to do add points together, only vectors. ...
  • 14.7k
0 votes
0 answers
711 views

How do I rotate an object so that it's always facing the mouse position?

I'm using ggez to make a game with some friends, and I'm trying to have our character rotate to face the pointer at all times. I know so far that I need to get an angle value (f32) in radians, and I ...
0 votes
2 answers
361 views

Is there a good way to do an overlapping copy in ndarray in rust?

Here's what I tried use ndarray::{arr2, s}; let mut a = arr2(&[[1, 2, 3], [4, 5, 6]]); let b = arr2(&[[2, 3, 3], [5, 6, 6]]); a.slice_mut(s![.., ..2])....