[GRASS-SVN] r64266 - grass-addons/grass7/imagery/i.spec.unmix
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jan 20 14:33:06 PST 2015
Author: neteler
Date: 2015-01-20 14:33:06 -0800 (Tue, 20 Jan 2015)
New Revision: 64266
Removed:
grass-addons/grass7/imagery/i.spec.unmix/la_extra.c
grass-addons/grass7/imagery/i.spec.unmix/la_extra.h
Modified:
grass-addons/grass7/imagery/i.spec.unmix/main.c
grass-addons/grass7/imagery/i.spec.unmix/open.c
Log:
i.spec.unmix Addon: lapack matrix/vector functions moved to libgmath (r64265)
Deleted: grass-addons/grass7/imagery/i.spec.unmix/la_extra.c
===================================================================
--- grass-addons/grass7/imagery/i.spec.unmix/la_extra.c 2015-01-20 22:31:51 UTC (rev 64265)
+++ grass-addons/grass7/imagery/i.spec.unmix/la_extra.c 2015-01-20 22:33:06 UTC (rev 64266)
@@ -1,175 +0,0 @@
-/* TODO: move to GMATHLIB */
-
-#include <stdio.h> /* needed here for ifdef/else */
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include <grass/config.h>
-
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include <grass/la.h>
-#include "la_extra.h"
-
-
-mat_struct *G_matrix_resize(mat_struct * in, int rows, int cols)
-{
- mat_struct *matrix;
- matrix = G_matrix_init(rows, cols, rows);
- int i, j, p, index = 0;
- for (i = 0; i < rows; i++)
- for (j = 0; j < cols; j++)
- G_matrix_set_element(matrix, i, j, G_matrix_get_element(in, i, j));
-/* matrix->vals[index++] = in->vals[i + j * cols];*/
-
- int old_size = in->rows * in->cols;
- int new_size = rows * cols;
-
- if (new_size > old_size)
- for (p = old_size; p < new_size; p++)
- G_matrix_set_element(matrix, i, j, 0.0);
-
- return (matrix);
-}
-
-
-mat_struct *G_matrix_scalar_mul(double scalar, mat_struct * matrix, mat_struct * out)
-{
- int m, n, i, j;
- int index = 0;
-
- if (matrix == NULL)
- {
- G_warning (_("Input matrix is uninitialized"));
- return NULL;
- }
-
- if (out == NULL)
- out = G_matrix_init(matrix->rows, matrix->cols, matrix->rows);
-
- if (out->rows != matrix->rows || out->cols != matrix->cols)
- out = G_matrix_resize(out, matrix->rows, matrix->cols);
-
- m = matrix->rows;
- n = matrix->cols;
-
- for (i = 0; i < m; i++)
- {
- for (j = 0; j < n; j++)
- {
- doublereal value = scalar * G_matrix_get_element(matrix, i, j);
- G_matrix_set_element (out, i,j, value);
- }
- }
-
- return (out);
-}
-
-vec_struct* G_mat_vector_product(mat_struct * A, vec_struct * b,vec_struct *out)
-{
- unsigned int i, m, n, j;
- register doublereal sum;
-
-//G_message("A=%d,%d,%d", A->cols, A->rows, A->ldim);
-//G_message("B=%d,%d,%d", b->cols, b->rows, b->ldim);
- if (A->cols != b->cols) {
- G_warning (_("Input matrix and vector have differing dimensions1"));
-
- return NULL;
-
- }
- if (!out) {
- G_warning (_("Output vector is uninitialized"));
- return NULL;
- }
-/* if (out->ldim != A->rows) {*/
-/* G_warning (_("Output vector has incorrect dimension"));*/
-/* exit(1);*/
-/* return NULL;*/
-/* }*/
-
-
- m = A->rows;
- n = A->cols;
-
- for (i = 0; i < m; i++) {
- sum = 0.0;
- int width = A->rows;
- for (j = 0; j < n; j++) {
-
- sum +=G_matrix_get_element(A, i, j) * G_matrix_get_element(b, 0, j);
- /*sum += A->vals[i + j * width] * b->vals[j];*/
- out->vals[i] = sum;
- }
- }
- return (out);
-}
-
-
-
-vec_struct *
-G_vector_product (vec_struct *v1, vec_struct *v2, vec_struct *out)
-{
- int idx1, idx2, idx0;
- int i;
-
- if (!out->is_init) {
- G_warning (_("Output vector is uninitialized"));
- return NULL;
- }
-
- if (v1->type != v2->type) {
- G_warning (_("Vectors are not of the same type"));
- return NULL;
- }
-
- if (v1->type != out->type) {
- G_warning (_("Output vector is of incorrect type"));
- return NULL;
- }
-
- if (v1->type == MATRIX_) {
- G_warning (_("Matrices not allowed"));
- return NULL;
- }
-
- if ((v1->type == ROWVEC_ && v1->cols != v2->cols) ||
- (v1->type == COLVEC_ && v1->rows != v2->rows))
- {
- G_warning (_("Vectors have differing dimensions"));
- return NULL;
- }
-
- if ((v1->type == ROWVEC_ && v1->cols != out->cols) ||
- (v1->type == COLVEC_ && v1->rows != out->rows))
- {
- G_warning (_("Output vector has incorrect dimension"));
- return NULL;
- }
-
-#if defined(HAVE_LAPACK) && defined(HAVE_LIBBLAS)
- f77_dhad (v1->cols, 1.0, v1->vals, 1, v2->vals, 1, 0.0, out->vals, 1.0);
-#else
- idx1 = (v1->v_indx > 0) ? v1->v_indx : 0;
- idx2 = (v2->v_indx > 0) ? v2->v_indx : 0;
- idx0 = (out->v_indx > 0) ? out->v_indx : 0;
-
- if (v1->type == ROWVEC_) {
- for (i = 0; i < v1->cols; i++)
- G_matrix_set_element(out, idx0, i,
- G_matrix_get_element(v1, idx1, i) *
- G_matrix_get_element(v2, idx2, i));
- } else {
- for (i = 0; i < v1->rows; i++)
- G_matrix_set_element(out, i, idx0,
- G_matrix_get_element(v1, i, idx1) *
- G_matrix_get_element(v2, i, idx2));
- }
-#endif
-
- return out;
-}
-
-
-
Deleted: grass-addons/grass7/imagery/i.spec.unmix/la_extra.h
===================================================================
--- grass-addons/grass7/imagery/i.spec.unmix/la_extra.h 2015-01-20 22:31:51 UTC (rev 64265)
+++ grass-addons/grass7/imagery/i.spec.unmix/la_extra.h 2015-01-20 22:33:06 UTC (rev 64266)
@@ -1,11 +0,0 @@
-/* TODO: move to GMATHLIB */
-
-#include <grass/config.h>
-#include <stdio.h>
-#include <grass/blas.h>
-#include <grass/lapack.h>
-
-mat_struct *G_matrix_scalar_mul(double scalar, mat_struct * matrix, mat_struct * out);
-vec_struct* G_vector_product (vec_struct *v1, vec_struct *v2, vec_struct *out);
-vec_struct* G_mat_vector_product(mat_struct * A, vec_struct * b,vec_struct *out);
-
Modified: grass-addons/grass7/imagery/i.spec.unmix/main.c
===================================================================
--- grass-addons/grass7/imagery/i.spec.unmix/main.c 2015-01-20 22:31:51 UTC (rev 64265)
+++ grass-addons/grass7/imagery/i.spec.unmix/main.c 2015-01-20 22:33:06 UTC (rev 64266)
@@ -3,15 +3,15 @@
*
* MODULE: i.spec.unmix
*
- * AUTHOR(S): Markus Neteler <neteler osgeo.org>: Original GRASS 5 version
- * Mohammed Rashad <rashadkm gmail.com> (update to GRASS 7)
+ * AUTHOR(S): Markus Neteler <neteler osgeo.org>: 1998, Original GRASS 5 version
+ * Mohammed Rashad <rashadkm gmail.com>: 2012, update to GRASS 7
*
* PURPOSE: Spectral mixture analysis of satellite/aerial images
*
* Notes: The original version was implemented with MESCHACH, the actual
* version is instead using BLAS/LAPACK via GMATHLIB.
* An error minimization approach is used instead of Single Value
- * Decomposition (SVD) which is numerically unstable. See the
+ * Decomposition (SVD) which is numerically unstable. See MN's
* related journal publication from 2005 for details.
*
* COPYRIGHT: (C) 1999-2012 by the GRASS Development Team
@@ -46,9 +46,7 @@
#include <grass/glocale.h>
#include "global.h"
-#include "la_extra.h"
-
#define GAMMA 10 /* last row value in Matrix and last b vector element
* for constraint Sum xi = 1 (GAMMA=weight)
*/
@@ -346,7 +344,7 @@
/* solve with iterative solution: */
while (fabs(change) > 0.0001) {
- G_mat_vector_product(A_tilde, startvector,
+ G_matvect_product(A_tilde, startvector,
A_times_startvector);
G_vector_sub(A_times_startvector, b_gamma, errorvector);
@@ -354,7 +352,7 @@
A_tilde_trans_mu =
G_matrix_scalar_mul(mu, A_tilde_trans, A_tilde_trans_mu);
- G_mat_vector_product(A_tilde_trans_mu, errorvector, temp);
+ G_matvect_product(A_tilde_trans_mu, errorvector, temp);
G_vector_sub(startvector, temp, startvector); /* update startvector */
for (k = 0; k < A_tilde->cols; k++)
@@ -417,6 +415,7 @@
Rast_close(resultfd[i]);
+/* TODO: avoid system calls, use modern approach for setting colors */
/* make grey scale color table */
sprintf(result_name, "%s.%d", parm.result->answer, (i + 1));
sprintf(command, "r.colors map=%s color=rules <<EOF\n"
Modified: grass-addons/grass7/imagery/i.spec.unmix/open.c
===================================================================
--- grass-addons/grass7/imagery/i.spec.unmix/open.c 2015-01-20 22:31:51 UTC (rev 64265)
+++ grass-addons/grass7/imagery/i.spec.unmix/open.c 2015-01-20 22:33:06 UTC (rev 64266)
@@ -14,7 +14,6 @@
#include <grass/gmath.h>
#include <grass/glocale.h>
#include "global.h"
-#include "la_extra.h"
int G_matrix_read2(FILE * fp, mat_struct * out); /* Modified version of G_matrix_read(..). */
More information about the grass-commit
mailing list