octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #59850] uniquetol missing, so I implemented it


From: anonymous
Subject: [Octave-bug-tracker] [bug #59850] uniquetol missing, so I implemented it
Date: Sun, 10 Jan 2021 07:10:37 -0500 (EST)
User-agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0

URL:
  <https://savannah.gnu.org/bugs/?59850>

                 Summary: uniquetol missing, so I implemented it
                 Project: GNU Octave
            Submitted by: None
            Submitted on: Sun 10 Jan 2021 12:10:34 PM UTC
                Category: Octave Function
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Matlab Compatibility
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
                 Release: 6.1.0
         Discussion Lock: Any
        Operating System: Any

    _______________________________________________________

Details:

I get the message uniquetol is missing from Octave and I could not find it in
a package so I have implemented it. I do not have Matlab so I can not directly
compare it but I have run all of the examples on the Matlab uniquetol help
page and I received the same output from my implementation as shown on that
page.

The Implementation


function [C,IA,IC]=uniquetol(A,varargin)


maxabsA=max(abs(A(:)));
ByRows=false;
OutputAllIndices=false;
DataScale=maxabsA;
sizeA=size(A);
if nargin()==1||~(isnumeric(varargin{1})&&isscalar(varargin{1}))
  if isa(A,'double')
    tol=1e-12;
  elseif isa(A,'single')
    tol=1e-6;
  endif
else
  tol=varargin{1};
end

for k=1:length(varargin)
  if isnumeric(varargin{k})
    continue
  elseif ischar(varargin{k})
    if strcmpi(varargin{k},'rows')
      ByRows=true;
    elseif strcmpi(varargin{k},'byrows')
      ByRows=logical(varargin{k+1});
    elseif strcmpi(varargin{k},'OutputAllIndices')
      OutputAllIndices=logical(varargin{k+1});
    elseif strcmpi(varargin{k},'DataScale')
      DataScale=varargin{k+1}(:).';
      columnsDataScale=columns(DataScale);
      if ~(columnsDataScale==1||columnsDataScale==sizeA(2))
        error("Incorrect size of data scale.");
      endif
    endif
  endif
end
if ~ByRows
  A=A(:);
end
x=A;
points=rows(x);
d=columns(x);
Iall=zeros(points,1);
I=nan(d,1);
IA={};
J=nan(d,1);
j=1;
ii=0;
tolDataScale=tol*DataScale;
for i=1:points
  if any(Iall==i)
    continue
  else
    eq=all(abs(x-x(i,:))<tolDataScale,2);
    sumeq=sum(eq);
    ia=find(eq);
    if OutputAllIndices
      IA{end+1}=ia;
    endif
    Iall(ii+(1:sumeq))=ia;
    I(j)=ia(1);
    J(eq)=j;
    ii+=sumeq;
    j+=1;
  end
end
C=x(I,:);
if sizeA(1)==1&&sizeA(2)>1
  C=C.';
end
if ~OutputAllIndices
  IA=I(1:j-1);
endif
IC=J;
end





    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?59850>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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