annotate liboctave/lo-cutils.c @ 8966:1bba53c0a38d

Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag. Date: Mon, 9 Mar 2009 17:45:22 -0400 This does not use the typical sparse-mx-ops generator. I suspect the sematics of elementwise multiplication and division to be rather controversial, so they are not included. If comparison operations are added, the implementation should be shifted over to use the typical generator. The template in Sparse-diag-op-defs.h likely could use const bools rather than functional argument operations. I haven't measured which is optimized more effectively. Also, the Octave binding layer in op-dm-scm.cc likely could use all sorts of macro or template trickery, but it's far easier to let Emacs handle it for now. That would be worth revisiting if further elementwise sparse and diagonal operations are added.
author Jason Riedy <jason@acm.org>
date Mon, 09 Mar 2009 17:49:14 -0400
parents a1dbe9d80eee
children 4c0cdbe0acca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3613
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
1 /*
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
2
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006, 2007 John W. Eaton
3613
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
4
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
6
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6111
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6111
diff changeset
10 option) any later version.
3613
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
11
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
15 for more details.
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
16
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6111
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6111
diff changeset
19 <http://www.gnu.org/licenses/>.
3613
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
20
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
21 */
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
22
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
23 /*
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
24
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
25 The function gethostname was adapted from a similar function from GNU
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
26 Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
27 Software Foundation, Inc.
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
28
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
29 */
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
30
3613
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
31 #ifdef HAVE_CONFIG_H
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
32 #include <config.h>
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
33 #endif
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
34
4290
73431774c0b7 [project @ 2003-01-05 06:30:44 by jwe]
jwe
parents: 4093
diff changeset
35 /* This gives us a better chance of finding a prototype for strptime
73431774c0b7 [project @ 2003-01-05 06:30:44 by jwe]
jwe
parents: 4093
diff changeset
36 on some systems. */
73431774c0b7 [project @ 2003-01-05 06:30:44 by jwe]
jwe
parents: 4093
diff changeset
37
73431774c0b7 [project @ 2003-01-05 06:30:44 by jwe]
jwe
parents: 4093
diff changeset
38 #if ! defined (_XOPEN_SOURCE)
73431774c0b7 [project @ 2003-01-05 06:30:44 by jwe]
jwe
parents: 4093
diff changeset
39 #define _XOPEN_SOURCE
73431774c0b7 [project @ 2003-01-05 06:30:44 by jwe]
jwe
parents: 4093
diff changeset
40 #endif
73431774c0b7 [project @ 2003-01-05 06:30:44 by jwe]
jwe
parents: 4093
diff changeset
41
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
42 #ifdef HAVE_UNISTD_H
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
43 #ifdef HAVE_SYS_TYPES_H
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
44 #include <sys/types.h>
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
45 #endif
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
46 #include <unistd.h>
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
47 #endif
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
48
3613
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
49 #include <stdlib.h>
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
50 #include <string.h>
3706
6581e686f83f [project @ 2000-07-25 05:30:02 by jwe]
jwe
parents: 3613
diff changeset
51 #include <time.h>
3613
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
52
5453
89f5979e8552 [project @ 2005-09-17 00:50:58 by jwe]
jwe
parents: 5451
diff changeset
53 #include "syswait.h"
89f5979e8552 [project @ 2005-09-17 00:50:58 by jwe]
jwe
parents: 5451
diff changeset
54
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5453
diff changeset
55 OCTAVE_API void
3613
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
56 octave_qsort (void *base, size_t n, size_t size,
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
57 int (*cmp) (const void *, const void *))
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
58 {
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
59 qsort (base, n, size, cmp);
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
60 }
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
61
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5453
diff changeset
62 OCTAVE_API char *
3706
6581e686f83f [project @ 2000-07-25 05:30:02 by jwe]
jwe
parents: 3613
diff changeset
63 oct_strptime (const char *buf, const char *format, struct tm *tm)
6581e686f83f [project @ 2000-07-25 05:30:02 by jwe]
jwe
parents: 3613
diff changeset
64 {
3786
9bb6e4197fc5 [project @ 2001-02-07 18:14:43 by jwe]
jwe
parents: 3707
diff changeset
65 return (char *) strptime (buf, format, tm);
3706
6581e686f83f [project @ 2000-07-25 05:30:02 by jwe]
jwe
parents: 3613
diff changeset
66 }
6581e686f83f [project @ 2000-07-25 05:30:02 by jwe]
jwe
parents: 3613
diff changeset
67
4093
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 3803
diff changeset
68 #if defined (__WIN32__) && ! defined (_POSIX_VERSION)
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 3803
diff changeset
69
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 3803
diff changeset
70 #include <winsock.h>
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 3803
diff changeset
71
5a82e874999b [project @ 2002-10-08 23:48:45 by jwe]
jwe
parents: 3803
diff changeset
72 #elif ! defined (HAVE_GETHOSTNAME) && defined (HAVE_SYS_UTSNAME_H)
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3706
diff changeset
73
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
74 #include <sys/utsname.h>
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
75
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
76 int
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
77 gethostname (char *name, int namelen)
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
78 {
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
79 int i;
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
80 struct utsname ut;
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
81
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
82 --namelen;
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
83
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
84 uname (&ut);
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
85 i = strlen (ut.nodename) + 1;
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
86 strncpy (name, ut.nodename, i < namelen ? i : namelen);
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
87 name[namelen] = '\0';
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
88
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
89 return 0;
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
90 }
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
91
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
92 #endif
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
93
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5453
diff changeset
94 OCTAVE_API int
6111
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents: 6108
diff changeset
95 octave_strcasecmp (const char *s1, const char *s2)
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents: 6108
diff changeset
96 {
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents: 6108
diff changeset
97 return strcasecmp (s1, s2);
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents: 6108
diff changeset
98 }
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents: 6108
diff changeset
99
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents: 6108
diff changeset
100 OCTAVE_API int
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents: 6108
diff changeset
101 octave_strncasecmp (const char *s1, const char *s2, size_t n)
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents: 6108
diff changeset
102 {
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents: 6108
diff changeset
103 return strncasecmp (s1, s2, n);
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents: 6108
diff changeset
104 }
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents: 6108
diff changeset
105
ed81d74118bb [project @ 2006-10-27 02:43:23 by jwe]
jwe
parents: 6108
diff changeset
106 OCTAVE_API int
3803
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
107 octave_gethostname (char *name, int namelen)
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
108 {
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
109 return gethostname (name, namelen);
63c75bc3db82 [project @ 2001-02-28 08:24:40 by jwe]
jwe
parents: 3786
diff changeset
110 }
3707
58140935c812 [project @ 2000-07-28 09:40:52 by jwe]
jwe
parents: 3706
diff changeset
111
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
112 #ifdef HAVE_LOADLIBRARY_API
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
113 #include <windows.h>
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
114
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
115 /* Need this since in C++ can't cast from int(*)() to void* */
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5453
diff changeset
116 OCTAVE_API void *
5453
89f5979e8552 [project @ 2005-09-17 00:50:58 by jwe]
jwe
parents: 5451
diff changeset
117 octave_w32_library_search (HINSTANCE handle, const char * name)
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
118 {
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
119 return (GetProcAddress (handle, name));
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
120 }
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
121 #endif
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
122
6108
143b556ce725 [project @ 2006-10-27 01:45:54 by jwe]
jwe
parents: 5453
diff changeset
123 OCTAVE_API pid_t
5453
89f5979e8552 [project @ 2005-09-17 00:50:58 by jwe]
jwe
parents: 5451
diff changeset
124 octave_waitpid (pid_t pid, int *status, int options)
89f5979e8552 [project @ 2005-09-17 00:50:58 by jwe]
jwe
parents: 5451
diff changeset
125 {
89f5979e8552 [project @ 2005-09-17 00:50:58 by jwe]
jwe
parents: 5451
diff changeset
126 return WAITPID (pid, status, options);
89f5979e8552 [project @ 2005-09-17 00:50:58 by jwe]
jwe
parents: 5451
diff changeset
127 }
89f5979e8552 [project @ 2005-09-17 00:50:58 by jwe]
jwe
parents: 5451
diff changeset
128
3613
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
129 /*
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
130 ;;; Local Variables: ***
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
131 ;;; mode: C++ ***
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
132 ;;; End: ***
0a93682f89c8 [project @ 2000-03-17 10:58:25 by jwe]
jwe
parents:
diff changeset
133 */