[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: extract a row from an NDArray
From: |
c. |
Subject: |
Re: extract a row from an NDArray |
Date: |
Tue, 5 May 2009 07:39:10 +0200 |
On 5 May 2009, at 07:27, Jaroslav Hajek wrote:
On Tue, May 5, 2009 at 7:03 AM, c. <address@hidden> wrote:
Hi,
What is the best way to extract a row from an NDArray in an .oct
file?
I am looking for a way to translate an m-file containing
w = squeeze(coefs(4,:,:))
into C++.
Thanks,
Carlo
Indexing by more than two indices requires building an index array
(C++ offers no good way to create methods with arbitrary number of
arguments).
Array<idx_vector> idx(3, idx_vector::colon); idx(0) = 4;
NDArray w = coefs.index (idx).squeeze ();
cheers
Jaroslav, thanks!
This seems to work only with 3.1 though:
-----------------------
#include <iostream>
#include <octave/oct.h>
DEFUN_DLD(provacc, args, nargout,"\
provacc: Undocumented private function\
")
{
octave_value_list retval;
const NDArray coefs = args(0).array_value ();
if (!error_state)
{
Array<idx_vector> idx(3, idx_vector::colon); idx(0) = 1;
NDArray w = coefs.index (idx).squeeze ();
retval(0) = octave_value(w);
}
return retval;
}
-----------------------
$ mkoctfile provacc.cc
provacc.cc: In function ‘octave_value_list Fprovacc(const
octave_value_list&, int)’:
provacc.cc:16: error: ‘colon’ is not a member of ‘idx_vector’
provacc.cc:17: error: conversion from ‘ArrayN<double>’ to non-scalar
type ‘NDArray’ requested
$ /opt/octave/3.1/bin/mkoctfile provacc.cc
$
-----------------------
is there a way to do this that is compatible with the 3.0 release as
well?
c.