[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: proposed implementation of interpn
From: |
Alexander Barth |
Subject: |
Re: proposed implementation of interpn |
Date: |
Mon, 12 Feb 2007 22:35:18 -0500 |
Hi,
here is a revised implementation of interpn.
On 2/8/07, John W. Eaton <address@hidden
| /*
|
| 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; ...
ok.
| 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.
The revised code now uses only OCTAVE_LOCAL_BUFFER.
| if (nargin % 2 == 0)
| {
| error("Wrong number of arguments");
| return octave_value();
| }
Please use the print_usage function for usage messages.
ok, changed.
| 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.
I agree. This is changed.
| if (isvector(X[0].dims()))
Instead of working with dims, I'd suggest writing a function to work on
Array objects.
OK.
| {
| 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);
This is changed too.
Cheers,
Alex
interpn.cc
Description: Text Data