dlaidig / vqf

137 stars 24 forks source link

VQF function (Python) - ValueError: ndarray is not C-contiguous #6

Closed mluacnunes closed 1 year ago

mluacnunes commented 1 year ago

Hi,

First of all, thank you for sharing your work!

I was trying to use VQF to calculate quarternions (ENU convention) from inertial data collected in an environment with magnetic disturbances:

from vqf import VQF
rate = 100  # Hz
vqf = VQF(1 / rate)
q_dict = vqf.updateBatch(gyro_dt, acc_dt, mag_dt)

Where gyro_dt, acc_dt and mag_dt and numpy arrays with shape (7677, 3).

Nevertheless, I got the following error, that seems to be related with the implementation of VQF class's updateBatch function in cython.

File "vqf\vqf.pyx", line 394, in vqf.vqf.VQF.updateBatch
ValueError: ndarray is not C-contiguous

Can you help me?

dlaidig commented 1 year ago

Hi,

The Cython functions expect the input arrays to be in C-contiguous memory order. This is apparently not the case for your data, which might be the result of transposing or indexing (and can happen when loading the data). You can easily fix this with np.ascontiguousarray:

import numpy as np
q_dict = vqf.updateBatch(np.ascontiguousarray(gyro_dt), np.ascontiguousarray(acc_dt), np.ascontiguousarray(mag_dt))

(If you care about speed and process the same data multiple times, you will want to only call np.ascontiguousarray once after loading the data.)