[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
proposed implementation of interpn
From: |
John W. Eaton |
Subject: |
proposed implementation of interpn |
Date: |
Thu, 8 Feb 2007 19:09:41 -0500 |
On 8-Feb-2007, Alexander Barth wrote:
| I noticed also that C-arrays can be significantly faster than octave's
| NDArray. Does NDArray performs bound-checking per default?
No, but the indexing operators must manage reference counts if the
array is non-const, so that could explain the difference.
| /*
|
| Copyright (C) 2007 Alexander Barth
|
| Octave is free software; you can redistribute it and/or modify it
Unless the code is part of Octave, the copyright statement for your
code should just say
This program is free software; ...
| void lin_interpn(int& n, int* size, int* scale, int& Ni, double extrapval,
double** x,double* v, double** y, double* vi)
| {
| bool out = false;
| int bit;
| double* coef = new double[2*n];
| int* index = new int[n];
Bare new/delete is discouraged for Octave code. If you want a local
buffer that is cleaned up automatically, use the OCTAVE_LOCAL_BUFFER
macro.
| if (nargin % 2 == 0)
| {
| error("Wrong number of arguments");
| return octave_value();
| }
Please use the print_usage function for usage messages.
| NDArray V = args(n).array_value();
| NDArray Vi = NDArray(args(n+1).dims());
| double* v = V.fortran_vec();
| double* vi = Vi.fortran_vec();
|
| int Ni = Vi.numel();
|
| int* scale = new int[n];
| int* size = new int[n];
|
|
| double extrapval = octave_NaN;
|
| for (int i = 0; i < n; i++)
| {
| X[i] = args(i).array_value();
| Y[i] = args(n+i+1).array_value();
|
Any time you extract a value from an octave_value object, you should
check error_state to avoid crashes if incorrect types are passed to
your function.
| if (isvector(X[0].dims()))
Instead of working with dims, I'd suggest writing a function to work on
Array objects.
| {
| for (int i = 0; i < n; i++)
| {
| if (~isvector(X[i].dims()) && X[i].numel() != size[i])
| {
| error("Incompatible size of argument number %d",i+1);
To be consistent with other error messages in Octave, you should not
capitalize the message. It also usually helps to start with the name
of the function. For example:
error ("interpn: incompatible size of argument number %d", i+1);
jwe