Skip to content

Instantly share code, notes, and snippets.

View aldente39's full-sized avatar
🍂

aldente39 aldente39

🍂
View GitHub Profile
@aldente39
aldente39 / shifted_bicg.m
Last active August 29, 2015 14:07
Shifted BiCG method
function x = shifted_bicg(A, b, sigma, tol, max_iter)
%%% initialization
if nargin < 4
tol = 1e-6;
max_iter = 1000;
end
if nargin < 5
max_iter = 1000;
object Strassen {
def add0(m:Array[Array[Double]], size:Int) = {
val log2 = Math.ceil(Math.log(size) / Math.log(2)).toInt
val next = Math.pow(2, log2).toInt
val res = Array.ofDim[Double](next, next)
for (i <- 0 until m.length) {
for (j <- 0 until m(0).length) {
res(i)(j) = m(i)(j)
}
@aldente39
aldente39 / readmtx.scala
Created February 22, 2013 17:16
Read a Matrix Market file
import scala.io._
def readmtx (file:String) = {
val source = Source.fromFile(file,"UTF-8").getLines.toList
val lines = source.filter(x => x.head != '%')
val info = ((lines(0)) split "[ ]+").map(x => x.toInt)
val mat = Array.ofDim[Double] (info(0), info(1))
for(i <- lines){
@aldente39
aldente39 / test.cpp
Created December 24, 2012 07:09
test
//MinGWのg++.exeでは、コンパイルは通るが実行した瞬間落ちる。
//Visual C++ 2010 Express に付いてきたcl.exeでは動く。
/*
g++ -vの出力
Using built-in specs.
COLLECT_GCC=D:\Applications\MinGW\bin\g++.exe
COLLECT_LTO_WRAPPER=d:/applications/mingw/bin/../libexec/gcc/mingw32/4.7.0/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.7.0/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --wi
@aldente39
aldente39 / laplace.hs
Created September 17, 2012 06:06
Laplace equation
{-ラプラス方程式を解く-}
import Data.Array.IO
{-パラメータ設定-}
n = 50 {-行列のサイズ-}
k = (n+2) {-境界を含めた行列のサイズ-}
loop u 0 = return ()
loop u n = do
writeArray u (1,n) 100
function say{
$a = [Reflection.Assembly]::LoadWithPartialName('System.Speech')
$message = New-Object System.Speech.Synthesis.SpeechSynthesizer
$message.Speak($args)
}
function tex2pdf([string]$filename, [switch]$nolog){
$pdfname = $filename -replace ".tex", ".pdf"
$psinfo = ps | Where-Object{$_.MainWindowTitle -like "*"+ $pdfname +"*"}
if($psinfo -ne $NULL){
foreach($a in $psinfo){
kill $a.Id
}
}
platex $filename
$newfilename = $filename -replace ".tex", ".dvi"
@aldente39
aldente39 / evenodd.py
Created May 29, 2012 06:20
check even-odd
def main():
filename = "guki.c"
f = open(filename, "w")
f.write("#include<stdio.h>\n")
f.write("#include<stdlib.h>\n\n")
f.write("int a(b){\n")
f.write(" int res;\n")
f.write(" switch(b){\n")
i = 0
while i < 1000:
@aldente39
aldente39 / RemovePath.ps1
Created April 7, 2012 14:30
remove path
function RemovePath{
$p = pwd
$name = "Path"
sl HKCU:
$s = Get-ItemProperty "HKCU:Environment" $name
sl $p
$s = $s.$name
if($s[-1] -eq ";"){
$s = $s.Remove($s.length - 1, 1)
}
function AddPath([string]$x){
$p = pwd
$name = "Path"
sl HKCU:
$s = Get-ItemProperty "HKCU:Environment" $name
sl $p
$s = $s.$name
Write-Host "path length:" $s.length + $x.length
if(($s.length -eq 0) -or ($s[-1] -eq ";")){
$s += $x