Question about subvector

Issue #440 resolved
luis.dias created an issue

Hi,
given vector A and vector B
Is it possible to assign a subvector of vector B to a specific range, subvector?, of vector A?

I can’t find a way to properly do it.

This is the specific part of my code where I am trying to do something like what I described:

        blaze::DynamicVector<float> y_shiftedAux1{ 2 * PI * fSearch[ii] * t_vec};
        blaze::DynamicVector<complex<float>> y_shiftedAux;
        y_shiftedAux = map(y_shiftedAux1, [](float v) { return complex<float>(cos(v), -sin(v)); });
        blaze::DynamicVector<complex<float>> y_shifted;
        y_shifted = y * y_shiftedAux;

        blaze::DynamicVector <complex<float>,aligned> y_trunc_reversed;
        y_trunc_reversed[0] = y_shifted[N_fft_xcorr - 1];
        auto y_sv2 = blaze::subvector(y_trunc_reversed, 1, N_fft_xcorr - 1);
        y_sv2 = blaze::subvector<aligned>(y_shifted, 0, N_fft_xcorr - 2);

The last line y_sv2 = blaze::subvector<aligned>(y_shifted, 0, N_fft_xcorr - 2); is where I need help.

I also would like to know if I can use subvector to create aligned vector from non-aligned vector.

Comments (5)

  1. Klaus Iglberger

    Hi Luis!

    The problem lies in the following line:

    blaze::DynamicVector <complex<float>,aligned> y_trunc_reversed;
    

    In this line you use the aligned flag in the place where the DynamicVector expects its transpose flag (i.e. the flag that distinguishes between row vectors and column vectors). Due to this you accidentally declare y_trunc_reversed as row vector, where all the other vectors are column vectors. Since Blaze does not allow the assignment of a row vector to a column vector, the code does not compile. The solution is to simply remove the flag:

    blaze::DynamicVector <complex<float>> y_trunc_reversed;
    

    To answer your second question: all basic vectors (DynamicVector, StaticVector, and HybridVector) are properly aligned on their own. So it is never necessary to specify an alignment flag for these types of vectors. However, since subvectors can refer to any range within these vectors, they can be aligned or unaligned. And yes, it is possible to create an aligned subvector from an unaligned subvector. However, the alignment is checked at runtime during the setup of the subvector (unless explicitly turned off by means of the unchecked argument):

    blaze::DynamicVector<int> v( 100UL );
    auto sv = subvector( v, 10UL, 20UL, unchecked );  // Creating an unchecked subvector
    

    I hope this helps,

    Best regards,

    Klaus!

  2. Log in to comment