help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: convert octave Matrix object to std::vector and viceversa


From: Mike Miller
Subject: Re: convert octave Matrix object to std::vector and viceversa
Date: Thu, 12 Mar 2020 18:58:19 -0700

On Thu, Mar 12, 2020 at 16:49:49 -0500, niconeuman wrote:
> Is there a simple and fast way of casting an octave Matrix of size (N,1) to
> std::vector inside an Oct-file?

By "casting" do you mean a zero-copy way of sharing the same internal
buffer? There is no easy way to do that, and seems very unsafe.

If copying is ok, then the simplest way is

    std::copy_n (matrix.data (), matrix.numel (), vector.begin ());

> And the other way around?

    std::copy_n (vector.begin (), vector.size (), matrix.data ());

Hope that helps,

-- 
mike

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]