conv.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. // Code generated by "go generate gonum.org/v1/gonum/blas”; DO NOT EDIT.
  2. // Copyright ©2015 The Gonum Authors. All rights reserved.
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSE file.
  5. package cblas128
  6. import "gonum.org/v1/gonum/blas"
  7. // GeneralCols represents a matrix using the conventional column-major storage scheme.
  8. type GeneralCols General
  9. // From fills the receiver with elements from a. The receiver
  10. // must have the same dimensions as a and have adequate backing
  11. // data storage.
  12. func (t GeneralCols) From(a General) {
  13. if t.Rows != a.Rows || t.Cols != a.Cols {
  14. panic("cblas128: mismatched dimension")
  15. }
  16. if len(t.Data) < (t.Cols-1)*t.Stride+t.Rows {
  17. panic("cblas128: short data slice")
  18. }
  19. for i := 0; i < a.Rows; i++ {
  20. for j, v := range a.Data[i*a.Stride : i*a.Stride+a.Cols] {
  21. t.Data[i+j*t.Stride] = v
  22. }
  23. }
  24. }
  25. // From fills the receiver with elements from a. The receiver
  26. // must have the same dimensions as a and have adequate backing
  27. // data storage.
  28. func (t General) From(a GeneralCols) {
  29. if t.Rows != a.Rows || t.Cols != a.Cols {
  30. panic("cblas128: mismatched dimension")
  31. }
  32. if len(t.Data) < (t.Rows-1)*t.Stride+t.Cols {
  33. panic("cblas128: short data slice")
  34. }
  35. for j := 0; j < a.Cols; j++ {
  36. for i, v := range a.Data[j*a.Stride : j*a.Stride+a.Rows] {
  37. t.Data[i*t.Stride+j] = v
  38. }
  39. }
  40. }
  41. // TriangularCols represents a matrix using the conventional column-major storage scheme.
  42. type TriangularCols Triangular
  43. // From fills the receiver with elements from a. The receiver
  44. // must have the same dimensions, uplo and diag as a and have
  45. // adequate backing data storage.
  46. func (t TriangularCols) From(a Triangular) {
  47. if t.N != a.N {
  48. panic("cblas128: mismatched dimension")
  49. }
  50. if t.Uplo != a.Uplo {
  51. panic("cblas128: mismatched BLAS uplo")
  52. }
  53. if t.Diag != a.Diag {
  54. panic("cblas128: mismatched BLAS diag")
  55. }
  56. switch a.Uplo {
  57. default:
  58. panic("cblas128: bad BLAS uplo")
  59. case blas.Upper:
  60. for i := 0; i < a.N; i++ {
  61. for j := i; j < a.N; j++ {
  62. t.Data[i+j*t.Stride] = a.Data[i*a.Stride+j]
  63. }
  64. }
  65. case blas.Lower:
  66. for i := 0; i < a.N; i++ {
  67. for j := 0; j <= i; j++ {
  68. t.Data[i+j*t.Stride] = a.Data[i*a.Stride+j]
  69. }
  70. }
  71. case blas.All:
  72. for i := 0; i < a.N; i++ {
  73. for j := 0; j < a.N; j++ {
  74. t.Data[i+j*t.Stride] = a.Data[i*a.Stride+j]
  75. }
  76. }
  77. }
  78. }
  79. // From fills the receiver with elements from a. The receiver
  80. // must have the same dimensions, uplo and diag as a and have
  81. // adequate backing data storage.
  82. func (t Triangular) From(a TriangularCols) {
  83. if t.N != a.N {
  84. panic("cblas128: mismatched dimension")
  85. }
  86. if t.Uplo != a.Uplo {
  87. panic("cblas128: mismatched BLAS uplo")
  88. }
  89. if t.Diag != a.Diag {
  90. panic("cblas128: mismatched BLAS diag")
  91. }
  92. switch a.Uplo {
  93. default:
  94. panic("cblas128: bad BLAS uplo")
  95. case blas.Upper:
  96. for i := 0; i < a.N; i++ {
  97. for j := i; j < a.N; j++ {
  98. t.Data[i*t.Stride+j] = a.Data[i+j*a.Stride]
  99. }
  100. }
  101. case blas.Lower:
  102. for i := 0; i < a.N; i++ {
  103. for j := 0; j <= i; j++ {
  104. t.Data[i*t.Stride+j] = a.Data[i+j*a.Stride]
  105. }
  106. }
  107. case blas.All:
  108. for i := 0; i < a.N; i++ {
  109. for j := 0; j < a.N; j++ {
  110. t.Data[i*t.Stride+j] = a.Data[i+j*a.Stride]
  111. }
  112. }
  113. }
  114. }
  115. // BandCols represents a matrix using the band column-major storage scheme.
  116. type BandCols Band
  117. // From fills the receiver with elements from a. The receiver
  118. // must have the same dimensions and bandwidth as a and have
  119. // adequate backing data storage.
  120. func (t BandCols) From(a Band) {
  121. if t.Rows != a.Rows || t.Cols != a.Cols {
  122. panic("cblas128: mismatched dimension")
  123. }
  124. if t.KL != a.KL || t.KU != a.KU {
  125. panic("cblas128: mismatched bandwidth")
  126. }
  127. if a.Stride < a.KL+a.KU+1 {
  128. panic("cblas128: short stride for source")
  129. }
  130. if t.Stride < t.KL+t.KU+1 {
  131. panic("cblas128: short stride for destination")
  132. }
  133. for i := 0; i < a.Rows; i++ {
  134. for j := max(0, i-a.KL); j < min(i+a.KU+1, a.Cols); j++ {
  135. t.Data[i+t.KU-j+j*t.Stride] = a.Data[j+a.KL-i+i*a.Stride]
  136. }
  137. }
  138. }
  139. // From fills the receiver with elements from a. The receiver
  140. // must have the same dimensions and bandwidth as a and have
  141. // adequate backing data storage.
  142. func (t Band) From(a BandCols) {
  143. if t.Rows != a.Rows || t.Cols != a.Cols {
  144. panic("cblas128: mismatched dimension")
  145. }
  146. if t.KL != a.KL || t.KU != a.KU {
  147. panic("cblas128: mismatched bandwidth")
  148. }
  149. if a.Stride < a.KL+a.KU+1 {
  150. panic("cblas128: short stride for source")
  151. }
  152. if t.Stride < t.KL+t.KU+1 {
  153. panic("cblas128: short stride for destination")
  154. }
  155. for j := 0; j < a.Cols; j++ {
  156. for i := max(0, j-a.KU); i < min(j+a.KL+1, a.Rows); i++ {
  157. t.Data[j+a.KL-i+i*a.Stride] = a.Data[i+t.KU-j+j*t.Stride]
  158. }
  159. }
  160. }
  161. // TriangularBandCols represents a triangular matrix using the band column-major storage scheme.
  162. type TriangularBandCols TriangularBand
  163. // From fills the receiver with elements from a. The receiver
  164. // must have the same dimensions, bandwidth and uplo as a and
  165. // have adequate backing data storage.
  166. func (t TriangularBandCols) From(a TriangularBand) {
  167. if t.N != a.N {
  168. panic("cblas128: mismatched dimension")
  169. }
  170. if t.K != a.K {
  171. panic("cblas128: mismatched bandwidth")
  172. }
  173. if a.Stride < a.K+1 {
  174. panic("cblas128: short stride for source")
  175. }
  176. if t.Stride < t.K+1 {
  177. panic("cblas128: short stride for destination")
  178. }
  179. if t.Uplo != a.Uplo {
  180. panic("cblas128: mismatched BLAS uplo")
  181. }
  182. if t.Diag != a.Diag {
  183. panic("cblas128: mismatched BLAS diag")
  184. }
  185. dst := BandCols{
  186. Rows: t.N, Cols: t.N,
  187. Stride: t.Stride,
  188. Data: t.Data,
  189. }
  190. src := Band{
  191. Rows: a.N, Cols: a.N,
  192. Stride: a.Stride,
  193. Data: a.Data,
  194. }
  195. switch a.Uplo {
  196. default:
  197. panic("cblas128: bad BLAS uplo")
  198. case blas.Upper:
  199. dst.KU = t.K
  200. src.KU = a.K
  201. case blas.Lower:
  202. dst.KL = t.K
  203. src.KL = a.K
  204. }
  205. dst.From(src)
  206. }
  207. // From fills the receiver with elements from a. The receiver
  208. // must have the same dimensions, bandwidth and uplo as a and
  209. // have adequate backing data storage.
  210. func (t TriangularBand) From(a TriangularBandCols) {
  211. if t.N != a.N {
  212. panic("cblas128: mismatched dimension")
  213. }
  214. if t.K != a.K {
  215. panic("cblas128: mismatched bandwidth")
  216. }
  217. if a.Stride < a.K+1 {
  218. panic("cblas128: short stride for source")
  219. }
  220. if t.Stride < t.K+1 {
  221. panic("cblas128: short stride for destination")
  222. }
  223. if t.Uplo != a.Uplo {
  224. panic("cblas128: mismatched BLAS uplo")
  225. }
  226. if t.Diag != a.Diag {
  227. panic("cblas128: mismatched BLAS diag")
  228. }
  229. dst := Band{
  230. Rows: t.N, Cols: t.N,
  231. Stride: t.Stride,
  232. Data: t.Data,
  233. }
  234. src := BandCols{
  235. Rows: a.N, Cols: a.N,
  236. Stride: a.Stride,
  237. Data: a.Data,
  238. }
  239. switch a.Uplo {
  240. default:
  241. panic("cblas128: bad BLAS uplo")
  242. case blas.Upper:
  243. dst.KU = t.K
  244. src.KU = a.K
  245. case blas.Lower:
  246. dst.KL = t.K
  247. src.KL = a.K
  248. }
  249. dst.From(src)
  250. }
  251. func min(a, b int) int {
  252. if a < b {
  253. return a
  254. }
  255. return b
  256. }
  257. func max(a, b int) int {
  258. if a > b {
  259. return a
  260. }
  261. return b
  262. }