Skip to content

Commit

Permalink
Merge pull request praat#2785 from PaulBoersma/master
Browse files Browse the repository at this point in the history
-
  • Loading branch information
PaulBoersma authored Nov 14, 2024
2 parents 0b1a2c9 + e73a55c commit 23ebeec
Show file tree
Hide file tree
Showing 12 changed files with 520 additions and 41 deletions.
38 changes: 37 additions & 1 deletion melder/MAT.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
/* MAT.h
*
* Copyright (C) 2017-2021 Paul Boersma
* Copyright (C) 2017-2021,2024 Paul Boersma
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -313,6 +313,24 @@ inline autoMAT subtract_MAT (constMATVU const& x, constMATVU const& y) {
return result;
}

inline void abs_MAT_out (MATVU const& target, constMATVU const& x) {
Melder_assert (target.nrow == x.nrow);
Melder_assert (target.ncol == x.ncol);
for (integer irow = 1; irow <= x.nrow; irow ++)
for (integer icol = 1; icol <= x.ncol; icol ++)
target [irow] [icol] = fabs (x [irow] [icol]);
}
inline void abs_MAT_inout (MATVU const& x) noexcept {
for (integer irow = 1; irow <= x.nrow; irow ++)
for (integer icol = 1; icol <= x.ncol; icol ++)
x [irow] [icol] = fabs (x [irow] [icol]);
}
inline autoMAT abs_MAT (constMATVU const& x) {
autoMAT result = raw_MAT (x.nrow, x.ncol);
abs_MAT_out (result.all(), x);
return result;
}

/*
Make the average of each column zero.
a[i][j] -= a[.][j]
Expand Down Expand Up @@ -405,6 +423,24 @@ inline autoMAT mul_fast_MAT (constMATVU const& x, constMATVU const& y) {
void MATmul_forceMetal_ (MATVU const& target, constMATVU const& x, constMATVU const& y);
void MATmul_forceOpenCL_ (MATVU const& target, constMATVU const& x, constMATVU const& y);

inline void neg_MAT_out (MATVU const& target, constMATVU const& x) {
Melder_assert (target.nrow == x.nrow);
Melder_assert (target.ncol == x.ncol);
for (integer irow = 1; irow <= x.nrow; irow ++)
for (integer icol = 1; icol <= x.ncol; icol ++)
target [irow] [icol] = - x [irow] [icol];
}
inline void neg_MAT_inout (MATVU const& x) noexcept {
for (integer irow = 1; irow <= x.nrow; irow ++)
for (integer icol = 1; icol <= x.ncol; icol ++)
x [irow] [icol] = - x [irow] [icol];
}
inline autoMAT neg_MAT (constMATVU const& x) {
autoMAT result = raw_MAT (x.nrow, x.ncol);
neg_MAT_out (result.all(), x);
return result;
}

void outer_MAT_out (MATVU const& target, constVECVU const& x, constVECVU const& y);
extern autoMAT outer_MAT (constVECVU const& x, constVECVU const& y);

Expand Down
17 changes: 16 additions & 1 deletion melder/VEC.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
/* VEC.h
*
* Copyright (C) 2017-2021 Paul Boersma
* Copyright (C) 2017-2021,2023,2024 Paul Boersma
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -249,6 +249,21 @@ extern void mul_VEC_out (VECVU const& target, constMATVU const& mat, constVECVU
extern autoVEC mul_VEC (constVECVU const& vec, constMATVU const& mat);
extern autoVEC mul_VEC (constMATVU const& mat, constVECVU const& vec);

inline void neg_VEC_out (VECVU const& target, constVECVU const& v) {
Melder_assert (target.size == v.size);
for (integer i = 1; i <= target.size; i ++)
target [i] = - v [i];
}
inline void neg_VEC_inout (VECVU const& vec) noexcept {
for (integer i = 1; i <= vec.size; i ++)
vec [i] = - vec [i];
}
inline autoVEC neg_VEC (constVECVU const& vec) {
autoVEC result = raw_VEC (vec.size);
neg_VEC_out (result.all(), vec);
return result;
}

extern void power_VEC_out (VECVU const& target, constVECVU const& vec, double power);
extern void power_VEC_inout (VECVU const& vec, double power);
inline autoVEC power_VEC (constVECVU const& vec, double power) {
Expand Down
Loading

0 comments on commit 23ebeec

Please sign in to comment.